fix symbol index collection not collecting legacy macros

This commit is contained in:
Lukas Wirth 2022-03-09 01:44:20 +01:00
parent 4e94fb7028
commit f9c8646d89
4 changed files with 260 additions and 251 deletions

View file

@ -174,6 +174,13 @@ impl<'a> SymbolCollector<'a> {
for const_id in scope.unnamed_consts() { for const_id in scope.unnamed_consts() {
self.collect_from_body(const_id); self.collect_from_body(const_id);
} }
for (_, id) in scope.legacy_macros() {
let loc = id.lookup(self.db.upcast());
if loc.container == module_id {
self.push_decl(id, FileSymbolKind::Macro);
}
}
} }
fn collect_from_body(&mut self, body_id: impl Into<DefWithBodyId>) { fn collect_from_body(&mut self, body_id: impl Into<DefWithBodyId>) {

View file

@ -128,9 +128,7 @@ impl ItemScope {
} }
/// Iterate over all legacy textual scoped macros visible at the end of the module /// Iterate over all legacy textual scoped macros visible at the end of the module
pub(crate) fn legacy_macros<'a>( pub fn legacy_macros<'a>(&'a self) -> impl Iterator<Item = (&'a Name, MacroRulesId)> + 'a {
&'a self,
) -> impl Iterator<Item = (&'a Name, MacroRulesId)> + 'a {
self.legacy_macros.iter().map(|(name, def)| (name, *def)) self.legacy_macros.iter().map(|(name, def)| (name, *def))
} }

View file

@ -425,7 +425,11 @@ struct StructInModB;
let symbols: Vec<_> = Crate::from(db.test_crate()) let symbols: Vec<_> = Crate::from(db.test_crate())
.modules(&db) .modules(&db)
.into_iter() .into_iter()
.map(|module_id| (module_id, SymbolCollector::collect(&db, module_id))) .map(|module_id| {
let mut symbols = SymbolCollector::collect(&db, module_id);
symbols.sort_by_key(|it| it.name.clone());
(module_id, symbols)
})
.collect(); .collect();
expect_file!["./test_data/test_symbol_index_collection.txt"].assert_debug_eq(&symbols); expect_file!["./test_data/test_symbol_index_collection.txt"].assert_debug_eq(&symbols);

View file

