From 7210f3259b3f2bdd95334524ca600637e03568be Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Tue, 25 Feb 2025 11:46:19 +0100 Subject: [PATCH] lsp: Fix buffer snapshots sometimes going missing (cherry-pick #25548) (#25553) Cherry-picked lsp: Fix buffer snapshots sometimes going missing (#25548) A call to register_buffer_with_language_servers could nuke existing snapshots, even when the buffer was already registered with a server. Essentially, had we had the else branch in place, this would have been detected. Closes #ISSUE Release Notes: - Fixed Rust analyzer renames sometimes failing. (Preview only) Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> --- crates/project/src/lsp_store.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/project/src/lsp_store.rs b/crates/project/src/lsp_store.rs index c7509091e068c5e862191916f9207039d6619f85..e38799882a39656c4c6e28eaae040ba03ef938b9 100644 --- a/crates/project/src/lsp_store.rs +++ b/crates/project/src/lsp_store.rs @@ -1924,20 +1924,20 @@ impl LocalLspStore { version: 0, snapshot: initial_snapshot.clone(), }; - let previous_snapshots = self - .buffer_snapshots + self.buffer_snapshots .entry(buffer_id) .or_default() - .insert(server.server_id(), vec![snapshot]); + .entry(server.server_id()) + .or_insert_with(|| { + server.register_buffer( + uri.clone(), + adapter.language_id(&language.name()), + 0, + initial_snapshot.text(), + ); - if previous_snapshots.is_none() { - server.register_buffer( - uri.clone(), - adapter.language_id(&language.name()), - 0, - initial_snapshot.text(), - ); - } + vec![snapshot] + }); } } }