7413: Handle unions in symbol search r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
bors[bot] 2021-01-24 00:42:59 +00:00 committed by GitHub
commit a7a1bb444d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 9 deletions

View File

@ -201,8 +201,7 @@ fn render_resolution(
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 @@ fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
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 @@ fn is_type(self: FileSymbolKind) -> bool {
| FileSymbolKind::Enum
| FileSymbolKind::Trait
| FileSymbolKind::TypeAlias
| FileSymbolKind::Union
)
}
}
@ -425,6 +427,7 @@ fn decl<N: NameOwner>(node: N) -> 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(),