@@ -1903,6 +1903,30 @@ impl Editor {
editor.update_lsp_data(false, Some(*buffer_id), window, cx);
}
}
+ project::Event::UnsavedBufferEdit(buffer) => {
+ let Some(workspace) = editor.workspace() else {
+ return;
+ };
+ workspace.update(cx, |workspace, cx| {
+ Self::new_in_workspace_from_buffer(
+ workspace,
+ buffer.clone(),
+ window,
+ cx,
+ ).detach_and_prompt_err(
+ "Failed to open buffer",
+ window,
+ cx,
+ |e, _, _| match e.error_code() {
+ ErrorCode::RemoteUpgradeRequired => Some(format!(
+ "The remote instance of Zed does not support this yet. It must be upgraded to {}",
+ e.error_tag("required").unwrap_or("the latest version")
+ )),
+ _ => None,
+ },
+ );
+ });
+ }
_ => {}
},
));
@@ -2584,6 +2608,23 @@ impl Editor {
})
}
+ fn new_in_workspace_from_buffer(
+ workspace: &mut Workspace,
+ buffer: Entity<Buffer>,
+ window: &mut Window,
+ cx: &mut Context<Workspace>,
+ ) -> Task<Result<Entity<Editor>>> {
+ let project = workspace.project().clone();
+ cx.spawn_in(window, async move |workspace, cx| {
+ workspace.update_in(cx, |workspace, window, cx| {
+ let editor =
+ cx.new(|cx| Editor::for_buffer(buffer, Some(project.clone()), window, cx));
+ workspace.add_item_to_active_pane(Box::new(editor.clone()), None, true, window, cx);
+ editor
+ })
+ })
+ }
+
fn new_file_vertical(
workspace: &mut Workspace,
_: &workspace::NewFileSplitVertical,
@@ -3555,6 +3555,7 @@ pub enum LspStoreEvent {
edits: Vec<(lsp::Range, Snippet)>,
most_recent_edit: clock::Lamport,
},
+ UnsavedBufferEdit(Entity<Buffer>),
}
#[derive(Clone, Debug, Serialize)]
@@ -9210,15 +9211,24 @@ impl LspStore {
.log_err()
.flatten()?;
- LocalLspStore::deserialize_workspace_edit(
- this.upgrade()?,
- edit,
- false,
- language_server.clone(),
- cx,
- )
- .await
- .ok();
+ if let Some(transaction) =
+ LocalLspStore::deserialize_workspace_edit(
+ this.upgrade()?,
+ edit,
+ false,
+ language_server.clone(),
+ cx,
+ )
+ .await
+ .ok()
+ {
+ for (buffer, _) in transaction.0 {
+ this.update(cx, |_, cx| {
+ cx.emit(LspStoreEvent::UnsavedBufferEdit(buffer));
+ })
+ .ok();
+ }
+ }
Some(())
}
});
@@ -326,6 +326,7 @@ pub enum Event {
RefreshCodeLens,
RevealInProjectPanel(ProjectEntryId),
SnippetEdit(BufferId, Vec<(lsp::Range, Snippet)>),
+ UnsavedBufferEdit(Entity<Buffer>),
ExpandedAllForEntry(WorktreeId, ProjectEntryId),
AgentLocationChanged,
}
@@ -2985,6 +2986,9 @@ impl Project {
cx.emit(Event::SnippetEdit(*buffer_id, edits.clone()))
}
}
+ LspStoreEvent::UnsavedBufferEdit(buffer) => {
+ cx.emit(Event::UnsavedBufferEdit(buffer.clone()));
+ }
}
}