History

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)

Piotr Osiewicz committed 1 year ago

Commit 86283f41 parent 8e1003e1 file · +11 −11Browse files

Unified · Split

crates/project/src/lsp_store.rs+11−11
@@ -1921,20 +1921,20 @@ impl LocalLspStore { · 1920 unmodified lines
19211921 version: 0,
19221922 snapshot: initial_snapshot.clone(),
19231923 };
1924− let previous_snapshots = self
1925− .buffer_snapshots
1924+ self.buffer_snapshots
19261925 .entry(buffer_id)
19271926 .or_default()
1928− .insert(server.server_id(), vec![snapshot]);
1927+ .entry(server.server_id())
1928+ .or_insert_with(|| {
1929+ server.register_buffer(
1930+ uri.clone(),
1931+ adapter.language_id(&language.name()),
1932+ 0,
1933+ initial_snapshot.text(),
1934+ );
19291935
1930− if previous_snapshots.is_none() {
1931− server.register_buffer(
1932− uri.clone(),
1933− adapter.language_id(&language.name()),
1934− 0,
1935− initial_snapshot.text(),
1936− );
1937− }
1936+ vec![snapshot]
1937+ });
19381938 }
19391939 }
19401940 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t