diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-09 14:46:10 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-09 14:46:10 +0000 |
commit | ab99eff7b68ea327c2d327e96e7f8e0119a08516 (patch) | |
tree | 1273129880e9c1bc8f6637afec380301dc41a1d2 /crates | |
parent | 21913d0fdb848445a908021dbcd4c3accf2ca0a5 (diff) | |
parent | abc0ed36bdf4975dc9c5fb2ddd3f960ad2db5494 (diff) |
Merge #7940
7940: Cleanup r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ide_completion/src/item.rs | 15 | ||||
-rw-r--r-- | crates/ide_completion/src/render.rs | 8 | ||||
-rw-r--r-- | crates/rust-analyzer/src/to_proto.rs | 52 |
3 files changed, 37 insertions, 38 deletions
diff --git a/crates/ide_completion/src/item.rs b/crates/ide_completion/src/item.rs index 9b039e3e5..b16f0775a 100644 --- a/crates/ide_completion/src/item.rs +++ b/crates/ide_completion/src/item.rs | |||
@@ -208,7 +208,7 @@ impl CompletionItem { | |||
208 | lookup: None, | 208 | lookup: None, |
209 | kind: None, | 209 | kind: None, |
210 | text_edit: None, | 210 | text_edit: None, |
211 | deprecated: None, | 211 | deprecated: false, |
212 | trigger_call_info: None, | 212 | trigger_call_info: None, |
213 | score: None, | 213 | score: None, |
214 | ref_match: None, | 214 | ref_match: None, |
@@ -308,7 +308,7 @@ pub(crate) struct Builder { | |||
308 | lookup: Option<String>, | 308 | lookup: Option<String>, |
309 | kind: Option<CompletionItemKind>, | 309 | kind: Option<CompletionItemKind>, |
310 | text_edit: Option<TextEdit>, | 310 | text_edit: Option<TextEdit>, |
311 | deprecated: Option<bool>, | 311 | deprecated: bool, |
312 | trigger_call_info: Option<bool>, | 312 | trigger_call_info: Option<bool>, |
313 | score: Option<CompletionScore>, | 313 | score: Option<CompletionScore>, |
314 | ref_match: Option<(Mutability, CompletionScore)>, | 314 | ref_match: Option<(Mutability, CompletionScore)>, |
@@ -355,7 +355,7 @@ impl Builder { | |||
355 | lookup, | 355 | lookup, |
356 | kind: self.kind, | 356 | kind: self.kind, |
357 | completion_kind: self.completion_kind, | 357 | completion_kind: self.completion_kind, |
358 | deprecated: self.deprecated.unwrap_or(false), | 358 | deprecated: self.deprecated, |
359 | trigger_call_info: self.trigger_call_info.unwrap_or(false), | 359 | trigger_call_info: self.trigger_call_info.unwrap_or(false), |
360 | score: self.score, | 360 | score: self.score, |
361 | ref_match: self.ref_match, | 361 | ref_match: self.ref_match, |
@@ -415,7 +415,7 @@ impl Builder { | |||
415 | self | 415 | self |
416 | } | 416 | } |
417 | pub(crate) fn set_deprecated(mut self, deprecated: bool) -> Builder { | 417 | pub(crate) fn set_deprecated(mut self, deprecated: bool) -> Builder { |
418 | self.deprecated = Some(deprecated); | 418 | self.deprecated = deprecated; |
419 | self | 419 | self |
420 | } | 420 | } |
421 | pub(crate) fn set_score(mut self, score: CompletionScore) -> Builder { | 421 | pub(crate) fn set_score(mut self, score: CompletionScore) -> Builder { |
@@ -430,11 +430,8 @@ impl Builder { | |||
430 | self.import_to_add = import_to_add; | 430 | self.import_to_add = import_to_add; |
431 | self | 431 | self |
432 | } | 432 | } |
433 | pub(crate) fn set_ref_match( | 433 | pub(crate) fn ref_match(mut self, ref_match: (Mutability, CompletionScore)) -> Builder { |
434 | mut self, | 434 | self.ref_match = Some(ref_match); |
435 | ref_match: Option<(Mutability, CompletionScore)>, | ||
436 | ) -> Builder { | ||
437 | self.ref_match = ref_match; | ||
438 | self | 435 | self |
439 | } | 436 | } |
440 | } | 437 | } |
diff --git a/crates/ide_completion/src/render.rs b/crates/ide_completion/src/render.rs index fae5685e2..0a6ac8804 100644 --- a/crates/ide_completion/src/render.rs +++ b/crates/ide_completion/src/render.rs | |||
@@ -246,7 +246,6 @@ impl<'a> Render<'a> { | |||
246 | } | 246 | } |
247 | }; | 247 | }; |
248 | 248 | ||
249 | let mut ref_match = None; | ||
250 | if let ScopeDef::Local(local) = resolution { | 249 | if let ScopeDef::Local(local) = resolution { |
251 | if let Some((active_name, active_type)) = self.ctx.active_name_and_type() { | 250 | if let Some((active_name, active_type)) = self.ctx.active_name_and_type() { |
252 | let ty = local.ty(self.ctx.db()); | 251 | let ty = local.ty(self.ctx.db()); |
@@ -255,7 +254,11 @@ impl<'a> Render<'a> { | |||
255 | { | 254 | { |
256 | item = item.set_score(score); | 255 | item = item.set_score(score); |
257 | } | 256 | } |
258 | ref_match = refed_type_matches(&active_type, &active_name, &ty, &local_name); | 257 | if let Some(ref_match) = |
258 | refed_type_matches(&active_type, &active_name, &ty, &local_name) | ||
259 | { | ||
260 | item = item.ref_match(ref_match); | ||
261 | } | ||
259 | } | 262 | } |
260 | } | 263 | } |
261 | 264 | ||
@@ -285,7 +288,6 @@ impl<'a> Render<'a> { | |||
285 | Some( | 288 | Some( |
286 | item.kind(kind) | 289 | item.kind(kind) |
287 | .add_import(import_to_add) | 290 | .add_import(import_to_add) |
288 | .set_ref_match(ref_match) | ||
289 | .set_documentation(self.docs(resolution)) | 291 | .set_documentation(self.docs(resolution)) |
290 | .set_deprecated(self.is_deprecated(resolution)) | 292 | .set_deprecated(self.is_deprecated(resolution)) |
291 | .build(), | 293 | .build(), |
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index 4235eb6dd..261d9fb18 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs | |||
@@ -173,20 +173,20 @@ pub(crate) fn snippet_text_edit_vec( | |||
173 | 173 | ||
174 | pub(crate) fn completion_item( | 174 | pub(crate) fn completion_item( |
175 | line_index: &LineIndex, | 175 | line_index: &LineIndex, |
176 | completion_item: CompletionItem, | 176 | item: CompletionItem, |
177 | ) -> Vec<lsp_types::CompletionItem> { | 177 | ) -> Vec<lsp_types::CompletionItem> { |
178 | fn set_score(res: &mut lsp_types::CompletionItem, label: &str) { | 178 | fn set_score(lsp_item: &mut lsp_types::CompletionItem, label: &str) { |
179 | res.preselect = Some(true); | 179 | lsp_item.preselect = Some(true); |
180 | // HACK: sort preselect items first | 180 | // HACK: sort preselect items first |
181 | res.sort_text = Some(format!(" {}", label)); | 181 | lsp_item.sort_text = Some(format!(" {}", label)); |
182 | } | 182 | } |
183 | 183 | ||
184 | let mut additional_text_edits = Vec::new(); | 184 | let mut additional_text_edits = Vec::new(); |
185 | let mut text_edit = None; | 185 | let mut text_edit = None; |
186 | // LSP does not allow arbitrary edits in completion, so we have to do a | 186 | // LSP does not allow arbitrary edits in completion, so we have to do a |
187 | // non-trivial mapping here. | 187 | // non-trivial mapping here. |
188 | let source_range = completion_item.source_range(); | 188 | let source_range = item.source_range(); |
189 | for indel in completion_item.text_edit().iter() { | 189 | for indel in item.text_edit().iter() { |
190 | if indel.delete.contains_range(source_range) { | 190 | if indel.delete.contains_range(source_range) { |
191 | text_edit = Some(if indel.delete == source_range { | 191 | text_edit = Some(if indel.delete == source_range { |
192 | self::text_edit(line_index, indel.clone()) | 192 | self::text_edit(line_index, indel.clone()) |
@@ -207,46 +207,46 @@ pub(crate) fn completion_item( | |||
207 | } | 207 | } |
208 | let text_edit = text_edit.unwrap(); | 208 | let text_edit = text_edit.unwrap(); |
209 | 209 | ||
210 | let mut res = lsp_types::CompletionItem { | 210 | let mut lsp_item = lsp_types::CompletionItem { |
211 | label: completion_item.label().to_string(), | 211 | label: item.label().to_string(), |
212 | detail: completion_item.detail().map(|it| it.to_string()), | 212 | detail: item.detail().map(|it| it.to_string()), |
213 | filter_text: Some(completion_item.lookup().to_string()), | 213 | filter_text: Some(item.lookup().to_string()), |
214 | kind: completion_item.kind().map(completion_item_kind), | 214 | kind: item.kind().map(completion_item_kind), |
215 | text_edit: Some(text_edit.into()), | 215 | text_edit: Some(text_edit.into()), |
216 | additional_text_edits: Some(additional_text_edits), | 216 | additional_text_edits: Some(additional_text_edits), |
217 | documentation: completion_item.documentation().map(documentation), | 217 | documentation: item.documentation().map(documentation), |
218 | deprecated: Some(completion_item.deprecated()), | 218 | deprecated: Some(item.deprecated()), |
219 | ..Default::default() | 219 | ..Default::default() |
220 | }; | 220 | }; |
221 | 221 | ||
222 | if completion_item.score().is_some() { | 222 | if item.score().is_some() { |
223 | set_score(&mut res, completion_item.label()); | 223 | set_score(&mut lsp_item, item.label()); |
224 | } | 224 | } |
225 | 225 | ||
226 | if completion_item.deprecated() { | 226 | if item.deprecated() { |
227 | res.tags = Some(vec![lsp_types::CompletionItemTag::Deprecated]) | 227 | lsp_item.tags = Some(vec![lsp_types::CompletionItemTag::Deprecated]) |
228 | } | 228 | } |
229 | 229 | ||
230 | if completion_item.trigger_call_info() { | 230 | if item.trigger_call_info() { |
231 | res.command = Some(command::trigger_parameter_hints()); | 231 | lsp_item.command = Some(command::trigger_parameter_hints()); |
232 | } | 232 | } |
233 | 233 | ||
234 | let mut all_results = match completion_item.ref_match() { | 234 | let mut res = match item.ref_match() { |
235 | Some(ref_match) => { | 235 | Some(ref_match) => { |
236 | let mut refed = res.clone(); | 236 | let mut refed = lsp_item.clone(); |
237 | let (mutability, _score) = ref_match; | 237 | let (mutability, _score) = ref_match; |
238 | let label = format!("&{}{}", mutability.as_keyword_for_ref(), refed.label); | 238 | let label = format!("&{}{}", mutability.as_keyword_for_ref(), refed.label); |
239 | set_score(&mut refed, &label); | 239 | set_score(&mut refed, &label); |
240 | refed.label = label; | 240 | refed.label = label; |
241 | vec![res, refed] | 241 | vec![lsp_item, refed] |
242 | } | 242 | } |
243 | None => vec![res], | 243 | None => vec![lsp_item], |
244 | }; | 244 | }; |
245 | 245 | ||
246 | for mut r in all_results.iter_mut() { | 246 | for mut r in res.iter_mut() { |
247 | r.insert_text_format = Some(insert_text_format(completion_item.insert_text_format())); | 247 | r.insert_text_format = Some(insert_text_format(item.insert_text_format())); |
248 | } | 248 | } |
249 | all_results | 249 | res |
250 | } | 250 | } |
251 | 251 | ||
252 | pub(crate) fn signature_help( | 252 | pub(crate) fn signature_help( |