From 2cc278c6ffa900d9fba8e19c5a1fc6996fbe6639 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 9 Mar 2021 17:39:22 +0300 Subject: Fix bad names `res` should only be used for the result variable --- crates/rust-analyzer/src/to_proto.rs | 52 ++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'crates') 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( pub(crate) fn completion_item( line_index: &LineIndex, - completion_item: CompletionItem, + item: CompletionItem, ) -> Vec { - fn set_score(res: &mut lsp_types::CompletionItem, label: &str) { - res.preselect = Some(true); + fn set_score(lsp_item: &mut lsp_types::CompletionItem, label: &str) { + lsp_item.preselect = Some(true); // HACK: sort preselect items first - res.sort_text = Some(format!(" {}", label)); + lsp_item.sort_text = Some(format!(" {}", label)); } let mut additional_text_edits = Vec::new(); let mut text_edit = None; // LSP does not allow arbitrary edits in completion, so we have to do a // non-trivial mapping here. - let source_range = completion_item.source_range(); - for indel in completion_item.text_edit().iter() { + let source_range = item.source_range(); + for indel in item.text_edit().iter() { if indel.delete.contains_range(source_range) { text_edit = Some(if indel.delete == source_range { self::text_edit(line_index, indel.clone()) @@ -207,46 +207,46 @@ pub(crate) fn completion_item( } let text_edit = text_edit.unwrap(); - let mut res = lsp_types::CompletionItem { - label: completion_item.label().to_string(), - detail: completion_item.detail().map(|it| it.to_string()), - filter_text: Some(completion_item.lookup().to_string()), - kind: completion_item.kind().map(completion_item_kind), + let mut lsp_item = lsp_types::CompletionItem { + label: item.label().to_string(), + detail: item.detail().map(|it| it.to_string()), + filter_text: Some(item.lookup().to_string()), + kind: item.kind().map(completion_item_kind), text_edit: Some(text_edit.into()), additional_text_edits: Some(additional_text_edits), - documentation: completion_item.documentation().map(documentation), - deprecated: Some(completion_item.deprecated()), + documentation: item.documentation().map(documentation), + deprecated: Some(item.deprecated()), ..Default::default() }; - if completion_item.score().is_some() { - set_score(&mut res, completion_item.label()); + if item.score().is_some() { + set_score(&mut lsp_item, item.label()); } - if completion_item.deprecated() { - res.tags = Some(vec![lsp_types::CompletionItemTag::Deprecated]) + if item.deprecated() { + lsp_item.tags = Some(vec![lsp_types::CompletionItemTag::Deprecated]) } - if completion_item.trigger_call_info() { - res.command = Some(command::trigger_parameter_hints()); + if item.trigger_call_info() { + lsp_item.command = Some(command::trigger_parameter_hints()); } - let mut all_results = match completion_item.ref_match() { + let mut res = match item.ref_match() { Some(ref_match) => { - let mut refed = res.clone(); + let mut refed = lsp_item.clone(); let (mutability, _score) = ref_match; let label = format!("&{}{}", mutability.as_keyword_for_ref(), refed.label); set_score(&mut refed, &label); refed.label = label; - vec![res, refed] + vec![lsp_item, refed] } - None => vec![res], + None => vec![lsp_item], }; - for mut r in all_results.iter_mut() { - r.insert_text_format = Some(insert_text_format(completion_item.insert_text_format())); + for mut r in res.iter_mut() { + r.insert_text_format = Some(insert_text_format(item.insert_text_format())); } - all_results + res } pub(crate) fn signature_help( -- cgit v1.2.3 From 444d67ae1802d2832b3bcdc0ff593b014477b37b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 9 Mar 2021 17:42:05 +0300 Subject: Cleanup --- crates/ide_completion/src/item.rs | 7 ++----- crates/ide_completion/src/render.rs | 8 +++++--- 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'crates') diff --git a/crates/ide_completion/src/item.rs b/crates/ide_completion/src/item.rs index 9b039e3e5..b6bc11da2 100644 --- a/crates/ide_completion/src/item.rs +++ b/crates/ide_completion/src/item.rs @@ -430,11 +430,8 @@ impl Builder { self.import_to_add = import_to_add; self } - pub(crate) fn set_ref_match( - mut self, - ref_match: Option<(Mutability, CompletionScore)>, - ) -> Builder { - self.ref_match = ref_match; + pub(crate) fn ref_match(mut self, ref_match: (Mutability, CompletionScore)) -> Builder { + self.ref_match = Some(ref_match); self } } 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> { } }; - let mut ref_match = None; if let ScopeDef::Local(local) = resolution { if let Some((active_name, active_type)) = self.ctx.active_name_and_type() { let ty = local.ty(self.ctx.db()); @@ -255,7 +254,11 @@ impl<'a> Render<'a> { { item = item.set_score(score); } - ref_match = refed_type_matches(&active_type, &active_name, &ty, &local_name); + if let Some(ref_match) = + refed_type_matches(&active_type, &active_name, &ty, &local_name) + { + item = item.ref_match(ref_match); + } } } @@ -285,7 +288,6 @@ impl<'a> Render<'a> { Some( item.kind(kind) .add_import(import_to_add) - .set_ref_match(ref_match) .set_documentation(self.docs(resolution)) .set_deprecated(self.is_deprecated(resolution)) .build(), -- cgit v1.2.3 From abc0ed36bdf4975dc9c5fb2ddd3f960ad2db5494 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 9 Mar 2021 17:44:27 +0300 Subject: Cleanup --- crates/ide_completion/src/item.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'crates') diff --git a/crates/ide_completion/src/item.rs b/crates/ide_completion/src/item.rs index b6bc11da2..b16f0775a 100644 --- a/crates/ide_completion/src/item.rs +++ b/crates/ide_completion/src/item.rs @@ -208,7 +208,7 @@ impl CompletionItem { lookup: None, kind: None, text_edit: None, - deprecated: None, + deprecated: false, trigger_call_info: None, score: None, ref_match: None, @@ -308,7 +308,7 @@ pub(crate) struct Builder { lookup: Option, kind: Option, text_edit: Option, - deprecated: Option, + deprecated: bool, trigger_call_info: Option, score: Option, ref_match: Option<(Mutability, CompletionScore)>, @@ -355,7 +355,7 @@ impl Builder { lookup, kind: self.kind, completion_kind: self.completion_kind, - deprecated: self.deprecated.unwrap_or(false), + deprecated: self.deprecated, trigger_call_info: self.trigger_call_info.unwrap_or(false), score: self.score, ref_match: self.ref_match, @@ -415,7 +415,7 @@ impl Builder { self } pub(crate) fn set_deprecated(mut self, deprecated: bool) -> Builder { - self.deprecated = Some(deprecated); + self.deprecated = deprecated; self } pub(crate) fn set_score(mut self, score: CompletionScore) -> Builder { -- cgit v1.2.3