From 4e588dfd88352e82d785c2b9d369c5c98c028c12 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 11 Jun 2021 18:26:52 +0200 Subject: Don't allow lookup by self for unprefixed self access completions --- crates/ide_completion/src/render.rs | 13 ++++++++----- crates/ide_completion/src/render/function.rs | 26 +++++++++++++------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/crates/ide_completion/src/render.rs b/crates/ide_completion/src/render.rs index 902df46ca..2eabc2a67 100644 --- a/crates/ide_completion/src/render.rs +++ b/crates/ide_completion/src/render.rs @@ -132,16 +132,17 @@ fn render_field_( ctx.source_range(), receiver.map_or_else(|| name.clone(), |receiver| format!("{}.{}", receiver, name)), ); - item.kind(SymbolKind::Field) - .detail(ty.display(ctx.db()).to_string()) - .set_documentation(field.docs(ctx.db())) - .set_deprecated(is_deprecated); item.set_relevance(CompletionRelevance { type_match: compute_type_match(ctx.completion, ty), exact_name_match: compute_exact_name_match(ctx.completion, &name), ..CompletionRelevance::default() }); + item.kind(SymbolKind::Field) + .detail(ty.display(ctx.db()).to_string()) + .set_documentation(field.docs(ctx.db())) + .set_deprecated(is_deprecated) + .lookup_by(name); if let Some(_ref_match) = compute_ref_match(ctx.completion, ty) { // FIXME @@ -164,7 +165,9 @@ fn render_tuple_field_( receiver.map_or_else(|| field.to_string(), |receiver| format!("{}.{}", receiver, field)), ); - item.kind(SymbolKind::Field).detail(ty.display(ctx.db()).to_string()); + item.kind(SymbolKind::Field) + .detail(ty.display(ctx.db()).to_string()) + .lookup_by(field.to_string()); item.build() } diff --git a/crates/ide_completion/src/render/function.rs b/crates/ide_completion/src/render/function.rs index 1abeed96d..1357b9f4a 100644 --- a/crates/ide_completion/src/render/function.rs +++ b/crates/ide_completion/src/render/function.rs @@ -58,29 +58,29 @@ impl<'a> FunctionRender<'a> { Some(FunctionRender { ctx, name, receiver, func: fn_, ast_node, is_method }) } - fn render(mut self, import_to_add: Option) -> CompletionItem { + fn render(self, import_to_add: Option) -> CompletionItem { let params = self.params(); - if let Some(receiver) = &self.receiver { - self.name = format!("{}.{}", receiver, &self.name) - } - let mut item = CompletionItem::new( - CompletionKind::Reference, - self.ctx.source_range(), - self.name.clone(), - ); + let call = if let Some(receiver) = &self.receiver { + format!("{}.{}", receiver, &self.name) + } else { + self.name.clone() + }; + let mut item = + CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), call.clone()); item.kind(self.kind()) .set_documentation(self.ctx.docs(self.func)) .set_deprecated( self.ctx.is_deprecated(self.func) || self.ctx.is_deprecated_assoc_item(self.func), ) .detail(self.detail()) - .add_call_parens(self.ctx.completion, self.name.clone(), params) - .add_import(import_to_add); + .add_call_parens(self.ctx.completion, call.clone(), params) + .add_import(import_to_add) + .lookup_by(self.name); let ret_type = self.func.ret_type(self.ctx.db()); item.set_relevance(CompletionRelevance { type_match: compute_type_match(self.ctx.completion, &ret_type), - exact_name_match: compute_exact_name_match(self.ctx.completion, &self.name), + exact_name_match: compute_exact_name_match(self.ctx.completion, &call), ..CompletionRelevance::default() }); @@ -263,7 +263,7 @@ fn bar(s: &S) { ); check_edit( - "self.foo", + "foo", r#" struct S {} impl S { -- cgit v1.2.3