refactor
This commit is contained in:
@@ -50,14 +50,8 @@ impl Completions {
|
|||||||
ScopeDef::ModuleDef(Function(func)) => {
|
ScopeDef::ModuleDef(Function(func)) => {
|
||||||
return self.add_function_with_name(ctx, Some(local_name), *func);
|
return self.add_function_with_name(ctx, Some(local_name), *func);
|
||||||
}
|
}
|
||||||
ScopeDef::ModuleDef(Adt(hir::Adt::Struct(it))) => {
|
ScopeDef::ModuleDef(Adt(adt)) => {
|
||||||
(CompletionItemKind::Struct, it.docs(ctx.db))
|
return self.add_adt_with_name(ctx, local_name, *adt);
|
||||||
}
|
|
||||||
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(EnumVariant(it)) => {
|
ScopeDef::ModuleDef(EnumVariant(it)) => {
|
||||||
(CompletionItemKind::EnumVariant, it.docs(ctx.db))
|
(CompletionItemKind::EnumVariant, it.docs(ctx.db))
|
||||||
@@ -173,6 +167,19 @@ impl Completions {
|
|||||||
self.add(builder)
|
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) {
|
pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) {
|
||||||
let ast_node = constant.source(ctx.db).ast;
|
let ast_node = constant.source(ctx.db).ast;
|
||||||
let name = match ast_node.name() {
|
let name = match ast_node.name() {
|
||||||
|
|||||||
Reference in New Issue
Block a user