Support unions in symbol search

This commit is contained in:
Lukas Wirth 2021-01-24 01:32:52 +01:00
parent 89fef5307e
commit a872ebf81f
3 changed files with 13 additions and 9 deletions

View file

@ -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),

View file

@ -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,

View file

@ -356,15 +356,16 @@ pub struct FileSymbol {
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
pub enum FileSymbolKind {
Function,
Struct,
Enum,
Trait,
Module,
TypeAlias,
Const,
Static,
Enum,
Function,
Macro,
Module,
Static,
Struct,
Trait,
TypeAlias,
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<FileSymbol> {
CONST => FileSymbolKind::Const,
STATIC => FileSymbolKind::Static,
MACRO_RULES => FileSymbolKind::Macro,
UNION => FileSymbolKind::Union,
kind => unreachable!("{:?}", kind),
},
range: node.text_range(),