@ -11,31 +11,7 @@
}, },
[ [
FileSymbol { FileSymbol {
name: "StructFromMacro", name: "Alias",
loc: DeclarationLocation {
hir_file_id: HirFileId(
MacroFile(
MacroFile {
macro_call_id: MacroCallId(
0,
),
},
),
),
ptr: SyntaxNodePtr {
kind: STRUCT,
range: 0..22,
},
name_ptr: SyntaxNodePtr {
kind: NAME,
range: 6..21,
},
},
kind: Struct,
container_name: None,
},
FileSymbol {
name: "Struct",
loc: DeclarationLocation { loc: DeclarationLocation {
hir_file_id: HirFileId( hir_file_id: HirFileId(
FileId( FileId(
@ -45,127 +21,15 @@
), ),
), ),
ptr: SyntaxNodePtr { ptr: SyntaxNodePtr {
kind: STRUCT, kind: TYPE_ALIAS,
range: 170..184, range: 397..417,
}, },
name_ptr: SyntaxNodePtr { name_ptr: SyntaxNodePtr {
kind: NAME, kind: NAME,
range: 177..183, range: 402..407,
}, },
}, },
kind: Struct, kind: TypeAlias,
container_name: None,
},
FileSymbol {
name: "Enum",
loc: DeclarationLocation {
hir_file_id: HirFileId(
FileId(
FileId(
0,
),
),
),
ptr: SyntaxNodePtr {
kind: ENUM,
range: 185..207,
},
name_ptr: SyntaxNodePtr {
kind: NAME,
range: 190..194,
},
},
kind: Enum,
container_name: None,
},
FileSymbol {
name: "Union",
loc: DeclarationLocation {
hir_file_id: HirFileId(
FileId(
FileId(
0,
),
),
),
ptr: SyntaxNodePtr {
kind: UNION,
range: 208..222,
},
name_ptr: SyntaxNodePtr {
kind: NAME,
range: 214..219,
},
},
kind: Union,
container_name: None,
},
FileSymbol {
name: "Trait",
loc: DeclarationLocation {
hir_file_id: HirFileId(
FileId(
FileId(
0,
),
),
),
ptr: SyntaxNodePtr {
kind: TRAIT,
range: 261..300,
},
name_ptr: SyntaxNodePtr {
kind: NAME,
range: 267..272,
},
},
kind: Trait,
container_name: None,
},
FileSymbol {
name: "trait_fn",
loc: DeclarationLocation {
hir_file_id: HirFileId(
FileId(
FileId(
0,
),
),
),
ptr: SyntaxNodePtr {
kind: FN,
range: 279..298,
},
name_ptr: SyntaxNodePtr {
kind: NAME,
range: 282..290,
},
},
kind: Function,
container_name: Some(
"Trait",
),
},
FileSymbol {
name: "main",
loc: DeclarationLocation {
hir_file_id: HirFileId(
FileId(
FileId(
0,
),
),
),
ptr: SyntaxNodePtr {
kind: FN,
range: 302..338,
},
name_ptr: SyntaxNodePtr {
kind: NAME,
range: 305..309,
},
},
kind: Function,
container_name: None, container_name: None,
}, },
FileSymbol { FileSymbol {
@ -190,6 +54,72 @@
kind: Const, kind: Const,
container_name: None, container_name: None,
}, },
FileSymbol {
name: "CONST_WITH_INNER",
loc: DeclarationLocation {
hir_file_id: HirFileId(
FileId(
FileId(
0,
),
),
),
ptr: SyntaxNodePtr {
kind: CONST,
range: 520..592,
},
name_ptr: SyntaxNodePtr {
kind: NAME,
range: 526..542,
},
},
kind: Const,
container_name: None,
},
FileSymbol {
name: "Enum",
loc: DeclarationLocation {
hir_file_id: HirFileId(
FileId(
FileId(
0,
),
),
),
ptr: SyntaxNodePtr {
kind: ENUM,
range: 185..207,
},
name_ptr: SyntaxNodePtr {
kind: NAME,
range: 190..194,
},
},
kind: Enum,
container_name: None,
},
FileSymbol {
name: "Macro",
loc: DeclarationLocation {
hir_file_id: HirFileId(
FileId(
FileId(
0,
),
),
),
ptr: SyntaxNodePtr {
kind: MACRO_DEF,
range: 153..168,
},
name_ptr: SyntaxNodePtr {
kind: NAME,
range: 159..164,
},
},
kind: Macro,
container_name: None,
},
FileSymbol { FileSymbol {
name: "STATIC", name: "STATIC",
loc: DeclarationLocation { loc: DeclarationLocation {
@ -213,7 +143,7 @@
container_name: None, container_name: None,
}, },
FileSymbol { FileSymbol {
name: "Alias", name: "Struct",
loc: DeclarationLocation { loc: DeclarationLocation {
hir_file_id: HirFileId( hir_file_id: HirFileId(
FileId( FileId(
@ -223,15 +153,153 @@
), ),
), ),
ptr: SyntaxNodePtr { ptr: SyntaxNodePtr {
kind: TYPE_ALIAS, kind: STRUCT,
range: 397..417, range: 170..184,
}, },
name_ptr: SyntaxNodePtr { name_ptr: SyntaxNodePtr {
kind: NAME, kind: NAME,
range: 402..407, range: 177..183,
}, },
}, },
kind: TypeAlias, kind: Struct,
container_name: None,
},
FileSymbol {
name: "StructFromMacro",
loc: DeclarationLocation {
hir_file_id: HirFileId(
MacroFile(
MacroFile {
macro_call_id: MacroCallId(
0,
),
},
),
),
ptr: SyntaxNodePtr {
kind: STRUCT,
range: 0..22,
},
name_ptr: SyntaxNodePtr {
kind: NAME,
range: 6..21,
},
},
kind: Struct,
container_name: None,
},
FileSymbol {
name: "StructInFn",
loc: DeclarationLocation {
hir_file_id: HirFileId(
FileId(
FileId(
0,
),
),
),
ptr: SyntaxNodePtr {
kind: STRUCT,
range: 318..336,
},
name_ptr: SyntaxNodePtr {
kind: NAME,
range: 325..335,
},
},
kind: Struct,
container_name: Some(
"main",
),
},
FileSymbol {
name: "StructInNamedConst",
loc: DeclarationLocation {
hir_file_id: HirFileId(
FileId(
FileId(
0,
),
),
),
ptr: SyntaxNodePtr {
kind: STRUCT,
range: 555..581,
},
name_ptr: SyntaxNodePtr {
kind: NAME,
range: 562..580,
},
},
kind: Struct,
container_name: Some(
"CONST_WITH_INNER",
),
},
FileSymbol {
name: "StructInUnnamedConst",
loc: DeclarationLocation {
hir_file_id: HirFileId(
FileId(
FileId(
0,
),
),
),
ptr: SyntaxNodePtr {
kind: STRUCT,
range: 479..507,
},
name_ptr: SyntaxNodePtr {
kind: NAME,
range: 486..506,
},
},
kind: Struct,
container_name: None,
},
FileSymbol {
name: "Trait",
loc: DeclarationLocation {
hir_file_id: HirFileId(
FileId(
FileId(
0,
),
),
),
ptr: SyntaxNodePtr {
kind: TRAIT,
range: 261..300,
},
name_ptr: SyntaxNodePtr {
kind: NAME,
range: 267..272,
},
},
kind: Trait,
container_name: None,
},
FileSymbol {
name: "Union",
loc: DeclarationLocation {
hir_file_id: HirFileId(
FileId(
FileId(
0,
),
),
),
ptr: SyntaxNodePtr {
kind: UNION,
range: 208..222,
},
name_ptr: SyntaxNodePtr {
kind: NAME,
range: 214..219,
},
},
kind: Union,
container_name: None, container_name: None,
}, },
FileSymbol { FileSymbol {
@ -256,28 +324,6 @@
kind: Module, kind: Module,
container_name: None, container_name: None,
}, },
FileSymbol {
name: "CONST_WITH_INNER",
loc: DeclarationLocation {
hir_file_id: HirFileId(
FileId(
FileId(
0,
),
),
),
ptr: SyntaxNodePtr {
kind: CONST,
range: 520..592,
},
name_ptr: SyntaxNodePtr {
kind: NAME,
range: 526..542,
},
},
kind: Const,
container_name: None,
},
FileSymbol { FileSymbol {
name: "b_mod", name: "b_mod",
loc: DeclarationLocation { loc: DeclarationLocation {
@ -300,6 +346,28 @@
kind: Module, kind: Module,
container_name: None, container_name: None,
}, },
FileSymbol {
name: "define_struct",
loc: DeclarationLocation {
hir_file_id: HirFileId(
FileId(
FileId(
0,
),
),
),
ptr: SyntaxNodePtr {
kind: MACRO_RULES,
range: 51..131,
},
name_ptr: SyntaxNodePtr {
kind: NAME,
range: 64..77,
},
},
kind: Macro,
container_name: None,
},
FileSymbol { FileSymbol {
name: "impl_fn", name: "impl_fn",
loc: DeclarationLocation { loc: DeclarationLocation {
@ -345,7 +413,7 @@
container_name: None, container_name: None,
}, },
FileSymbol { FileSymbol {
name: "define_struct", name: "main",
loc: DeclarationLocation { loc: DeclarationLocation {
hir_file_id: HirFileId( hir_file_id: HirFileId(
FileId( FileId(
@ -355,19 +423,19 @@
), ),
), ),
ptr: SyntaxNodePtr { ptr: SyntaxNodePtr {
kind: MACRO_RULES, kind: FN,
range: 51..131, range: 302..338,
}, },
name_ptr: SyntaxNodePtr { name_ptr: SyntaxNodePtr {
kind: NAME, kind: NAME,
range: 64..77, range: 305..309,
}, },
}, },
kind: Macro, kind: Function,
container_name: None, container_name: None,
}, },
FileSymbol { FileSymbol {
name: "Macro", name: "trait_fn",
loc: DeclarationLocation { loc: DeclarationLocation {
hir_file_id: HirFileId( hir_file_id: HirFileId(
FileId( FileId(
@ -377,85 +445,17 @@
), ),
), ),
ptr: SyntaxNodePtr { ptr: SyntaxNodePtr {
kind: MACRO_DEF, kind: FN,
range: 153..168, range: 279..298,
}, },
name_ptr: SyntaxNodePtr { name_ptr: SyntaxNodePtr {
kind: NAME, kind: NAME,
range: 159..164, range: 282..290,
}, },
}, },
kind: Macro, kind: Function,
container_name: None,
},
FileSymbol {
name: "StructInUnnamedConst",
loc: DeclarationLocation {
hir_file_id: HirFileId(
FileId(
FileId(
0,
),
),
),
ptr: SyntaxNodePtr {
kind: STRUCT,
range: 479..507,
},
name_ptr: SyntaxNodePtr {
kind: NAME,
range: 486..506,
},
},
kind: Struct,
container_name: None,
},
FileSymbol {
name: "StructInNamedConst",
loc: DeclarationLocation {
hir_file_id: HirFileId(
FileId(
FileId(
0,
),
),
),
ptr: SyntaxNodePtr {
kind: STRUCT,
range: 555..581,
},
name_ptr: SyntaxNodePtr {
kind: NAME,
range: 562..580,
},
},
kind: Struct,
container_name: Some( container_name: Some(
"CONST_WITH_INNER", "Trait",
),
},
FileSymbol {
name: "StructInFn",
loc: DeclarationLocation {
hir_file_id: HirFileId(
FileId(
FileId(
0,
),
),
),
ptr: SyntaxNodePtr {
kind: STRUCT,
range: 318..336,
},
name_ptr: SyntaxNodePtr {
kind: NAME,
range: 325..335,
},
},
kind: Struct,
container_name: Some(
"main",
), ),
}, },
], ],