mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 01:17:27 +00:00
refactor
This commit is contained in:
parent
06a8deae4a
commit
2f85a640a2
1 changed files with 15 additions and 8 deletions
|
@ -50,14 +50,8 @@ impl Completions {
|
|||
ScopeDef::ModuleDef(Function(func)) => {
|
||||
return self.add_function_with_name(ctx, Some(local_name), *func);
|
||||
}
|
||||
ScopeDef::ModuleDef(Adt(hir::Adt::Struct(it))) => {
|
||||
(CompletionItemKind::Struct, it.docs(ctx.db))
|
||||
}
|
||||
ScopeDef::ModuleDef(Adt(hir::Adt::Union(it))) => {
|
||||
(CompletionItemKind::Struct, it.docs(ctx.db))
|
||||
}
|
||||
ScopeDef::ModuleDef(Adt(hir::Adt::Enum(it))) => {
|
||||
(CompletionItemKind::Enum, it.docs(ctx.db))
|
||||
ScopeDef::ModuleDef(Adt(adt)) => {
|
||||
return self.add_adt_with_name(ctx, local_name, *adt);
|
||||
}
|
||||
ScopeDef::ModuleDef(EnumVariant(it)) => {
|
||||
(CompletionItemKind::EnumVariant, it.docs(ctx.db))
|
||||
|
@ -173,6 +167,19 @@ impl Completions {
|
|||
self.add(builder)
|
||||
}
|
||||
|
||||
fn add_adt_with_name(&mut self, ctx: &CompletionContext, name: String, adt: hir::Adt) {
|
||||
let builder = CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name);
|
||||
|
||||
let (kind, docs) = match adt {
|
||||
hir::Adt::Struct(it) => (CompletionItemKind::Struct, it.docs(ctx.db)),
|
||||
// FIXME: add CompletionItemKind::Union
|
||||
hir::Adt::Union(it) => (CompletionItemKind::Struct, it.docs(ctx.db)),
|
||||
hir::Adt::Enum(it) => (CompletionItemKind::Enum, it.docs(ctx.db)),
|
||||
};
|
||||
|
||||
builder.kind(kind).set_documentation(docs).add_to(self)
|
||||
}
|
||||
|
||||
pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) {
|
||||
let ast_node = constant.source(ctx.db).ast;
|
||||
let name = match ast_node.name() {
|
||||
|
|
Loading…
Reference in a new issue