From 2529e9e1e165590f9be8daf0d467da93bd9e1c06 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Tue, 10 Dec 2024 12:33:13 +0200 Subject: [PATCH] Address the feedback from Veykril * Exclude documentation field from hashing * Do less cloning during initial completion list generation --- crates/rust-analyzer/src/lib.rs | 6 +++--- crates/rust-analyzer/src/lsp/to_proto.rs | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/rust-analyzer/src/lib.rs b/crates/rust-analyzer/src/lib.rs index 8c8ac8de81..15d60c873f 100644 --- a/crates/rust-analyzer/src/lib.rs +++ b/crates/rust-analyzer/src/lib.rs @@ -120,14 +120,14 @@ fn completion_item_hash(item: &CompletionItem, is_ref_completion: bool) -> [u8; } // NB: do not hash edits or source range, as those may change between the time the client sends the resolve request // and the time it receives it: some editors do allow changing the buffer between that, leading to ranges being different. + // + // Documentation hashing is skipped too, as it's a large blob to process, + // while not really making completion properties more unique as they are already. hasher.update(item.kind.tag()); hasher.update(&item.lookup); if let Some(detail) = &item.detail { hasher.update(detail); } - if let Some(documentation) = &item.documentation { - hasher.update(documentation.as_str()); - } hash_completion_relevance(&mut hasher, &item.relevance); if let Some((mutability, text_size)) = &item.ref_match { hasher.update(mutability.as_keyword_for_ref()); diff --git a/crates/rust-analyzer/src/lsp/to_proto.rs b/crates/rust-analyzer/src/lsp/to_proto.rs index f70968d694..a64e1a8621 100644 --- a/crates/rust-analyzer/src/lsp/to_proto.rs +++ b/crates/rust-analyzer/src/lsp/to_proto.rs @@ -275,7 +275,6 @@ fn completion_item( completion_trigger_character: Option, item: CompletionItem, ) { - let original_completion_item = item.clone(); let insert_replace_support = config.insert_replace_support().then_some(tdpp.position); let ref_match = item.ref_match(); @@ -297,7 +296,7 @@ fn completion_item( // non-trivial mapping here. let mut text_edit = None; let source_range = item.source_range; - for indel in item.text_edit { + for indel in &item.text_edit { if indel.delete.contains_range(source_range) { // Extract this indel as the main edit text_edit = Some(if indel.delete == source_range { @@ -349,7 +348,7 @@ fn completion_item( something_to_resolve |= item.documentation.is_some(); None } else { - item.documentation.map(documentation) + item.documentation.clone().map(documentation) }; let mut lsp_item = lsp_types::CompletionItem { @@ -373,10 +372,10 @@ fn completion_item( } else { lsp_item.label_details = Some(lsp_types::CompletionItemLabelDetails { detail: item.label_detail.as_ref().map(ToString::to_string), - description: item.detail, + description: item.detail.clone(), }); } - } else if let Some(label_detail) = item.label_detail { + } else if let Some(label_detail) = &item.label_detail { lsp_item.label.push_str(label_detail.as_str()); } @@ -385,6 +384,7 @@ fn completion_item( let imports = if config.completion(None).enable_imports_on_the_fly && !item.import_to_add.is_empty() { item.import_to_add + .clone() .into_iter() .map(|(import_path, import_name)| lsp_ext::CompletionImport { full_import_path: import_path, @@ -402,7 +402,7 @@ fn completion_item( version, trigger_character: completion_trigger_character, for_ref: true, - hash: completion_item_hash(&original_completion_item, true), + hash: completion_item_hash(&item, true), }; Some(to_value(ref_resolve_data).unwrap()) } else { @@ -414,7 +414,7 @@ fn completion_item( version, trigger_character: completion_trigger_character, for_ref: false, - hash: completion_item_hash(&original_completion_item, false), + hash: completion_item_hash(&item, false), }; (ref_resolve_data, Some(to_value(resolve_data).unwrap())) } else {