document module

This commit is contained in:
Aleksey Kladov 2019-09-09 12:39:59 +03:00
parent ef2b84ddf1
commit e5a8093dd4
2 changed files with 27 additions and 8 deletions
crates
ra_batch/src
ra_hir/src

@ -39,7 +39,7 @@ pub fn load_cargo(root: &Path) -> Result<(AnalysisHost, FxHashMap<SourceRootId,
sender,
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);
log::debug!("vfs file {:?} -> {:?}", path, vfs_file);
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};
@ -50,15 +70,14 @@ impl<DB: HirDebugHelper> HirDebugDatabase for DB {
}
}
fn debug_fn(f: impl FnOnce(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl fmt::Debug {
struct DebugFn<F>(Cell<Option<F>>);
fn debug_fn(f: impl Fn(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl fmt::Debug {
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 {
let f = self.0.take().unwrap();
f(fmt)
(&self.0)(fmt)
}
}
DebugFn(Cell::new(Some(f)))
DebugFn(f)
}