diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_batch/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/debug.rs | 33 |
2 files changed, 27 insertions, 8 deletions
diff --git a/crates/ra_batch/src/lib.rs b/crates/ra_batch/src/lib.rs index 07a7e0c86..a14139b26 100644 --- a/crates/ra_batch/src/lib.rs +++ b/crates/ra_batch/src/lib.rs | |||
@@ -39,7 +39,7 @@ pub fn load_cargo(root: &Path) -> Result<(AnalysisHost, FxHashMap<SourceRootId, | |||
39 | sender, | 39 | sender, |
40 | Watch(false), | 40 | Watch(false), |
41 | ); | 41 | ); |
42 | let crate_graph = ws.to_crate_graph(&mut |path: &Path| { | 42 | let (crate_graph, _crate_names) = ws.to_crate_graph(&mut |path: &Path| { |
43 | let vfs_file = vfs.load(path); | 43 | let vfs_file = vfs.load(path); |
44 | log::debug!("vfs file {:?} -> {:?}", path, vfs_file); | 44 | log::debug!("vfs file {:?} -> {:?}", path, vfs_file); |
45 | vfs_file.map(vfs_file_to_id) | 45 | vfs_file.map(vfs_file_to_id) |
diff --git a/crates/ra_hir/src/debug.rs b/crates/ra_hir/src/debug.rs index 5a835741d..87f3180c3 100644 --- a/crates/ra_hir/src/debug.rs +++ b/crates/ra_hir/src/debug.rs | |||
@@ -1,4 +1,24 @@ | |||
1 | use std::{cell::Cell, fmt}; | 1 | //! printf debugging infrastructure for rust-analyzer. |
2 | //! | ||
3 | //! When you print a hir type, like a module, using `eprintln!("{:?}", module)`, | ||
4 | //! you usually get back a numeric ID, which doesn't tell you much: | ||
5 | //! `Module(92)`. | ||
6 | //! | ||
7 | //! This module adds convenience `debug` methods to various types, which resolve | ||
8 | //! the id to a human-readable location info: | ||
9 | //! | ||
10 | //! ```not_rust | ||
11 | //! eprintln!("{:?}", module.debug(db)); | ||
12 | //! => | ||
13 | //! Module { name: collections, path: "liballoc/collections/mod.rs" } | ||
14 | //! ``` | ||
15 | //! | ||
16 | //! Note that to get this info, we might need to execute queries! So | ||
17 | //! | ||
18 | //! * don't use the `debug` methods for logging | ||
19 | //! * when debugging, be aware that interference is possible. | ||
20 | |||
21 | use std::fmt; | ||
2 | 22 | ||
3 | use ra_db::{CrateId, FileId}; | 23 | use ra_db::{CrateId, FileId}; |
4 | 24 | ||
@@ -50,15 +70,14 @@ impl<DB: HirDebugHelper> HirDebugDatabase for DB { | |||
50 | } | 70 | } |
51 | } | 71 | } |
52 | 72 | ||
53 | fn debug_fn(f: impl FnOnce(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl fmt::Debug { | 73 | fn debug_fn(f: impl Fn(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl fmt::Debug { |
54 | struct DebugFn<F>(Cell<Option<F>>); | 74 | struct DebugFn<F>(F); |
55 | 75 | ||
56 | impl<F: FnOnce(&mut fmt::Formatter<'_>) -> fmt::Result> fmt::Debug for DebugFn<F> { | 76 | impl<F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result> fmt::Debug for DebugFn<F> { |
57 | fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { | 77 | fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { |
58 | let f = self.0.take().unwrap(); | 78 | (&self.0)(fmt) |
59 | f(fmt) | ||
60 | } | 79 | } |
61 | } | 80 | } |
62 | 81 | ||
63 | DebugFn(Cell::new(Some(f))) | 82 | DebugFn(f) |
64 | } | 83 | } |