aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/completion/completion_item.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/completion/completion_item.rs')
-rw-r--r--crates/ra_ide_api/src/completion/completion_item.rs59
1 files changed, 21 insertions, 38 deletions
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs
index 18c151932..3ba6c33ee 100644
--- a/crates/ra_ide_api/src/completion/completion_item.rs
+++ b/crates/ra_ide_api/src/completion/completion_item.rs
@@ -1,6 +1,4 @@
1use hir::{Docs, Documentation, PerNs}; 1use hir::{Docs, Documentation};
2
3use crate::completion::completion_context::CompletionContext;
4use ra_syntax::{ 2use ra_syntax::{
5 ast::{self, AstNode}, 3 ast::{self, AstNode},
6 TextRange, 4 TextRange,
@@ -8,6 +6,8 @@ use ra_syntax::{
8use ra_text_edit::TextEdit; 6use ra_text_edit::TextEdit;
9use test_utils::tested_by; 7use test_utils::tested_by;
10 8
9use crate::completion::completion_context::CompletionContext;
10
11/// `CompletionItem` describes a single completion variant in the editor pop-up. 11/// `CompletionItem` describes a single completion variant in the editor pop-up.
12/// It is basically a POD with various properties. To construct a 12/// It is basically a POD with various properties. To construct a
13/// `CompletionItem`, use `new` method and the `Builder` struct. 13/// `CompletionItem`, use `new` method and the `Builder` struct.
@@ -209,41 +209,24 @@ impl Builder {
209 ctx: &CompletionContext, 209 ctx: &CompletionContext,
210 resolution: &hir::Resolution, 210 resolution: &hir::Resolution,
211 ) -> Builder { 211 ) -> Builder {
212 let resolved = resolution.def_id.map(|d| d.resolve(ctx.db)); 212 let def = resolution
213 let (kind, docs) = match resolved { 213 .def_id
214 PerNs { 214 .take_types()
215 types: Some(hir::Def::Module(..)), 215 .or(resolution.def_id.take_values());
216 .. 216 let def = match def {
217 } => (CompletionItemKind::Module, None), 217 None => return self,
218 PerNs { 218 Some(it) => it,
219 types: Some(hir::Def::Struct(s)), 219 };
220 .. 220 let (kind, docs) = match def {
221 } => (CompletionItemKind::Struct, s.docs(ctx.db)), 221 hir::ModuleDef::Module(_) => (CompletionItemKind::Module, None),
222 PerNs { 222 hir::ModuleDef::Function(func) => return self.from_function(ctx, func),
223 types: Some(hir::Def::Enum(e)), 223 hir::ModuleDef::Struct(it) => (CompletionItemKind::Struct, it.docs(ctx.db)),
224 .. 224 hir::ModuleDef::Enum(it) => (CompletionItemKind::Enum, it.docs(ctx.db)),
225 } => (CompletionItemKind::Enum, e.docs(ctx.db)), 225 hir::ModuleDef::EnumVariant(it) => (CompletionItemKind::EnumVariant, it.docs(ctx.db)),
226 PerNs { 226 hir::ModuleDef::Const(it) => (CompletionItemKind::Const, it.docs(ctx.db)),
227 types: Some(hir::Def::Trait(t)), 227 hir::ModuleDef::Static(it) => (CompletionItemKind::Static, it.docs(ctx.db)),
228 .. 228 hir::ModuleDef::Trait(it) => (CompletionItemKind::Trait, it.docs(ctx.db)),
229 } => (CompletionItemKind::Trait, t.docs(ctx.db)), 229 hir::ModuleDef::Type(it) => (CompletionItemKind::TypeAlias, it.docs(ctx.db)),
230 PerNs {
231 types: Some(hir::Def::Type(t)),
232 ..
233 } => (CompletionItemKind::TypeAlias, t.docs(ctx.db)),
234 PerNs {
235 values: Some(hir::Def::Const(c)),
236 ..
237 } => (CompletionItemKind::Const, c.docs(ctx.db)),
238 PerNs {
239 values: Some(hir::Def::Static(s)),
240 ..
241 } => (CompletionItemKind::Static, s.docs(ctx.db)),
242 PerNs {
243 values: Some(hir::Def::Function(function)),
244 ..
245 } => return self.from_function(ctx, function),
246 _ => return self,
247 }; 230 };
248 self.kind = Some(kind); 231 self.kind = Some(kind);
249 self.documentation = docs; 232 self.documentation = docs;