Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
lsp: Open updated imports in multibuffer after file rename (#45110)
Gaauwe Romboutsc186877ff740
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 4072b1db7a1..a66d92ceb8b 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -2063,46 +2063,34 @@ impl Editor {})});});- let edited_buffers_already_open = {- let other_editors: Vec<Entity<Editor>> = workspace- .read(cx)- .panes()- .iter()- .flat_map(|pane| pane.read(cx).items_of_type::<Editor>())- .filter(|editor| editor.entity_id() != cx.entity_id())- .collect();-- transaction.0.keys().all(|buffer| {- other_editors.iter().any(|editor| {- let multi_buffer = editor.read(cx).buffer();- multi_buffer.read(cx).is_singleton()- && multi_buffer.read(cx).as_singleton().map_or(- false,- |singleton| {- singleton.entity_id() == buffer.entity_id()- },- )- })- })- };- if !edited_buffers_already_open {- let workspace = workspace.downgrade();- let transaction = transaction.clone();- cx.defer_in(window, move |_, window, cx| {- cx.spawn_in(window, async move |editor, cx| {- Self::open_project_transaction(- &editor,- workspace,- transaction,- "Rename".to_string(),- cx,- )- .await- .ok()- })- .detach();- });- }++ Self::open_transaction_for_hidden_buffers(+ workspace,+ transaction.clone(),+ "Rename".to_string(),+ window,+ cx,+ );+ }+ }++ project::Event::WorkspaceEditApplied(transaction) => {+ let Some(workspace) = editor.workspace() else {+ return;+ };+ let Some(active_editor) = workspace.read(cx).active_item_as::<Self>(cx)+ else {+ return;+ };++ if active_editor.entity_id() == cx.entity_id() {+ Self::open_transaction_for_hidden_buffers(+ workspace,+ transaction.clone(),+ "LSP Edit".to_string(),+ window,+ cx,+ );}}@@ -6672,6 +6660,52 @@ impl Editor {}}+ fn open_transaction_for_hidden_buffers(+ workspace: Entity<Workspace>,+ transaction: ProjectTransaction,+ title: String,+ window: &mut Window,+ cx: &mut Context<Self>,+ ) {+ if transaction.0.is_empty() {+ return;+ }++ let edited_buffers_already_open = {+ let other_editors: Vec<Entity<Editor>> = workspace+ .read(cx)+ .panes()+ .iter()+ .flat_map(|pane| pane.read(cx).items_of_type::<Editor>())+ .filter(|editor| editor.entity_id() != cx.entity_id())+ .collect();++ transaction.0.keys().all(|buffer| {+ other_editors.iter().any(|editor| {+ let multi_buffer = editor.read(cx).buffer();+ multi_buffer.read(cx).is_singleton()+ && multi_buffer+ .read(cx)+ .as_singleton()+ .map_or(false, |singleton| {+ singleton.entity_id() == buffer.entity_id()+ })+ })+ })+ };+ if !edited_buffers_already_open {+ let workspace = workspace.downgrade();+ cx.defer_in(window, move |_, window, cx| {+ cx.spawn_in(window, async move |editor, cx| {+ Self::open_project_transaction(&editor, workspace, transaction, title, cx)+ .await+ .ok()+ })+ .detach();+ });+ }+ }+pub async fn open_project_transaction(editor: &WeakEntity<Editor>,workspace: WeakEntity<Workspace>,diff --git a/crates/project/src/lsp_store.rs b/crates/project/src/lsp_store.rsindex f3ebac277b0..6696ec8c4c2 100644--- a/crates/project/src/lsp_store.rs+++ b/crates/project/src/lsp_store.rs@@ -3311,8 +3311,10 @@ impl LocalLspStore {).await.log_err();- this.update(cx, |this, _| {+ this.update(cx, |this, cx| {if let Some(transaction) = transaction {+ cx.emit(LspStoreEvent::WorkspaceEditApplied(transaction.clone()));+this.as_local_mut().unwrap().last_workspace_edits_by_language_server@@ -3852,6 +3854,7 @@ pub enum LspStoreEvent {edits: Vec<(lsp::Range, Snippet)>,most_recent_edit: clock::Lamport,},+ WorkspaceEditApplied(ProjectTransaction),}#[derive(Clone, Debug, Serialize)]diff --git a/crates/project/src/project.rs b/crates/project/src/project.rsindex 9152096508b..b348fcdae2c 100644--- a/crates/project/src/project.rs+++ b/crates/project/src/project.rs@@ -350,6 +350,7 @@ pub enum Event {SnippetEdit(BufferId, Vec<(lsp::Range, Snippet)>),ExpandedAllForEntry(WorktreeId, ProjectEntryId),EntryRenamed(ProjectTransaction, ProjectPath, PathBuf),+ WorkspaceEditApplied(ProjectTransaction),AgentLocationChanged,}@@ -3249,6 +3250,9 @@ impl Project {cx.emit(Event::SnippetEdit(*buffer_id, edits.clone()))}}+ LspStoreEvent::WorkspaceEditApplied(transaction) => {+ cx.emit(Event::WorkspaceEditApplied(transaction.clone()))+ }}}