From c34fc5c6e504bb66bc8973a2c95fc358b613cfea Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Tue, 17 Sep 2024 11:47:17 +0200 Subject: [PATCH] lsp store: Refactor to use shared method to find buffer snapshot (#17929) 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 --- crates/project/src/lsp_store.rs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/crates/project/src/lsp_store.rs b/crates/project/src/lsp_store.rs index ee02492dd8cfda5b5095f1e2496d25e1e2f73eb7..fb3d52eb9ebc62226d06512e117695698841efe2 100644 --- a/crates/project/src/lsp_store.rs +++ b/crates/project/src/lsp_store.rs @@ -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| {