Don't allow lookup by self for unprefixed self access completions

This commit is contained in:
Lukas Wirth 2021-06-11 18:26:52 +02:00
parent c6133fe51c
commit 4e588dfd88
2 changed files with 21 additions and 18 deletions

View File

@ -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()
}

View File

@ -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<ImportEdit>) -> CompletionItem {
fn render(self, import_to_add: Option<ImportEdit>) -> 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 {