diff options
author | Aleksey Kladov <aleksey.kladov@gmail.com> | 2019-01-23 20:14:13 +0000 |
---|---|---|
committer | Aleksey Kladov <aleksey.kladov@gmail.com> | 2019-01-24 10:29:19 +0000 |
commit | 3ab1519cb27b927074ed7fbbb18a856e6e7fabb8 (patch) | |
tree | 692c7a256604e188d38890966290bd1637d7dd60 /crates/ra_ide_api/src/completion | |
parent | cfb085ded8d61d7b744d0a83ecbb3da254f6ab9f (diff) |
Change ids strategy
this is a part of larghish hir refactoring which aims to
* replace per-source-root module trees with per crate trees
* switch from a monotyped DedId to type-specific ids
Diffstat (limited to 'crates/ra_ide_api/src/completion')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_path.rs | 37 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/completion_item.rs | 61 |
2 files changed, 43 insertions, 55 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index e44b76c4a..0d7942496 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs | |||
@@ -13,8 +13,8 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
13 | Some(it) => it, | 13 | Some(it) => it, |
14 | None => return, | 14 | None => return, |
15 | }; | 15 | }; |
16 | match def_id.resolve(ctx.db) { | 16 | match def_id { |
17 | hir::Def::Module(module) => { | 17 | hir::ModuleDef::Module(module) => { |
18 | let module_scope = module.scope(ctx.db); | 18 | let module_scope = module.scope(ctx.db); |
19 | for (name, res) in module_scope.entries() { | 19 | for (name, res) in module_scope.entries() { |
20 | CompletionItem::new( | 20 | CompletionItem::new( |
@@ -26,21 +26,24 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
26 | .add_to(acc); | 26 | .add_to(acc); |
27 | } | 27 | } |
28 | } | 28 | } |
29 | hir::Def::Enum(e) => { | 29 | |
30 | e.variants(ctx.db) | 30 | hir::ModuleDef::Def(def_id) => match def_id.resolve(ctx.db) { |
31 | .into_iter() | 31 | hir::Def::Enum(e) => { |
32 | .for_each(|(variant_name, variant)| { | 32 | e.variants(ctx.db) |
33 | CompletionItem::new( | 33 | .into_iter() |
34 | CompletionKind::Reference, | 34 | .for_each(|(variant_name, variant)| { |
35 | ctx.source_range(), | 35 | CompletionItem::new( |
36 | variant_name.to_string(), | 36 | CompletionKind::Reference, |
37 | ) | 37 | ctx.source_range(), |
38 | .kind(CompletionItemKind::EnumVariant) | 38 | variant_name.to_string(), |
39 | .set_documentation(variant.docs(ctx.db)) | 39 | ) |
40 | .add_to(acc) | 40 | .kind(CompletionItemKind::EnumVariant) |
41 | }); | 41 | .set_documentation(variant.docs(ctx.db)) |
42 | } | 42 | .add_to(acc) |
43 | _ => return, | 43 | }); |
44 | } | ||
45 | _ => return, | ||
46 | }, | ||
44 | }; | 47 | }; |
45 | } | 48 | } |
46 | 49 | ||
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; |