diff options
Diffstat (limited to 'crates/ra_ide_api/src/completion')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_dot.rs | 3 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_path.rs | 6 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/presentation.rs | 20 |
3 files changed, 14 insertions, 15 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index 4e2c497e1..5a3f9b5f6 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs | |||
@@ -59,8 +59,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) | |||
59 | fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { | 59 | fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { |
60 | let mut seen_methods = FxHashSet::default(); | 60 | let mut seen_methods = FxHashSet::default(); |
61 | ctx.analyzer.iterate_method_candidates(ctx.db, receiver, None, |_ty, func| { | 61 | ctx.analyzer.iterate_method_candidates(ctx.db, receiver, None, |_ty, func| { |
62 | let data = func.data(ctx.db); | 62 | if func.has_self_param(ctx.db) && seen_methods.insert(func.name(ctx.db)) { |
63 | if data.has_self_param() && seen_methods.insert(data.name().clone()) { | ||
64 | acc.add_function(ctx, func); | 63 | acc.add_function(ctx, func); |
65 | } | 64 | } |
66 | None::<()> | 65 | None::<()> |
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 5d974cf6d..802c7701a 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs | |||
@@ -53,8 +53,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
53 | ctx.analyzer.iterate_path_candidates(ctx.db, ty.clone(), None, |_ty, item| { | 53 | ctx.analyzer.iterate_path_candidates(ctx.db, ty.clone(), None, |_ty, item| { |
54 | match item { | 54 | match item { |
55 | hir::AssocItem::Function(func) => { | 55 | hir::AssocItem::Function(func) => { |
56 | let data = func.data(ctx.db); | 56 | if !func.has_self_param(ctx.db) { |
57 | if !data.has_self_param() { | ||
58 | acc.add_function(ctx, func); | 57 | acc.add_function(ctx, func); |
59 | } | 58 | } |
60 | } | 59 | } |
@@ -80,8 +79,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
80 | for item in t.items(ctx.db) { | 79 | for item in t.items(ctx.db) { |
81 | match item { | 80 | match item { |
82 | hir::AssocItem::Function(func) => { | 81 | hir::AssocItem::Function(func) => { |
83 | let data = func.data(ctx.db); | 82 | if !func.has_self_param(ctx.db) { |
84 | if !data.has_self_param() { | ||
85 | acc.add_function(ctx, func); | 83 | acc.add_function(ctx, func); |
86 | } | 84 | } |
87 | } | 85 | } |
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index bd464d193..896ad1517 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs | |||
@@ -199,14 +199,17 @@ impl Completions { | |||
199 | name: Option<String>, | 199 | name: Option<String>, |
200 | func: hir::Function, | 200 | func: hir::Function, |
201 | ) { | 201 | ) { |
202 | let data = func.data(ctx.db); | 202 | let func_name = func.name(ctx.db); |
203 | let name = name.unwrap_or_else(|| data.name().to_string()); | 203 | let has_self_param = func.has_self_param(ctx.db); |
204 | let params = func.params(ctx.db); | ||
205 | |||
206 | let name = name.unwrap_or_else(|| func_name.to_string()); | ||
204 | let ast_node = func.source(ctx.db).value; | 207 | let ast_node = func.source(ctx.db).value; |
205 | let detail = function_label(&ast_node); | 208 | let detail = function_label(&ast_node); |
206 | 209 | ||
207 | let mut builder = | 210 | let mut builder = |
208 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.clone()) | 211 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.clone()) |
209 | .kind(if data.has_self_param() { | 212 | .kind(if has_self_param { |
210 | CompletionItemKind::Method | 213 | CompletionItemKind::Method |
211 | } else { | 214 | } else { |
212 | CompletionItemKind::Function | 215 | CompletionItemKind::Function |
@@ -221,12 +224,11 @@ impl Completions { | |||
221 | && ctx.db.feature_flags.get("completion.insertion.add-call-parenthesis") | 224 | && ctx.db.feature_flags.get("completion.insertion.add-call-parenthesis") |
222 | { | 225 | { |
223 | tested_by!(inserts_parens_for_function_calls); | 226 | tested_by!(inserts_parens_for_function_calls); |
224 | let (snippet, label) = | 227 | let (snippet, label) = if params.is_empty() || has_self_param && params.len() == 1 { |
225 | if data.params().is_empty() || data.has_self_param() && data.params().len() == 1 { | 228 | (format!("{}()$0", func_name), format!("{}()", name)) |
226 | (format!("{}()$0", data.name()), format!("{}()", name)) | 229 | } else { |
227 | } else { | 230 | (format!("{}($0)", func_name), format!("{}(…)", name)) |
228 | (format!("{}($0)", data.name()), format!("{}(…)", name)) | 231 | }; |
229 | }; | ||
230 | builder = builder.lookup_by(name).label(label).insert_snippet(snippet); | 232 | builder = builder.lookup_by(name).label(label).insert_snippet(snippet); |
231 | } | 233 | } |
232 | 234 | ||