aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_ide_api/src/completion/complete_dot.rs32
-rw-r--r--crates/ra_ide_api/src/completion/complete_path.rs35
-rw-r--r--crates/ra_ide_api/src/completion/completion_item.rs4
-rw-r--r--crates/ra_ide_api/src/navigation_target.rs20
4 files changed, 45 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 1a2b0b2f6..d0fa8146c 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, AdtDef}; 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;
@@ -29,23 +29,21 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty)
29 def_id, ref substs, .. 29 def_id, ref substs, ..
30 } => { 30 } => {
31 match def_id { 31 match def_id {
32 AdtDef::Struct() => {} 32 AdtDef::Struct(s) => {
33 AdtDef::Def(def_id) => match def_id.resolve(ctx.db) { 33 for field in s.fields(ctx.db) {
34 Def::Struct(s) => { 34 CompletionItem::new(
35 for field in s.fields(ctx.db) { 35 CompletionKind::Reference,
36 CompletionItem::new( 36 ctx.source_range(),
37 CompletionKind::Reference, 37 field.name().to_string(),
38 ctx.source_range(), 38 )
39 field.name().to_string(), 39 .kind(CompletionItemKind::Field)
40 ) 40 .set_detail(field.ty(ctx.db).map(|ty| ty.subst(substs).to_string()))
41 .kind(CompletionItemKind::Field) 41 .add_to(acc);
42 .set_detail(field.ty(ctx.db).map(|ty| ty.subst(substs).to_string()))
43 .add_to(acc);
44 }
45 } 42 }
46 // TODO unions 43 }
47 _ => {} 44
48 }, 45 // TODO unions
46 AdtDef::Enum(_) => (),
49 } 47 }
50 } 48 }
51 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 3aef479d9..e039a333c 100644
--- a/crates/ra_ide_api/src/completion/complete_path.rs
+++ b/crates/ra_ide_api/src/completion/complete_path.rs
@@ -26,26 +26,21 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
26 .add_to(acc); 26 .add_to(acc);
27 } 27 }
28 } 28 }
29 29 hir::ModuleDef::Enum(e) => {
30 hir::ModuleDef::Def(def_id) => match def_id.resolve(ctx.db) { 30 e.variants(ctx.db)
31 hir::Def::Enum(e) => { 31 .into_iter()
32 e.variants(ctx.db) 32 .for_each(|(variant_name, variant)| {
33 .into_iter() 33 CompletionItem::new(
34 .for_each(|(variant_name, variant)| { 34 CompletionKind::Reference,
35 CompletionItem::new( 35 ctx.source_range(),
36 CompletionKind::Reference, 36 variant_name.to_string(),
37 ctx.source_range(), 37 )
38 variant_name.to_string(), 38 .kind(CompletionItemKind::EnumVariant)
39 ) 39 .set_documentation(variant.docs(ctx.db))
40 .kind(CompletionItemKind::EnumVariant) 40 .add_to(acc)
41 .set_documentation(variant.docs(ctx.db)) 41 });
42 .add_to(acc) 42 }
43 }); 43 hir::ModuleDef::Function(_) | hir::ModuleDef::Struct(_) | hir::ModuleDef::Def(_) => return,
44 }
45 _ => return,
46 },
47
48 hir::ModuleDef::Function(_) => return,
49 }; 44 };
50} 45}
51 46
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs
index 5b2ba7e4a..f2301653a 100644
--- a/crates/ra_ide_api/src/completion/completion_item.rs
+++ b/crates/ra_ide_api/src/completion/completion_item.rs
@@ -220,9 +220,9 @@ impl Builder {
220 let (kind, docs) = match def { 220 let (kind, docs) = match def {
221 hir::ModuleDef::Module(_) => (CompletionItemKind::Module, None), 221 hir::ModuleDef::Module(_) => (CompletionItemKind::Module, None),
222 hir::ModuleDef::Function(func) => return self.from_function(ctx, func), 222 hir::ModuleDef::Function(func) => return self.from_function(ctx, func),
223 hir::ModuleDef::Struct(it) => (CompletionItemKind::Struct, it.docs(ctx.db)),
224 hir::ModuleDef::Enum(it) => (CompletionItemKind::Enum, it.docs(ctx.db)),
223 hir::ModuleDef::Def(def_id) => match def_id.resolve(ctx.db) { 225 hir::ModuleDef::Def(def_id) => match def_id.resolve(ctx.db) {
224 hir::Def::Struct(it) => (CompletionItemKind::Struct, it.docs(ctx.db)),
225 hir::Def::Enum(it) => (CompletionItemKind::Enum, it.docs(ctx.db)),
226 hir::Def::Trait(it) => (CompletionItemKind::Trait, it.docs(ctx.db)), 226 hir::Def::Trait(it) => (CompletionItemKind::Trait, it.docs(ctx.db)),
227 hir::Def::Type(it) => (CompletionItemKind::TypeAlias, it.docs(ctx.db)), 227 hir::Def::Type(it) => (CompletionItemKind::TypeAlias, it.docs(ctx.db)),
228 hir::Def::Const(it) => (CompletionItemKind::Const, it.docs(ctx.db)), 228 hir::Def::Const(it) => (CompletionItemKind::Const, it.docs(ctx.db)),
diff --git a/crates/ra_ide_api/src/navigation_target.rs b/crates/ra_ide_api/src/navigation_target.rs
index 19cea2fd6..b92670f36 100644
--- a/crates/ra_ide_api/src/navigation_target.rs
+++ b/crates/ra_ide_api/src/navigation_target.rs
@@ -114,17 +114,23 @@ impl NavigationTarget {
114 hir::ModuleDef::Function(func) => { 114 hir::ModuleDef::Function(func) => {
115 return Some(NavigationTarget::from_function(db, func)); 115 return Some(NavigationTarget::from_function(db, func));
116 } 116 }
117 }; 117 hir::ModuleDef::Struct(s) => {
118
119 let res = match def {
120 Def::Struct(s) => {
121 let (file_id, node) = s.source(db); 118 let (file_id, node) = s.source(db);
122 NavigationTarget::from_named(file_id.original_file(db), &*node) 119 return Some(NavigationTarget::from_named(
120 file_id.original_file(db),
121 &*node,
122 ));
123 } 123 }
124 Def::Enum(e) => { 124 hir::ModuleDef::Enum(e) => {
125 let (file_id, node) = e.source(db); 125 let (file_id, node) = e.source(db);
126 NavigationTarget::from_named(file_id.original_file(db), &*node) 126 return Some(NavigationTarget::from_named(
127 file_id.original_file(db),
128 &*node,
129 ));
127 } 130 }
131 };
132
133 let res = match def {
128 Def::EnumVariant(ev) => { 134 Def::EnumVariant(ev) => {
129 let (file_id, node) = ev.source(db); 135 let (file_id, node) = ev.source(db);
130 NavigationTarget::from_named(file_id.original_file(db), &*node) 136 NavigationTarget::from_named(file_id.original_file(db), &*node)