mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +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)) => {
|
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() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue