This commit is contained in:
Aleksey Kladov 2020-07-20 17:44:44 +02:00
parent c9c518e5e9
commit c7ccfb072c
2 changed files with 11 additions and 11 deletions

View file

@ -229,12 +229,11 @@ impl CrateDefMap {
// even), as this should be a great debugging aid. // even), as this should be a great debugging aid.
pub fn dump(&self) -> String { pub fn dump(&self) -> String {
let mut buf = String::new(); let mut buf = String::new();
go(&mut buf, self, "\ncrate", self.root); go(&mut buf, self, "crate", self.root);
return buf.trim().to_string(); return buf;
fn go(buf: &mut String, map: &CrateDefMap, path: &str, module: LocalModuleId) { fn go(buf: &mut String, map: &CrateDefMap, path: &str, module: LocalModuleId) {
*buf += path; format_to!(buf, "{}\n", path);
*buf += "\n";
let mut entries: Vec<_> = map.modules[module].scope.resolutions().collect(); let mut entries: Vec<_> = map.modules[module].scope.resolutions().collect();
entries.sort_by_key(|(name, _)| name.clone()); entries.sort_by_key(|(name, _)| name.clone());
@ -243,23 +242,24 @@ impl CrateDefMap {
format_to!(buf, "{}:", name); format_to!(buf, "{}:", name);
if def.types.is_some() { if def.types.is_some() {
*buf += " t"; buf.push_str(" t");
} }
if def.values.is_some() { if def.values.is_some() {
*buf += " v"; buf.push_str(" v");
} }
if def.macros.is_some() { if def.macros.is_some() {
*buf += " m"; buf.push_str(" m");
} }
if def.is_none() { if def.is_none() {
*buf += " _"; buf.push_str(" _");
} }
*buf += "\n"; buf.push_str("\n");
} }
for (name, child) in map.modules[module].children.iter() { for (name, child) in map.modules[module].children.iter() {
let path = &format!("{}::{}", path, name); let path = format!("{}::{}", path, name);
buf.push('\n');
go(buf, map, &path, *child); go(buf, map, &path, *child);
} }
} }

View file

@ -21,7 +21,7 @@ fn compute_crate_def_map(fixture: &str) -> Arc<CrateDefMap> {
fn check(ra_fixture: &str, expect: Expect) { fn check(ra_fixture: &str, expect: Expect) {
let db = TestDB::with_files(ra_fixture); let db = TestDB::with_files(ra_fixture);
let krate = db.crate_graph().iter().next().unwrap(); let krate = db.crate_graph().iter().next().unwrap();
let actual = db.crate_def_map(krate).dump() + "\n"; let actual = db.crate_def_map(krate).dump();
expect.assert_eq(&actual); expect.assert_eq(&actual);
} }