Skip to content

Commit

Permalink
Fix LSP rename in Go (cherry-pick #25073) (#25075)
Browse files Browse the repository at this point in the history
Cherry-picked Fix LSP rename in Go (#25073)

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`.

Closes #23706

Release Notes:

- Fixed a bug that prevented renames for some languages.

Co-authored-by: Antonio Scandurra <me@as-cii.com>
  • Loading branch information
gcp-cherry-pick-bot[bot] and as-cii authored Feb 18, 2025
1 parent 06efcd1 commit 4522352
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions crates/project/src/lsp_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1896,13 +1896,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)
Expand Down

0 comments on commit 4522352

Please sign in to comment.