Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Fix LSP rename in Go (#25073)

Antonio Scandurra00bb9a4e9213
diff --git a/crates/project/src/lsp_store.rs b/crates/project/src/lsp_store.rs
index 17a1306df60..28e88c504a3 100644
--- a/crates/project/src/lsp_store.rs
+++ b/crates/project/src/lsp_store.rs
@@ -1986,13 +1986,21 @@ impl LocalLspStore {
if let Some(version) = version {
let buffer_id = buffer.read(cx).remote_id();
- let snapshots = self
+ let snapshots = if let Some(snapshots) = self
.buffer_snapshots
.get_mut(&buffer_id)
.and_then(|m| m.get_mut(&server_id))
- .ok_or_else(|| {
- anyhow!("no snapshots found for buffer {buffer_id} and server {server_id}")
- })?;
+ {
+ snapshots
+ } else if version == 0 {
+ // Some language servers report version 0 even if the buffer hasn't been opened yet.
+ // We detect this case and treat it as if the version was `None`.
+ return Ok(buffer.read(cx).text_snapshot());
+ } else {
+ return Err(anyhow!(
+ "no snapshots found for buffer {buffer_id} and server {server_id}"
+ ));
+ };
let found_snapshot = snapshots
.binary_search_by_key(&version, |e| e.version)