about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorDavid Barsky <me@davidbarsky.com>2025-07-07 15:15:27 +0000
committerGitHub <noreply@github.com>2025-07-07 15:15:27 +0000
commit7fbbdb62955e13ec3825fe9fe954ed4b3747200f (patch)
treed1e28c2ac15471b39d156850bdd0278df759291a /src/tools
parent1cf9a7bd7b639aaaa774480041020ee5bf4ec700 (diff)
parenta9b8eec4b7d69176e14646c13b0580b4cdb9eab2 (diff)
downloadrust-7fbbdb62955e13ec3825fe9fe954ed4b3747200f.tar.gz
rust-7fbbdb62955e13ec3825fe9fe954ed4b3747200f.zip
Merge pull request #20185 from ChayimFriedman2/variant-symbols
feat: Include enum variants in world symbols
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/rust-analyzer/crates/hir/src/symbols.rs7
-rw-r--r--src/tools/rust-analyzer/crates/ide-db/src/test_data/test_symbol_index_collection.txt68
2 files changed, 75 insertions, 0 deletions
diff --git a/src/tools/rust-analyzer/crates/hir/src/symbols.rs b/src/tools/rust-analyzer/crates/hir/src/symbols.rs
index 756650891d4..dca10193e29 100644
--- a/src/tools/rust-analyzer/crates/hir/src/symbols.rs
+++ b/src/tools/rust-analyzer/crates/hir/src/symbols.rs
@@ -125,6 +125,13 @@ impl<'a> SymbolCollector<'a> {
                 }
                 ModuleDefId::AdtId(AdtId::EnumId(id)) => {
                     this.push_decl(id, name, false, None);
+                    let enum_name = this.db.enum_signature(id).name.as_str().to_smolstr();
+                    this.with_container_name(Some(enum_name), |this| {
+                        let variants = id.enum_variants(this.db);
+                        for (variant_id, variant_name, _) in &variants.variants {
+                            this.push_decl(*variant_id, variant_name, true, None);
+                        }
+                    });
                 }
                 ModuleDefId::AdtId(AdtId::UnionId(id)) => {
                     this.push_decl(id, name, false, None);
diff --git a/src/tools/rust-analyzer/crates/ide-db/src/test_data/test_symbol_index_collection.txt b/src/tools/rust-analyzer/crates/ide-db/src/test_data/test_symbol_index_collection.txt
index de046e70c67..973256c470f 100644
--- a/src/tools/rust-analyzer/crates/ide-db/src/test_data/test_symbol_index_collection.txt
+++ b/src/tools/rust-analyzer/crates/ide-db/src/test_data/test_symbol_index_collection.txt
@@ -11,6 +11,40 @@
         },
         [
             FileSymbol {
+                name: "A",
+                def: Variant(
+                    Variant {
+                        id: EnumVariantId(
+                            7800,
+                        ),
+                    },
+                ),
+                loc: DeclarationLocation {
+                    hir_file_id: FileId(
+                        EditionedFileId(
+                            Id(2000),
+                        ),
+                    ),
+                    ptr: SyntaxNodePtr {
+                        kind: VARIANT,
+                        range: 201..202,
+                    },
+                    name_ptr: AstPtr(
+                        SyntaxNodePtr {
+                            kind: NAME,
+                            range: 201..202,
+                        },
+                    ),
+                },
+                container_name: Some(
+                    "Enum",
+                ),
+                is_alias: false,
+                is_assoc: true,
+                is_import: false,
+                do_not_complete: Yes,
+            },
+            FileSymbol {
                 name: "Alias",
                 def: TypeAlias(
                     TypeAlias {
@@ -43,6 +77,40 @@
                 do_not_complete: Yes,
             },
             FileSymbol {
+                name: "B",
+                def: Variant(
+                    Variant {
+                        id: EnumVariantId(
+                            7801,
+                        ),
+                    },
+                ),
+                loc: DeclarationLocation {
+                    hir_file_id: FileId(
+                        EditionedFileId(
+                            Id(2000),
+                        ),
+                    ),
+                    ptr: SyntaxNodePtr {
+                        kind: VARIANT,
+                        range: 204..205,
+                    },
+                    name_ptr: AstPtr(
+                        SyntaxNodePtr {
+                            kind: NAME,
+                            range: 204..205,
+                        },
+                    ),
+                },
+                container_name: Some(
+                    "Enum",
+                ),
+                is_alias: false,
+                is_assoc: true,
+                is_import: false,
+                do_not_complete: Yes,
+            },
+            FileSymbol {
                 name: "CONST",
                 def: Const(
                     Const {