From 89c2aaed8ce225a38d08806ef7d74c079bf2d636 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Tue, 10 Dec 2024 00:04:53 +0200 Subject: [PATCH] Avoid hashing completion-related ranges as those may change during /resolve query --- crates/rust-analyzer/src/lib.rs | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/crates/rust-analyzer/src/lib.rs b/crates/rust-analyzer/src/lib.rs index 7cf88e60db..aed8479589 100644 --- a/crates/rust-analyzer/src/lib.rs +++ b/crates/rust-analyzer/src/lib.rs @@ -47,7 +47,7 @@ use self::lsp::ext as lsp_ext; #[cfg(test)] mod integrated_benchmarks; -use ide::{CompletionItem, CompletionRelevance, TextEdit, TextRange}; +use ide::{CompletionItem, CompletionRelevance}; use serde::de::DeserializeOwned; use tenthash::TentHasher; @@ -65,18 +65,6 @@ pub fn from_json( } fn completion_item_hash(item: &CompletionItem, is_ref_completion: bool) -> [u8; 20] { - fn hash_text_range(hasher: &mut TentHasher, text_range: &TextRange) { - hasher.update(u32::from(text_range.start()).to_le_bytes()); - hasher.update(u32::from(text_range.end()).to_le_bytes()); - } - - fn hash_text_edit(hasher: &mut TentHasher, edit: &TextEdit) { - for indel in edit.iter() { - hasher.update(&indel.insert); - hash_text_range(hasher, &indel.delete); - } - } - fn hash_completion_relevance(hasher: &mut TentHasher, relevance: &CompletionRelevance) { use ide_completion::{ CompletionRelevancePostfixMatch, CompletionRelevanceReturnType, @@ -130,8 +118,8 @@ fn completion_item_hash(item: &CompletionItem, is_ref_completion: bool) -> [u8; if let Some(label_detail) = &item.label_detail { hasher.update(label_detail); } - hash_text_range(&mut hasher, &item.source_range); - hash_text_edit(&mut hasher, &item.text_edit); + // 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. hasher.update(item.kind.tag()); hasher.update(&item.lookup); if let Some(detail) = &item.detail {