aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/completion
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/completion')
-rw-r--r--crates/ra_ide_api/src/completion/complete_dot.rs9
-rw-r--r--crates/ra_ide_api/src/completion/complete_path.rs6
-rw-r--r--crates/ra_ide_api/src/completion/completion_context.rs2
-rw-r--r--crates/ra_ide_api/src/completion/completion_item.rs59
4 files changed, 30 insertions, 46 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs
index 07007d03f..6a9358d33 100644
--- a/crates/ra_ide_api/src/completion/complete_dot.rs
+++ b/crates/ra_ide_api/src/completion/complete_dot.rs
@@ -1,4 +1,4 @@
1use hir::{Ty, Def}; 1use hir::{Ty, AdtDef};
2 2
3use crate::completion::{CompletionContext, Completions, CompletionItem, CompletionItemKind}; 3use crate::completion::{CompletionContext, Completions, CompletionItem, CompletionItemKind};
4use crate::completion::completion_item::CompletionKind; 4use crate::completion::completion_item::CompletionKind;
@@ -28,8 +28,8 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty)
28 Ty::Adt { 28 Ty::Adt {
29 def_id, ref substs, .. 29 def_id, ref substs, ..
30 } => { 30 } => {
31 match def_id.resolve(ctx.db) { 31 match def_id {
32 Def::Struct(s) => { 32 AdtDef::Struct(s) => {
33 for field in s.fields(ctx.db) { 33 for field in s.fields(ctx.db) {
34 CompletionItem::new( 34 CompletionItem::new(
35 CompletionKind::Reference, 35 CompletionKind::Reference,
@@ -41,8 +41,9 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty)
41 .add_to(acc); 41 .add_to(acc);
42 } 42 }
43 } 43 }
44
44 // TODO unions 45 // TODO unions
45 _ => {} 46 AdtDef::Enum(_) => (),
46 } 47 }
47 } 48 }
48 Ty::Tuple(fields) => { 49 Ty::Tuple(fields) => {
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs
index e44b76c4a..e72586e2e 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,7 +26,7 @@ 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 hir::ModuleDef::Enum(e) => {
30 e.variants(ctx.db) 30 e.variants(ctx.db)
31 .into_iter() 31 .into_iter()
32 .for_each(|(variant_name, variant)| { 32 .for_each(|(variant_name, variant)| {
diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs
index ca2069e2a..578af6e5b 100644
--- a/crates/ra_ide_api/src/completion/completion_context.rs
+++ b/crates/ra_ide_api/src/completion/completion_context.rs
@@ -127,7 +127,7 @@ impl<'a> CompletionContext<'a> {
127 .ancestors() 127 .ancestors()
128 .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE) 128 .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE)
129 .find_map(ast::FnDef::cast); 129 .find_map(ast::FnDef::cast);
130 match (&self.module, self.function_syntax) { 130 match (self.module, self.function_syntax) {
131 (Some(module), Some(fn_def)) => { 131 (Some(module), Some(fn_def)) => {
132 let function = source_binder::function_from_module(self.db, module, fn_def); 132 let function = source_binder::function_from_module(self.db, module, fn_def);
133 self.function = Some(function); 133 self.function = Some(function);
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;