aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r--crates/ra_ide_api/src/completion/complete_dot.rs8
-rw-r--r--crates/ra_ide_api/src/completion/complete_path.rs2
-rw-r--r--crates/ra_ide_api/src/completion/complete_struct_literal.rs4
-rw-r--r--crates/ra_ide_api/src/completion/presentation.rs52
4 files changed, 31 insertions, 35 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs
index a6b988062..be76b997e 100644
--- a/crates/ra_ide_api/src/completion/complete_dot.rs
+++ b/crates/ra_ide_api/src/completion/complete_dot.rs
@@ -1,6 +1,6 @@
1use hir::{Ty, AdtDef}; 1use hir::{Ty, AdtDef};
2 2
3use crate::completion::{CompletionContext, Completions, CompletionKind}; 3use crate::completion::{CompletionContext, Completions};
4 4
5/// Complete dot accesses, i.e. fields or methods (currently only fields). 5/// Complete dot accesses, i.e. fields or methods (currently only fields).
6pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) { 6pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
@@ -28,7 +28,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty)
28 match def_id { 28 match def_id {
29 AdtDef::Struct(s) => { 29 AdtDef::Struct(s) => {
30 for field in s.fields(ctx.db) { 30 for field in s.fields(ctx.db) {
31 acc.add_field(CompletionKind::Reference, ctx, field, substs); 31 acc.add_field(ctx, field, substs);
32 } 32 }
33 } 33 }
34 34
@@ -38,7 +38,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty)
38 } 38 }
39 Ty::Tuple(fields) => { 39 Ty::Tuple(fields) => {
40 for (i, ty) in fields.iter().enumerate() { 40 for (i, ty) in fields.iter().enumerate() {
41 acc.add_pos_field(CompletionKind::Reference, ctx, i, ty); 41 acc.add_pos_field(ctx, i, ty);
42 } 42 }
43 } 43 }
44 _ => {} 44 _ => {}
@@ -50,7 +50,7 @@ fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty
50 receiver.iterate_methods(ctx.db, |_ty, func| { 50 receiver.iterate_methods(ctx.db, |_ty, func| {
51 let sig = func.signature(ctx.db); 51 let sig = func.signature(ctx.db);
52 if sig.has_self_param() { 52 if sig.has_self_param() {
53 acc.add_function(CompletionKind::Reference, ctx, func); 53 acc.add_function(ctx, func);
54 } 54 }
55 None::<()> 55 None::<()>
56 }); 56 });
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs
index f8595b5c4..d2f65310f 100644
--- a/crates/ra_ide_api/src/completion/complete_path.rs
+++ b/crates/ra_ide_api/src/completion/complete_path.rs
@@ -64,7 +64,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
64 hir::ImplItem::Method(func) => { 64 hir::ImplItem::Method(func) => {
65 let sig = func.signature(ctx.db); 65 let sig = func.signature(ctx.db);
66 if !sig.has_self_param() { 66 if !sig.has_self_param() {
67 acc.add_function(CompletionKind::Reference, ctx, func); 67 acc.add_function(ctx, func);
68 } 68 }
69 None::<()> 69 None::<()>
70 } 70 }
diff --git a/crates/ra_ide_api/src/completion/complete_struct_literal.rs b/crates/ra_ide_api/src/completion/complete_struct_literal.rs
index c617bff5f..1b8fb0768 100644
--- a/crates/ra_ide_api/src/completion/complete_struct_literal.rs
+++ b/crates/ra_ide_api/src/completion/complete_struct_literal.rs
@@ -1,6 +1,6 @@
1use hir::{Ty, AdtDef}; 1use hir::{Ty, AdtDef};
2 2
3use crate::completion::{CompletionContext, Completions, CompletionKind}; 3use crate::completion::{CompletionContext, Completions};
4 4
5/// Complete fields in fields literals. 5/// Complete fields in fields literals.
6pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionContext) { 6pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionContext) {
@@ -22,7 +22,7 @@ pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionCon
22 match adt { 22 match adt {
23 AdtDef::Struct(s) => { 23 AdtDef::Struct(s) => {
24 for field in s.fields(ctx.db) { 24 for field in s.fields(ctx.db) {
25 acc.add_field(CompletionKind::Reference, ctx, field, substs); 25 acc.add_field(ctx, field, substs);
26 } 26 }
27 } 27 }
28 28
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs
index 057dbc21a..514f3b539 100644
--- a/crates/ra_ide_api/src/completion/presentation.rs
+++ b/crates/ra_ide_api/src/completion/presentation.rs
@@ -10,47 +10,43 @@ use crate::completion::{
10impl Completions { 10impl Completions {
11 pub(crate) fn add_field( 11 pub(crate) fn add_field(
12 &mut self, 12 &mut self,
13 kind: CompletionKind,
14 ctx: &CompletionContext, 13 ctx: &CompletionContext,
15 field: hir::StructField, 14 field: hir::StructField,
16 substs: &hir::Substs, 15 substs: &hir::Substs,
17 ) { 16 ) {
18 CompletionItem::new(kind, ctx.source_range(), field.name(ctx.db).to_string()) 17 CompletionItem::new(
19 .kind(CompletionItemKind::Field) 18 CompletionKind::Reference,
20 .detail(field.ty(ctx.db).subst(substs).to_string()) 19 ctx.source_range(),
21 .set_documentation(field.docs(ctx.db)) 20 field.name(ctx.db).to_string(),
22 .add_to(self); 21 )
22 .kind(CompletionItemKind::Field)
23 .detail(field.ty(ctx.db).subst(substs).to_string())
24 .set_documentation(field.docs(ctx.db))
25 .add_to(self);
23 } 26 }
24 27
25 pub(crate) fn add_pos_field( 28 pub(crate) fn add_pos_field(&mut self, ctx: &CompletionContext, field: usize, ty: &hir::Ty) {
26 &mut self, 29 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), field.to_string())
27 kind: CompletionKind,
28 ctx: &CompletionContext,
29 field: usize,
30 ty: &hir::Ty,
31 ) {
32 CompletionItem::new(kind, ctx.source_range(), field.to_string())
33 .kind(CompletionItemKind::Field) 30 .kind(CompletionItemKind::Field)
34 .detail(ty.to_string()) 31 .detail(ty.to_string())
35 .add_to(self); 32 .add_to(self);
36 } 33 }
37 34
38 pub(crate) fn add_function( 35 pub(crate) fn add_function(&mut self, ctx: &CompletionContext, func: hir::Function) {
39 &mut self,
40 kind: CompletionKind,
41 ctx: &CompletionContext,
42 func: hir::Function,
43 ) {
44 let sig = func.signature(ctx.db); 36 let sig = func.signature(ctx.db);
45 37
46 let mut builder = CompletionItem::new(kind, ctx.source_range(), sig.name().to_string()) 38 let mut builder = CompletionItem::new(
47 .kind(if sig.has_self_param() { 39 CompletionKind::Reference,
48 CompletionItemKind::Method 40 ctx.source_range(),
49 } else { 41 sig.name().to_string(),
50 CompletionItemKind::Function 42 )
51 }) 43 .kind(if sig.has_self_param() {
52 .set_documentation(func.docs(ctx.db)) 44 CompletionItemKind::Method
53 .set_detail(function_item_label(ctx, func)); 45 } else {
46 CompletionItemKind::Function
47 })
48 .set_documentation(func.docs(ctx.db))
49 .set_detail(function_item_label(ctx, func));
54 // If not an import, add parenthesis automatically. 50 // If not an import, add parenthesis automatically.
55 if ctx.use_item_syntax.is_none() && !ctx.is_call { 51 if ctx.use_item_syntax.is_none() && !ctx.is_call {
56 tested_by!(inserts_parens_for_function_calls); 52 tested_by!(inserts_parens_for_function_calls);