diff options
Diffstat (limited to 'crates/ra_ide_api/src/completion/completion_item.rs')
-rw-r--r-- | crates/ra_ide_api/src/completion/completion_item.rs | 61 |
1 files changed, 23 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..5d6718a8d 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 @@ | |||
1 | use hir::{Docs, Documentation, PerNs}; | 1 | use hir::{Docs, Documentation}; |
2 | |||
3 | use crate::completion::completion_context::CompletionContext; | ||
4 | use ra_syntax::{ | 2 | use ra_syntax::{ |
5 | ast::{self, AstNode}, | 3 | ast::{self, AstNode}, |
6 | TextRange, | 4 | TextRange, |
@@ -8,6 +6,8 @@ use ra_syntax::{ | |||
8 | use ra_text_edit::TextEdit; | 6 | use ra_text_edit::TextEdit; |
9 | use test_utils::tested_by; | 7 | use test_utils::tested_by; |
10 | 8 | ||
9 | use 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,26 @@ 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::Def(def_id) => match def_id.resolve(ctx.db) { |
223 | types: Some(hir::Def::Enum(e)), | 223 | hir::Def::Struct(it) => (CompletionItemKind::Struct, it.docs(ctx.db)), |
224 | .. | 224 | hir::Def::Enum(it) => (CompletionItemKind::Enum, it.docs(ctx.db)), |
225 | } => (CompletionItemKind::Enum, e.docs(ctx.db)), | 225 | hir::Def::Trait(it) => (CompletionItemKind::Trait, it.docs(ctx.db)), |
226 | PerNs { | 226 | hir::Def::Type(it) => (CompletionItemKind::TypeAlias, it.docs(ctx.db)), |
227 | types: Some(hir::Def::Trait(t)), | 227 | hir::Def::Const(it) => (CompletionItemKind::Const, it.docs(ctx.db)), |
228 | .. | 228 | hir::Def::Static(it) => (CompletionItemKind::Static, it.docs(ctx.db)), |
229 | } => (CompletionItemKind::Trait, t.docs(ctx.db)), | 229 | hir::Def::Function(function) => return self.from_function(ctx, function), |
230 | PerNs { | 230 | _ => return self, |
231 | types: Some(hir::Def::Type(t)), | 231 | }, |
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 | }; | 232 | }; |
248 | self.kind = Some(kind); | 233 | self.kind = Some(kind); |
249 | self.documentation = docs; | 234 | self.documentation = docs; |