fix symbol index collection not collecting legacy macros
This commit is contained in:
parent
4e94fb7028
commit
f9c8646d89
@ -174,6 +174,13 @@ fn collect_from_module(&mut self, module_id: ModuleId) {
|
||||
for const_id in scope.unnamed_consts() {
|
||||
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>) {
|
||||
|
@ -128,9 +128,7 @@ pub(crate) fn macros<'a>(&'a self) -> impl Iterator<Item = (&'a Name, MacroId)>
|
||||
}
|
||||
|
||||
/// Iterate over all legacy textual scoped macros visible at the end of the module
|
||||
pub(crate) fn legacy_macros<'a>(
|
||||
&'a self,
|
||||
) -> impl Iterator<Item = (&'a Name, MacroRulesId)> + 'a {
|
||||
pub fn legacy_macros<'a>(&'a self) -> impl Iterator<Item = (&'a Name, MacroRulesId)> + 'a {
|
||||
self.legacy_macros.iter().map(|(name, def)| (name, *def))
|
||||
}
|
||||
|
||||
|
@ -425,7 +425,11 @@ mod a_mod {
|
||||
let symbols: Vec<_> = Crate::from(db.test_crate())
|
||||
.modules(&db)
|
||||
.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();
|
||||
|
||||
expect_file!["./test_data/test_symbol_index_collection.txt"].assert_debug_eq(&symbols);
|
||||
|
@ -11,31 +11,7 @@
|
||||
},
|
||||
[
|
||||
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: "Struct",
|
||||
name: "Alias",
|
||||
loc: DeclarationLocation {
|
||||
hir_file_id: HirFileId(
|
||||
FileId(
|
||||
@ -45,127 +21,15 @@
|
||||
),
|
||||
),
|
||||
ptr: SyntaxNodePtr {
|
||||
kind: STRUCT,
|
||||
range: 170..184,
|
||||
kind: TYPE_ALIAS,
|
||||
range: 397..417,
|
||||
},
|
||||
name_ptr: SyntaxNodePtr {
|
||||
kind: NAME,
|
||||
range: 177..183,
|
||||
range: 402..407,
|
||||
},
|
||||
},
|
||||
kind: Struct,
|
||||
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,
|
||||
kind: TypeAlias,
|
||||
container_name: None,
|
||||
},
|
||||
FileSymbol {
|
||||
@ -190,6 +54,72 @@
|
||||
kind: Const,
|
||||
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 {
|
||||
name: "STATIC",
|
||||
loc: DeclarationLocation {
|
||||
@ -213,7 +143,7 @@
|
||||
container_name: None,
|
||||
},
|
||||
FileSymbol {
|
||||
name: "Alias",
|
||||
name: "Struct",
|
||||
loc: DeclarationLocation {
|
||||
hir_file_id: HirFileId(
|
||||
FileId(
|
||||
@ -223,15 +153,153 @@
|
||||
),
|
||||
),
|
||||
ptr: SyntaxNodePtr {
|
||||
kind: TYPE_ALIAS,
|
||||
range: 397..417,
|
||||
kind: STRUCT,
|
||||
range: 170..184,
|
||||
},
|
||||
name_ptr: SyntaxNodePtr {
|
||||
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,
|
||||
},
|
||||
FileSymbol {
|
||||
@ -256,28 +324,6 @@
|
||||
kind: Module,
|
||||
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: "b_mod",
|
||||
loc: DeclarationLocation {
|
||||
@ -300,6 +346,28 @@
|
||||
kind: Module,
|
||||
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 {
|
||||
name: "impl_fn",
|
||||
loc: DeclarationLocation {
|
||||
@ -345,7 +413,7 @@
|
||||
container_name: None,
|
||||
},
|
||||
FileSymbol {
|
||||
name: "define_struct",
|
||||
name: "main",
|
||||
loc: DeclarationLocation {
|
||||
hir_file_id: HirFileId(
|
||||
FileId(
|
||||
@ -355,19 +423,19 @@
|
||||
),
|
||||
),
|
||||
ptr: SyntaxNodePtr {
|
||||
kind: MACRO_RULES,
|
||||
range: 51..131,
|
||||
kind: FN,
|
||||
range: 302..338,
|
||||
},
|
||||
name_ptr: SyntaxNodePtr {
|
||||
kind: NAME,
|
||||
range: 64..77,
|
||||
range: 305..309,
|
||||
},
|
||||
},
|
||||
kind: Macro,
|
||||
kind: Function,
|
||||
container_name: None,
|
||||
},
|
||||
FileSymbol {
|
||||
name: "Macro",
|
||||
name: "trait_fn",
|
||||
loc: DeclarationLocation {
|
||||
hir_file_id: HirFileId(
|
||||
FileId(
|
||||
@ -377,85 +445,17 @@
|
||||
),
|
||||
),
|
||||
ptr: SyntaxNodePtr {
|
||||
kind: MACRO_DEF,
|
||||
range: 153..168,
|
||||
kind: FN,
|
||||
range: 279..298,
|
||||
},
|
||||
name_ptr: SyntaxNodePtr {
|
||||
kind: NAME,
|
||||
range: 159..164,
|
||||
range: 282..290,
|
||||
},
|
||||
},
|
||||
kind: Macro,
|
||||
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,
|
||||
kind: Function,
|
||||
container_name: Some(
|
||||
"CONST_WITH_INNER",
|
||||
),
|
||||
},
|
||||
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",
|
||||
"Trait",
|
||||
),
|
||||
},
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user