mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
document module
This commit is contained in:
parent
ef2b84ddf1
commit
e5a8093dd4
2 changed files with 27 additions and 8 deletions
|
@ -39,7 +39,7 @@ pub fn load_cargo(root: &Path) -> Result<(AnalysisHost, FxHashMap<SourceRootId,
|
||||||
sender,
|
sender,
|
||||||
Watch(false),
|
Watch(false),
|
||||||
);
|
);
|
||||||
let crate_graph = ws.to_crate_graph(&mut |path: &Path| {
|
let (crate_graph, _crate_names) = ws.to_crate_graph(&mut |path: &Path| {
|
||||||
let vfs_file = vfs.load(path);
|
let vfs_file = vfs.load(path);
|
||||||
log::debug!("vfs file {:?} -> {:?}", path, vfs_file);
|
log::debug!("vfs file {:?} -> {:?}", path, vfs_file);
|
||||||
vfs_file.map(vfs_file_to_id)
|
vfs_file.map(vfs_file_to_id)
|
||||||
|
|
|
@ -1,4 +1,24 @@
|
||||||
use std::{cell::Cell, fmt};
|
//! printf debugging infrastructure for rust-analyzer.
|
||||||
|
//!
|
||||||
|
//! When you print a hir type, like a module, using `eprintln!("{:?}", module)`,
|
||||||
|
//! you usually get back a numeric ID, which doesn't tell you much:
|
||||||
|
//! `Module(92)`.
|
||||||
|
//!
|
||||||
|
//! This module adds convenience `debug` methods to various types, which resolve
|
||||||
|
//! the id to a human-readable location info:
|
||||||
|
//!
|
||||||
|
//! ```not_rust
|
||||||
|
//! eprintln!("{:?}", module.debug(db));
|
||||||
|
//! =>
|
||||||
|
//! Module { name: collections, path: "liballoc/collections/mod.rs" }
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
//! Note that to get this info, we might need to execute queries! So
|
||||||
|
//!
|
||||||
|
//! * don't use the `debug` methods for logging
|
||||||
|
//! * when debugging, be aware that interference is possible.
|
||||||
|
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
use ra_db::{CrateId, FileId};
|
use ra_db::{CrateId, FileId};
|
||||||
|
|
||||||
|
@ -50,15 +70,14 @@ impl<DB: HirDebugHelper> HirDebugDatabase for DB {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn debug_fn(f: impl FnOnce(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl fmt::Debug {
|
fn debug_fn(f: impl Fn(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl fmt::Debug {
|
||||||
struct DebugFn<F>(Cell<Option<F>>);
|
struct DebugFn<F>(F);
|
||||||
|
|
||||||
impl<F: FnOnce(&mut fmt::Formatter<'_>) -> fmt::Result> fmt::Debug for DebugFn<F> {
|
impl<F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result> fmt::Debug for DebugFn<F> {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let f = self.0.take().unwrap();
|
(&self.0)(fmt)
|
||||||
f(fmt)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugFn(Cell::new(Some(f)))
|
DebugFn(f)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue