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)
This commit is contained in:
Piotr Osiewicz 2025-02-25 10:39:09 +01:00 committed by GitHub
parent 8e1003ef59
commit 86283f4e3d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1921,20 +1921,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]
});
}
}
}