diff options
author | Lukas Wirth <[email protected]> | 2021-06-11 17:26:52 +0100 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2021-06-11 17:26:52 +0100 |
commit | 4e588dfd88352e82d785c2b9d369c5c98c028c12 (patch) | |
tree | 2de82178bf37be7b4ae00c03fa20354b3419a15e /crates/ide_completion | |
parent | c6133fe51c2cf31d776f16d520de4f78c709181c (diff) |
Don't allow lookup by self for unprefixed self access completions
Diffstat (limited to 'crates/ide_completion')
-rw-r--r-- | crates/ide_completion/src/render.rs | 13 | ||||
-rw-r--r-- | 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_( | |||
132 | ctx.source_range(), | 132 | ctx.source_range(), |
133 | receiver.map_or_else(|| name.clone(), |receiver| format!("{}.{}", receiver, name)), | 133 | receiver.map_or_else(|| name.clone(), |receiver| format!("{}.{}", receiver, name)), |
134 | ); | 134 | ); |
135 | item.kind(SymbolKind::Field) | ||
136 | .detail(ty.display(ctx.db()).to_string()) | ||
137 | .set_documentation(field.docs(ctx.db())) | ||
138 | .set_deprecated(is_deprecated); | ||
139 | 135 | ||
140 | item.set_relevance(CompletionRelevance { | 136 | item.set_relevance(CompletionRelevance { |
141 | type_match: compute_type_match(ctx.completion, ty), | 137 | type_match: compute_type_match(ctx.completion, ty), |
142 | exact_name_match: compute_exact_name_match(ctx.completion, &name), | 138 | exact_name_match: compute_exact_name_match(ctx.completion, &name), |
143 | ..CompletionRelevance::default() | 139 | ..CompletionRelevance::default() |
144 | }); | 140 | }); |
141 | item.kind(SymbolKind::Field) | ||
142 | .detail(ty.display(ctx.db()).to_string()) | ||
143 | .set_documentation(field.docs(ctx.db())) | ||
144 | .set_deprecated(is_deprecated) | ||
145 | .lookup_by(name); | ||
145 | 146 | ||
146 | if let Some(_ref_match) = compute_ref_match(ctx.completion, ty) { | 147 | if let Some(_ref_match) = compute_ref_match(ctx.completion, ty) { |
147 | // FIXME | 148 | // FIXME |
@@ -164,7 +165,9 @@ fn render_tuple_field_( | |||
164 | receiver.map_or_else(|| field.to_string(), |receiver| format!("{}.{}", receiver, field)), | 165 | receiver.map_or_else(|| field.to_string(), |receiver| format!("{}.{}", receiver, field)), |
165 | ); | 166 | ); |
166 | 167 | ||
167 | item.kind(SymbolKind::Field).detail(ty.display(ctx.db()).to_string()); | 168 | item.kind(SymbolKind::Field) |
169 | .detail(ty.display(ctx.db()).to_string()) | ||
170 | .lookup_by(field.to_string()); | ||
168 | 171 | ||
169 | item.build() | 172 | item.build() |
170 | } | 173 | } |
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> { | |||
58 | Some(FunctionRender { ctx, name, receiver, func: fn_, ast_node, is_method }) | 58 | Some(FunctionRender { ctx, name, receiver, func: fn_, ast_node, is_method }) |
59 | } | 59 | } |
60 | 60 | ||
61 | fn render(mut self, import_to_add: Option<ImportEdit>) -> CompletionItem { | 61 | fn render(self, import_to_add: Option<ImportEdit>) -> CompletionItem { |
62 | let params = self.params(); | 62 | let params = self.params(); |
63 | if let Some(receiver) = &self.receiver { | 63 | let call = if let Some(receiver) = &self.receiver { |
64 | self.name = format!("{}.{}", receiver, &self.name) | 64 | format!("{}.{}", receiver, &self.name) |
65 | } | 65 | } else { |
66 | let mut item = CompletionItem::new( | 66 | self.name.clone() |
67 | CompletionKind::Reference, | 67 | }; |
68 | self.ctx.source_range(), | 68 | let mut item = |
69 | self.name.clone(), | 69 | CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), call.clone()); |
70 | ); | ||
71 | item.kind(self.kind()) | 70 | item.kind(self.kind()) |
72 | .set_documentation(self.ctx.docs(self.func)) | 71 | .set_documentation(self.ctx.docs(self.func)) |
73 | .set_deprecated( | 72 | .set_deprecated( |
74 | self.ctx.is_deprecated(self.func) || self.ctx.is_deprecated_assoc_item(self.func), | 73 | self.ctx.is_deprecated(self.func) || self.ctx.is_deprecated_assoc_item(self.func), |
75 | ) | 74 | ) |
76 | .detail(self.detail()) | 75 | .detail(self.detail()) |
77 | .add_call_parens(self.ctx.completion, self.name.clone(), params) | 76 | .add_call_parens(self.ctx.completion, call.clone(), params) |
78 | .add_import(import_to_add); | 77 | .add_import(import_to_add) |
78 | .lookup_by(self.name); | ||
79 | 79 | ||
80 | let ret_type = self.func.ret_type(self.ctx.db()); | 80 | let ret_type = self.func.ret_type(self.ctx.db()); |
81 | item.set_relevance(CompletionRelevance { | 81 | item.set_relevance(CompletionRelevance { |
82 | type_match: compute_type_match(self.ctx.completion, &ret_type), | 82 | type_match: compute_type_match(self.ctx.completion, &ret_type), |
83 | exact_name_match: compute_exact_name_match(self.ctx.completion, &self.name), | 83 | exact_name_match: compute_exact_name_match(self.ctx.completion, &call), |
84 | ..CompletionRelevance::default() | 84 | ..CompletionRelevance::default() |
85 | }); | 85 | }); |
86 | 86 | ||
@@ -263,7 +263,7 @@ fn bar(s: &S) { | |||
263 | ); | 263 | ); |
264 | 264 | ||
265 | check_edit( | 265 | check_edit( |
266 | "self.foo", | 266 | "foo", |
267 | r#" | 267 | r#" |
268 | struct S {} | 268 | struct S {} |
269 | impl S { | 269 | impl S { |