Skip to content

Commit 5bae4f5

Browse files
authored
Merge pull request #20185 from ChayimFriedman2/variant-symbols
feat: Include enum variants in world symbols
2 parents 0ac6559 + b34e5b7 commit 5bae4f5

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

crates/hir/src/symbols.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ impl<'a> SymbolCollector<'a> {
125125
}
126126
ModuleDefId::AdtId(AdtId::EnumId(id)) => {
127127
this.push_decl(id, name, false, None);
128+
let enum_name = this.db.enum_signature(id).name.as_str().to_smolstr();
129+
this.with_container_name(Some(enum_name), |this| {
130+
let variants = id.enum_variants(this.db);
131+
for (variant_id, variant_name, _) in &variants.variants {
132+
this.push_decl(*variant_id, variant_name, true, None);
133+
}
134+
});
128135
}
129136
ModuleDefId::AdtId(AdtId::UnionId(id)) => {
130137
this.push_decl(id, name, false, None);

crates/ide-db/src/test_data/test_symbol_index_collection.txt

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,40 @@
1010
},
1111
},
1212
[
13+
FileSymbol {
14+
name: "A",
15+
def: Variant(
16+
Variant {
17+
id: EnumVariantId(
18+
7800,
19+
),
20+
},
21+
),
22+
loc: DeclarationLocation {
23+
hir_file_id: FileId(
24+
EditionedFileId(
25+
Id(2000),
26+
),
27+
),
28+
ptr: SyntaxNodePtr {
29+
kind: VARIANT,
30+
range: 201..202,
31+
},
32+
name_ptr: AstPtr(
33+
SyntaxNodePtr {
34+
kind: NAME,
35+
range: 201..202,
36+
},
37+
),
38+
},
39+
container_name: Some(
40+
"Enum",
41+
),
42+
is_alias: false,
43+
is_assoc: true,
44+
is_import: false,
45+
do_not_complete: Yes,
46+
},
1347
FileSymbol {
1448
name: "Alias",
1549
def: TypeAlias(
@@ -42,6 +76,40 @@
4276
is_import: false,
4377
do_not_complete: Yes,
4478
},
79+
FileSymbol {
80+
name: "B",
81+
def: Variant(
82+
Variant {
83+
id: EnumVariantId(
84+
7801,
85+
),
86+
},
87+
),
88+
loc: DeclarationLocation {
89+
hir_file_id: FileId(
90+
EditionedFileId(
91+
Id(2000),
92+
),
93+
),
94+
ptr: SyntaxNodePtr {
95+
kind: VARIANT,
96+
range: 204..205,
97+
},
98+
name_ptr: AstPtr(
99+
SyntaxNodePtr {
100+
kind: NAME,
101+
range: 204..205,
102+
},
103+
),
104+
},
105+
container_name: Some(
106+
"Enum",
107+
),
108+
is_alias: false,
109+
is_assoc: true,
110+
is_import: false,
111+
do_not_complete: Yes,
112+
},
45113
FileSymbol {
46114
name: "CONST",
47115
def: Const(

0 commit comments

Comments
 (0)