From a872ebf81f20815501299ae562c39bb9c872ba47 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sun, 24 Jan 2021 01:32:52 +0100 Subject: Support unions in symbol search --- crates/completion/src/render.rs | 3 +-- crates/ide/src/display/navigation_target.rs | 1 + crates/ide_db/src/symbol_index.rs | 14 +++++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/crates/completion/src/render.rs b/crates/completion/src/render.rs index 6eb20df2b..e11b881ca 100644 --- a/crates/completion/src/render.rs +++ b/crates/completion/src/render.rs @@ -201,8 +201,7 @@ impl<'a> Render<'a> { ScopeDef::ModuleDef(Module(..)) => CompletionItemKind::SymbolKind(SymbolKind::Module), ScopeDef::ModuleDef(Adt(adt)) => CompletionItemKind::SymbolKind(match adt { hir::Adt::Struct(_) => SymbolKind::Struct, - // FIXME: add CompletionItemKind::Union - hir::Adt::Union(_) => SymbolKind::Struct, + hir::Adt::Union(_) => SymbolKind::Union, hir::Adt::Enum(_) => SymbolKind::Enum, }), ScopeDef::ModuleDef(Const(..)) => CompletionItemKind::SymbolKind(SymbolKind::Const), diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs index 16fa828ad..f178dd744 100644 --- a/crates/ide/src/display/navigation_target.rs +++ b/crates/ide/src/display/navigation_target.rs @@ -173,6 +173,7 @@ impl ToNav for FileSymbol { FileSymbolKind::Const => SymbolKind::Const, FileSymbolKind::Static => SymbolKind::Static, FileSymbolKind::Macro => SymbolKind::Macro, + FileSymbolKind::Union => SymbolKind::Union, }), full_range: self.range, focus_range: self.name_range, diff --git a/crates/ide_db/src/symbol_index.rs b/crates/ide_db/src/symbol_index.rs index e954bd72e..9ed9568ce 100644 --- a/crates/ide_db/src/symbol_index.rs +++ b/crates/ide_db/src/symbol_index.rs @@ -356,15 +356,16 @@ pub struct FileSymbol { #[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)] pub enum FileSymbolKind { + Const, + Enum, Function, + Macro, + Module, + Static, Struct, - Enum, Trait, - Module, TypeAlias, - Const, - Static, - Macro, + Union, } impl FileSymbolKind { @@ -375,6 +376,7 @@ impl FileSymbolKind { | FileSymbolKind::Enum | FileSymbolKind::Trait | FileSymbolKind::TypeAlias + | FileSymbolKind::Union ) } } @@ -425,6 +427,7 @@ fn to_symbol(node: &SyntaxNode) -> Option<(SmolStr, SyntaxNodePtr, TextRange)> { ast::Const(it) => decl(it), ast::Static(it) => decl(it), ast::MacroRules(it) => decl(it), + ast::Union(it) => decl(it), _ => None, } } @@ -443,6 +446,7 @@ fn to_file_symbol(node: &SyntaxNode, file_id: FileId) -> Option { CONST => FileSymbolKind::Const, STATIC => FileSymbolKind::Static, MACRO_RULES => FileSymbolKind::Macro, + UNION => FileSymbolKind::Union, kind => unreachable!("{:?}", kind), }, range: node.text_range(), -- cgit v1.2.3