lsp store: Refactor to use shared method to find buffer snapshot (#17929)
Some checks are pending
CI / Check formatting and spelling (push) Waiting to run
CI / (macOS) Run Clippy and tests (push) Waiting to run
CI / (Linux) Run Clippy and tests (push) Waiting to run
CI / (Windows) Run Clippy and tests (push) Waiting to run
CI / Create a macOS bundle (push) Blocked by required conditions
CI / Create a Linux bundle (push) Blocked by required conditions
CI / Create arm64 Linux bundle (push) Blocked by required conditions
Deploy Docs / Deploy Docs (push) Waiting to run
Docs / Check formatting (push) Waiting to run

Came across this code while investigating something else and I think we
should use the same method. As far as I know, it does the same thing,
except that `buffer_snapshot_for_lsp_version` also cleans up the stored
snapshots.

Release Notes:

- N/A
This commit is contained in:
Thorsten Ball 2024-09-17 11:47:17 +02:00 committed by GitHub
parent 5f0925fb5d
commit c34fc5c6e5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6383,21 +6383,16 @@ impl LspStore {
let buffer_id = buffer_to_edit.read(cx).remote_id();
let version = if let Some(buffer_version) = op.text_document.version
{
this.buffer_snapshots
.get(&buffer_id)
.and_then(|server_to_snapshots| {
let all_snapshots = server_to_snapshots
.get(&language_server.server_id())?;
all_snapshots
.binary_search_by_key(&buffer_version, |snapshot| {
snapshot.version
})
.ok()
.and_then(|index| all_snapshots.get(index))
})
.map(|lsp_snapshot| lsp_snapshot.snapshot.version())
this.buffer_snapshot_for_lsp_version(
&buffer_to_edit,
language_server.server_id(),
Some(buffer_version),
cx,
)
.ok()
.map(|snapshot| snapshot.version)
} else {
Some(buffer_to_edit.read(cx).saved_version())
Some(buffer_to_edit.read(cx).saved_version().clone())
};
let most_recent_edit = version.and_then(|version| {