From 8d4bdd6dc61ad0405232deac2f249dd641eee3ad Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Wed, 4 Sep 2024 19:31:32 +0200 Subject: [PATCH] lsp: Fill in version for SnippetEdit from drive (#17360) Related to #16680 Release Notes: - N/A --- crates/project/src/lsp_store.rs | 36 ++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/crates/project/src/lsp_store.rs b/crates/project/src/lsp_store.rs index d61806f54a..6cb740f96e 100644 --- a/crates/project/src/lsp_store.rs +++ b/crates/project/src/lsp_store.rs @@ -5715,11 +5715,10 @@ impl LspStore { } } if !snippet_edits.is_empty() { - if let Some(buffer_version) = op.text_document.version { - let buffer_id = buffer_to_edit.read(cx).remote_id(); - // Check if the edit that triggered that edit has been made by this participant. - let most_recent_edit = this - .buffer_snapshots + 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 @@ -5731,17 +5730,22 @@ impl LspStore { .ok() .and_then(|index| all_snapshots.get(index)) }) - .and_then(|lsp_snapshot| { - let version = lsp_snapshot.snapshot.version(); - version.iter().max_by_key(|timestamp| timestamp.value) - }); - if let Some(most_recent_edit) = most_recent_edit { - cx.emit(LspStoreEvent::SnippetEdit { - buffer_id, - edits: snippet_edits, - most_recent_edit, - }); - } + .map(|lsp_snapshot| lsp_snapshot.snapshot.version()) + } else { + Some(buffer_to_edit.read(cx).saved_version()) + }; + + let most_recent_edit = version.and_then(|version| { + version.iter().max_by_key(|timestamp| timestamp.value) + }); + // Check if the edit that triggered that edit has been made by this participant. + + if let Some(most_recent_edit) = most_recent_edit { + cx.emit(LspStoreEvent::SnippetEdit { + buffer_id, + edits: snippet_edits, + most_recent_edit, + }); } }