diff options
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/debug.rs | 94 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 2 |
2 files changed, 0 insertions, 96 deletions
diff --git a/crates/ra_hir/src/debug.rs b/crates/ra_hir/src/debug.rs deleted file mode 100644 index 6cd5c8cb9..000000000 --- a/crates/ra_hir/src/debug.rs +++ /dev/null | |||
@@ -1,94 +0,0 @@ | |||
1 | //! XXX: This does not work at the moment. | ||
2 | //! | ||
3 | //! printf debugging infrastructure for rust-analyzer. | ||
4 | //! | ||
5 | //! When you print a hir type, like a module, using `eprintln!("{:?}", module)`, | ||
6 | //! you usually get back a numeric ID, which doesn't tell you much: | ||
7 | //! `Module(92)`. | ||
8 | //! | ||
9 | //! This module adds convenience `debug` methods to various types, which resolve | ||
10 | //! the id to a human-readable location info: | ||
11 | //! | ||
12 | //! ```not_rust | ||
13 | //! eprintln!("{:?}", module.debug(db)); | ||
14 | //! => | ||
15 | //! Module { name: collections, path: "liballoc/collections/mod.rs" } | ||
16 | //! ``` | ||
17 | //! | ||
18 | //! Note that to get this info, we might need to execute queries! So | ||
19 | //! | ||
20 | //! * don't use the `debug` methods for logging | ||
21 | //! * when debugging, be aware that interference is possible. | ||
22 | |||
23 | use std::fmt; | ||
24 | |||
25 | use hir_expand::HirFileId; | ||
26 | use ra_db::{CrateId, FileId}; | ||
27 | |||
28 | use crate::{db::HirDatabase, Crate, Module, Name}; | ||
29 | |||
30 | impl Crate { | ||
31 | pub fn debug(self, db: &impl HirDebugDatabase) -> impl fmt::Debug + '_ { | ||
32 | debug_fn(move |fmt| db.debug_crate(self, fmt)) | ||
33 | } | ||
34 | } | ||
35 | |||
36 | impl Module { | ||
37 | pub fn debug(self, db: &impl HirDebugDatabase) -> impl fmt::Debug + '_ { | ||
38 | debug_fn(move |fmt| db.debug_module(self, fmt)) | ||
39 | } | ||
40 | } | ||
41 | |||
42 | pub trait HirDebugHelper: HirDatabase { | ||
43 | fn crate_name(&self, _krate: CrateId) -> Option<String> { | ||
44 | None | ||
45 | } | ||
46 | fn file_path(&self, _file_id: FileId) -> Option<String> { | ||
47 | None | ||
48 | } | ||
49 | } | ||
50 | |||
51 | pub trait HirDebugDatabase { | ||
52 | fn debug_crate(&self, krate: Crate, fmt: &mut fmt::Formatter<'_>) -> fmt::Result; | ||
53 | fn debug_module(&self, module: Module, fmt: &mut fmt::Formatter<'_>) -> fmt::Result; | ||
54 | fn debug_hir_file_id(&self, file_id: HirFileId, fmt: &mut fmt::Formatter<'_>) -> fmt::Result; | ||
55 | } | ||
56 | |||
57 | impl<DB: HirDebugHelper> HirDebugDatabase for DB { | ||
58 | fn debug_crate(&self, krate: Crate, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
59 | let mut builder = fmt.debug_tuple("Crate"); | ||
60 | match self.crate_name(krate.id) { | ||
61 | Some(name) => builder.field(&name), | ||
62 | None => builder.field(&krate.id), | ||
63 | } | ||
64 | .finish() | ||
65 | } | ||
66 | |||
67 | fn debug_module(&self, module: Module, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
68 | let file_id = module.definition_source(self).file_id.original_file(self); | ||
69 | let path = self.file_path(file_id).unwrap_or_else(|| "N/A".to_string()); | ||
70 | fmt.debug_struct("Module") | ||
71 | .field("name", &module.name(self).unwrap_or_else(Name::missing)) | ||
72 | .field("path", &path) | ||
73 | .finish() | ||
74 | } | ||
75 | |||
76 | fn debug_hir_file_id(&self, file_id: HirFileId, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
77 | let original = file_id.original_file(self); | ||
78 | let path = self.file_path(original).unwrap_or_else(|| "N/A".to_string()); | ||
79 | let is_macro = file_id != original.into(); | ||
80 | fmt.debug_struct("HirFileId").field("path", &path).field("macro", &is_macro).finish() | ||
81 | } | ||
82 | } | ||
83 | |||
84 | fn debug_fn(f: impl Fn(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl fmt::Debug { | ||
85 | struct DebugFn<F>(F); | ||
86 | |||
87 | impl<F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result> fmt::Debug for DebugFn<F> { | ||
88 | fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
89 | (&self.0)(fmt) | ||
90 | } | ||
91 | } | ||
92 | |||
93 | DebugFn(f) | ||
94 | } | ||
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 946299ba0..e7602ee30 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -26,8 +26,6 @@ macro_rules! impl_froms { | |||
26 | } | 26 | } |
27 | } | 27 | } |
28 | 28 | ||
29 | pub mod debug; | ||
30 | |||
31 | pub mod db; | 29 | pub mod db; |
32 | pub mod source_binder; | 30 | pub mod source_binder; |
33 | 31 | ||