diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_assists/src/test_db.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/debug.rs | 94 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/db.rs | 14 |
4 files changed, 1 insertions, 111 deletions
diff --git a/crates/ra_assists/src/test_db.rs b/crates/ra_assists/src/test_db.rs index 523259fd4..d5249f308 100644 --- a/crates/ra_assists/src/test_db.rs +++ b/crates/ra_assists/src/test_db.rs | |||
@@ -43,5 +43,3 @@ impl FileLoader for TestDB { | |||
43 | FileLoaderDelegate(self).relevant_crates(file_id) | 43 | FileLoaderDelegate(self).relevant_crates(file_id) |
44 | } | 44 | } |
45 | } | 45 | } |
46 | |||
47 | impl hir::debug::HirDebugHelper for TestDB {} | ||
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 | ||
diff --git a/crates/ra_ide/src/db.rs b/crates/ra_ide/src/db.rs index f739ebecd..47d0aed6f 100644 --- a/crates/ra_ide/src/db.rs +++ b/crates/ra_ide/src/db.rs | |||
@@ -5,7 +5,7 @@ use std::sync::Arc; | |||
5 | use ra_db::{ | 5 | use ra_db::{ |
6 | salsa::{self, Database, Durability}, | 6 | salsa::{self, Database, Durability}, |
7 | Canceled, CheckCanceled, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath, | 7 | Canceled, CheckCanceled, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath, |
8 | SourceDatabase, SourceDatabaseExt, SourceRootId, | 8 | SourceDatabase, SourceRootId, |
9 | }; | 9 | }; |
10 | use rustc_hash::FxHashMap; | 10 | use rustc_hash::FxHashMap; |
11 | 11 | ||
@@ -49,18 +49,6 @@ impl FileLoader for RootDatabase { | |||
49 | } | 49 | } |
50 | } | 50 | } |
51 | 51 | ||
52 | impl hir::debug::HirDebugHelper for RootDatabase { | ||
53 | fn crate_name(&self, krate: CrateId) -> Option<String> { | ||
54 | self.debug_data.crate_names.get(&krate).cloned() | ||
55 | } | ||
56 | fn file_path(&self, file_id: FileId) -> Option<String> { | ||
57 | let source_root_id = self.file_source_root(file_id); | ||
58 | let source_root_path = self.debug_data.root_paths.get(&source_root_id)?; | ||
59 | let file_path = self.file_relative_path(file_id); | ||
60 | Some(format!("{}/{}", source_root_path, file_path)) | ||
61 | } | ||
62 | } | ||
63 | |||
64 | impl salsa::Database for RootDatabase { | 52 | impl salsa::Database for RootDatabase { |
65 | fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> { | 53 | fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> { |
66 | &self.runtime | 54 | &self.runtime |