diff options
Diffstat (limited to 'crates/ra_hir/src/debug.rs')
-rw-r--r-- | crates/ra_hir/src/debug.rs | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/crates/ra_hir/src/debug.rs b/crates/ra_hir/src/debug.rs index 87f3180c3..48b69000b 100644 --- a/crates/ra_hir/src/debug.rs +++ b/crates/ra_hir/src/debug.rs | |||
@@ -22,7 +22,7 @@ use std::fmt; | |||
22 | 22 | ||
23 | use ra_db::{CrateId, FileId}; | 23 | use ra_db::{CrateId, FileId}; |
24 | 24 | ||
25 | use crate::{db::HirDatabase, Crate, Module, Name}; | 25 | use crate::{db::HirDatabase, Crate, HirFileId, Module, Name}; |
26 | 26 | ||
27 | impl Crate { | 27 | impl Crate { |
28 | pub fn debug(self, db: &impl HirDebugDatabase) -> impl fmt::Debug + '_ { | 28 | pub fn debug(self, db: &impl HirDebugDatabase) -> impl fmt::Debug + '_ { |
@@ -36,6 +36,12 @@ impl Module { | |||
36 | } | 36 | } |
37 | } | 37 | } |
38 | 38 | ||
39 | impl HirFileId { | ||
40 | pub fn debug(self, db: &impl HirDebugDatabase) -> impl fmt::Debug + '_ { | ||
41 | debug_fn(move |fmt| db.debug_hir_file_id(self, fmt)) | ||
42 | } | ||
43 | } | ||
44 | |||
39 | pub trait HirDebugHelper: HirDatabase { | 45 | pub trait HirDebugHelper: HirDatabase { |
40 | fn crate_name(&self, _krate: CrateId) -> Option<String> { | 46 | fn crate_name(&self, _krate: CrateId) -> Option<String> { |
41 | None | 47 | None |
@@ -48,6 +54,7 @@ pub trait HirDebugHelper: HirDatabase { | |||
48 | pub trait HirDebugDatabase { | 54 | pub trait HirDebugDatabase { |
49 | fn debug_crate(&self, krate: Crate, fmt: &mut fmt::Formatter<'_>) -> fmt::Result; | 55 | fn debug_crate(&self, krate: Crate, fmt: &mut fmt::Formatter<'_>) -> fmt::Result; |
50 | fn debug_module(&self, module: Module, fmt: &mut fmt::Formatter<'_>) -> fmt::Result; | 56 | fn debug_module(&self, module: Module, fmt: &mut fmt::Formatter<'_>) -> fmt::Result; |
57 | fn debug_hir_file_id(&self, file_id: HirFileId, fmt: &mut fmt::Formatter<'_>) -> fmt::Result; | ||
51 | } | 58 | } |
52 | 59 | ||
53 | impl<DB: HirDebugHelper> HirDebugDatabase for DB { | 60 | impl<DB: HirDebugHelper> HirDebugDatabase for DB { |
@@ -62,12 +69,19 @@ impl<DB: HirDebugHelper> HirDebugDatabase for DB { | |||
62 | 69 | ||
63 | fn debug_module(&self, module: Module, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { | 70 | fn debug_module(&self, module: Module, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { |
64 | let file_id = module.definition_source(self).file_id.original_file(self); | 71 | let file_id = module.definition_source(self).file_id.original_file(self); |
65 | let path = self.file_path(file_id); | 72 | let path = self.file_path(file_id).unwrap_or_else(|| "N/A".to_string()); |
66 | fmt.debug_struct("Module") | 73 | fmt.debug_struct("Module") |
67 | .field("name", &module.name(self).unwrap_or_else(Name::missing)) | 74 | .field("name", &module.name(self).unwrap_or_else(Name::missing)) |
68 | .field("path", &path.unwrap_or_else(|| "N/A".to_string())) | 75 | .field("path", &path) |
69 | .finish() | 76 | .finish() |
70 | } | 77 | } |
78 | |||
79 | fn debug_hir_file_id(&self, file_id: HirFileId, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
80 | let original = file_id.original_file(self); | ||
81 | let path = self.file_path(original).unwrap_or_else(|| "N/A".to_string()); | ||
82 | let is_macro = file_id != original.into(); | ||
83 | fmt.debug_struct("HirFileId").field("path", &path).field("macro", &is_macro).finish() | ||
84 | } | ||
71 | } | 85 | } |
72 | 86 | ||
73 | fn debug_fn(f: impl Fn(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl fmt::Debug { | 87 | fn debug_fn(f: impl Fn(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl fmt::Debug { |