mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 17:28:09 +00:00
Publicize debug printing of CrateDefMap
This commit is contained in:
parent
2ddfc4ed5b
commit
4b9e5d5dd9
2 changed files with 42 additions and 41 deletions
|
@ -229,6 +229,46 @@ impl CrateDefMap {
|
|||
self.resolve_path_fp_with_macro(db, ResolveMode::Other, original_module, path, shadow);
|
||||
(res.resolved_def, res.segment_index)
|
||||
}
|
||||
|
||||
// FIXME: this can use some more human-readable format (ideally, an IR
|
||||
// even), as this should be a great debugging aid.
|
||||
pub fn dump(&self) -> String {
|
||||
let mut buf = String::new();
|
||||
go(&mut buf, self, "\ncrate", self.root);
|
||||
return buf.trim().to_string();
|
||||
|
||||
fn go(buf: &mut String, map: &CrateDefMap, path: &str, module: LocalModuleId) {
|
||||
*buf += path;
|
||||
*buf += "\n";
|
||||
|
||||
let mut entries: Vec<_> = map.modules[module].scope.resolutions().collect();
|
||||
entries.sort_by_key(|(name, _)| name.clone());
|
||||
|
||||
for (name, def) in entries {
|
||||
*buf += &format!("{}:", name);
|
||||
|
||||
if def.types.is_some() {
|
||||
*buf += " t";
|
||||
}
|
||||
if def.values.is_some() {
|
||||
*buf += " v";
|
||||
}
|
||||
if def.macros.is_some() {
|
||||
*buf += " m";
|
||||
}
|
||||
if def.is_none() {
|
||||
*buf += " _";
|
||||
}
|
||||
|
||||
*buf += "\n";
|
||||
}
|
||||
|
||||
for (name, child) in map.modules[module].children.iter() {
|
||||
let path = path.to_string() + &format!("::{}", name);
|
||||
go(buf, map, &path, *child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ModuleData {
|
||||
|
|
|
@ -10,11 +10,10 @@ use insta::assert_snapshot;
|
|||
use ra_db::{fixture::WithFixture, SourceDatabase};
|
||||
use test_utils::covers;
|
||||
|
||||
use crate::{db::DefDatabase, nameres::*, test_db::TestDB, LocalModuleId};
|
||||
use crate::{db::DefDatabase, nameres::*, test_db::TestDB};
|
||||
|
||||
fn def_map(fixture: &str) -> String {
|
||||
let dm = compute_crate_def_map(fixture);
|
||||
render_crate_def_map(&dm)
|
||||
compute_crate_def_map(fixture).dump()
|
||||
}
|
||||
|
||||
fn compute_crate_def_map(fixture: &str) -> Arc<CrateDefMap> {
|
||||
|
@ -23,44 +22,6 @@ fn compute_crate_def_map(fixture: &str) -> Arc<CrateDefMap> {
|
|||
db.crate_def_map(krate)
|
||||
}
|
||||
|
||||
fn render_crate_def_map(map: &CrateDefMap) -> String {
|
||||
let mut buf = String::new();
|
||||
go(&mut buf, map, "\ncrate", map.root);
|
||||
return buf.trim().to_string();
|
||||
|
||||
fn go(buf: &mut String, map: &CrateDefMap, path: &str, module: LocalModuleId) {
|
||||
*buf += path;
|
||||
*buf += "\n";
|
||||
|
||||
let mut entries: Vec<_> = map.modules[module].scope.resolutions().collect();
|
||||
entries.sort_by_key(|(name, _)| name.clone());
|
||||
|
||||
for (name, def) in entries {
|
||||
*buf += &format!("{}:", name);
|
||||
|
||||
if def.types.is_some() {
|
||||
*buf += " t";
|
||||
}
|
||||
if def.values.is_some() {
|
||||
*buf += " v";
|
||||
}
|
||||
if def.macros.is_some() {
|
||||
*buf += " m";
|
||||
}
|
||||
if def.is_none() {
|
||||
*buf += " _";
|
||||
}
|
||||
|
||||
*buf += "\n";
|
||||
}
|
||||
|
||||
for (name, child) in map.modules[module].children.iter() {
|
||||
let path = path.to_string() + &format!("::{}", name);
|
||||
go(buf, map, &path, *child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn crate_def_map_smoke_test() {
|
||||
let map = def_map(
|
||||
|
|
Loading…
Reference in a new issue