Skip to content

Commit 0eccdfe

Browse files
authored
project: Spawn terminal process on background executor (#40774)
We were spawning the process on the foreground thread before which can block an arbitrary amount of time. Likewise we no longer block deserialization on the terminal loading. Release Notes: - Improved startup time on systems with slow process spawning capabilities
1 parent 0be70e2 commit 0eccdfe

File tree

28 files changed

+727
-640
lines changed

28 files changed

+727
-640
lines changed

crates/agent_ui/src/agent_diff.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,11 +581,13 @@ impl Item for AgentDiffPane {
581581
_workspace_id: Option<workspace::WorkspaceId>,
582582
window: &mut Window,
583583
cx: &mut Context<Self>,
584-
) -> Option<Entity<Self>>
584+
) -> Task<Option<Entity<Self>>>
585585
where
586586
Self: Sized,
587587
{
588-
Some(cx.new(|cx| Self::new(self.thread.clone(), self.workspace.clone(), window, cx)))
588+
Task::ready(Some(cx.new(|cx| {
589+
Self::new(self.thread.clone(), self.workspace.clone(), window, cx)
590+
})))
589591
}
590592

591593
fn is_dirty(&self, cx: &App) -> bool {

crates/collab/src/tests/following_tests.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -776,26 +776,30 @@ async fn test_peers_following_each_other(cx_a: &mut TestAppContext, cx_b: &mut T
776776
.unwrap();
777777

778778
// Clients A and B follow each other in split panes
779-
workspace_a.update_in(cx_a, |workspace, window, cx| {
780-
workspace.split_and_clone(
781-
workspace.active_pane().clone(),
782-
SplitDirection::Right,
783-
window,
784-
cx,
785-
);
786-
});
779+
workspace_a
780+
.update_in(cx_a, |workspace, window, cx| {
781+
workspace.split_and_clone(
782+
workspace.active_pane().clone(),
783+
SplitDirection::Right,
784+
window,
785+
cx,
786+
)
787+
})
788+
.await;
787789
workspace_a.update_in(cx_a, |workspace, window, cx| {
788790
workspace.follow(client_b.peer_id().unwrap(), window, cx)
789791
});
790792
executor.run_until_parked();
791-
workspace_b.update_in(cx_b, |workspace, window, cx| {
792-
workspace.split_and_clone(
793-
workspace.active_pane().clone(),
794-
SplitDirection::Right,
795-
window,
796-
cx,
797-
);
798-
});
793+
workspace_b
794+
.update_in(cx_b, |workspace, window, cx| {
795+
workspace.split_and_clone(
796+
workspace.active_pane().clone(),
797+
SplitDirection::Right,
798+
window,
799+
cx,
800+
)
801+
})
802+
.await;
799803
workspace_b.update_in(cx_b, |workspace, window, cx| {
800804
workspace.follow(client_a.peer_id().unwrap(), window, cx)
801805
});
@@ -1369,9 +1373,11 @@ async fn test_auto_unfollowing(cx_a: &mut TestAppContext, cx_b: &mut TestAppCont
13691373
);
13701374

13711375
// When client B activates a different pane, it continues following client A in the original pane.
1372-
workspace_b.update_in(cx_b, |workspace, window, cx| {
1373-
workspace.split_and_clone(pane_b.clone(), SplitDirection::Right, window, cx)
1374-
});
1376+
workspace_b
1377+
.update_in(cx_b, |workspace, window, cx| {
1378+
workspace.split_and_clone(pane_b.clone(), SplitDirection::Right, window, cx)
1379+
})
1380+
.await;
13751381
assert_eq!(
13761382
workspace_b.update(cx_b, |workspace, _| workspace.leader_for_pane(&pane_b)),
13771383
Some(leader_id.into())

crates/collab/src/tests/integration_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6748,7 +6748,7 @@ async fn test_preview_tabs(cx: &mut TestAppContext) {
67486748
pane.update(cx, |pane, cx| {
67496749
pane.split(workspace::SplitDirection::Right, cx);
67506750
});
6751-
6751+
cx.run_until_parked();
67526752
let right_pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());
67536753

67546754
pane.update(cx, |pane, cx| {

crates/collab_ui/src/channel_view.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,8 @@ impl Item for ChannelView {
498498
_: Option<WorkspaceId>,
499499
window: &mut Window,
500500
cx: &mut Context<Self>,
501-
) -> Option<Entity<Self>> {
502-
Some(cx.new(|cx| {
501+
) -> Task<Option<Entity<Self>>> {
502+
Task::ready(Some(cx.new(|cx| {
503503
Self::new(
504504
self.project.clone(),
505505
self.workspace.clone(),
@@ -508,7 +508,7 @@ impl Item for ChannelView {
508508
window,
509509
cx,
510510
)
511-
}))
511+
})))
512512
}
513513

514514
fn navigate(

crates/diagnostics/src/buffer_diagnostics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -693,11 +693,11 @@ impl Item for BufferDiagnosticsEditor {
693693
_workspace_id: Option<workspace::WorkspaceId>,
694694
window: &mut Window,
695695
cx: &mut Context<Self>,
696-
) -> Option<Entity<Self>>
696+
) -> Task<Option<Entity<Self>>>
697697
where
698698
Self: Sized,
699699
{
700-
Some(cx.new(|cx| {
700+
Task::ready(Some(cx.new(|cx| {
701701
BufferDiagnosticsEditor::new(
702702
self.project_path.clone(),
703703
self.project.clone(),
@@ -706,7 +706,7 @@ impl Item for BufferDiagnosticsEditor {
706706
window,
707707
cx,
708708
)
709-
}))
709+
})))
710710
}
711711

712712
fn deactivated(&mut self, window: &mut Window, cx: &mut Context<Self>) {

crates/diagnostics/src/diagnostics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -732,19 +732,19 @@ impl Item for ProjectDiagnosticsEditor {
732732
_workspace_id: Option<workspace::WorkspaceId>,
733733
window: &mut Window,
734734
cx: &mut Context<Self>,
735-
) -> Option<Entity<Self>>
735+
) -> Task<Option<Entity<Self>>>
736736
where
737737
Self: Sized,
738738
{
739-
Some(cx.new(|cx| {
739+
Task::ready(Some(cx.new(|cx| {
740740
ProjectDiagnosticsEditor::new(
741741
self.include_warnings,
742742
self.project.clone(),
743743
self.workspace.clone(),
744744
window,
745745
cx,
746746
)
747-
}))
747+
})))
748748
}
749749

750750
fn is_dirty(&self, cx: &App) -> bool {

crates/editor/src/items.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,11 +762,11 @@ impl Item for Editor {
762762
_workspace_id: Option<WorkspaceId>,
763763
window: &mut Window,
764764
cx: &mut Context<Self>,
765-
) -> Option<Entity<Editor>>
765+
) -> Task<Option<Entity<Editor>>>
766766
where
767767
Self: Sized,
768768
{
769-
Some(cx.new(|cx| self.clone(window, cx)))
769+
Task::ready(Some(cx.new(|cx| self.clone(window, cx))))
770770
}
771771

772772
fn set_nav_history(

crates/git_ui/src/commit_view.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use editor::{Editor, EditorEvent, MultiBuffer, SelectionEffects, multibuffer_con
44
use git::repository::{CommitDetails, CommitDiff, RepoPath};
55
use gpui::{
66
Action, AnyElement, AnyView, App, AppContext as _, AsyncApp, AsyncWindowContext, Context,
7-
Entity, EventEmitter, FocusHandle, Focusable, IntoElement, PromptLevel, Render, WeakEntity,
8-
Window, actions,
7+
Entity, EventEmitter, FocusHandle, Focusable, IntoElement, PromptLevel, Render, Task,
8+
WeakEntity, Window, actions,
99
};
1010
use language::{
1111
Anchor, Buffer, Capability, DiskState, File, LanguageRegistry, LineEnding, OffsetRangeExt as _,
@@ -561,11 +561,11 @@ impl Item for CommitView {
561561
_workspace_id: Option<workspace::WorkspaceId>,
562562
window: &mut Window,
563563
cx: &mut Context<Self>,
564-
) -> Option<Entity<Self>>
564+
) -> Task<Option<Entity<Self>>>
565565
where
566566
Self: Sized,
567567
{
568-
Some(cx.new(|cx| {
568+
Task::ready(Some(cx.new(|cx| {
569569
let editor = cx.new(|cx| {
570570
self.editor
571571
.update(cx, |editor, cx| editor.clone(window, cx))
@@ -577,7 +577,7 @@ impl Item for CommitView {
577577
commit: self.commit.clone(),
578578
stash: self.stash,
579579
}
580-
}))
580+
})))
581581
}
582582
}
583583

crates/git_ui/src/project_diff.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,12 +625,16 @@ impl Item for ProjectDiff {
625625
_workspace_id: Option<workspace::WorkspaceId>,
626626
window: &mut Window,
627627
cx: &mut Context<Self>,
628-
) -> Option<Entity<Self>>
628+
) -> Task<Option<Entity<Self>>>
629629
where
630630
Self: Sized,
631631
{
632-
let workspace = self.workspace.upgrade()?;
633-
Some(cx.new(|cx| ProjectDiff::new(self.project.clone(), workspace, window, cx)))
632+
let Some(workspace) = self.workspace.upgrade() else {
633+
return Task::ready(None);
634+
};
635+
Task::ready(Some(cx.new(|cx| {
636+
ProjectDiff::new(self.project.clone(), workspace, window, cx)
637+
})))
634638
}
635639

636640
fn is_dirty(&self, cx: &App) -> bool {

crates/image_viewer/src/image_viewer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,15 @@ impl Item for ImageView {
176176
_workspace_id: Option<WorkspaceId>,
177177
_: &mut Window,
178178
cx: &mut Context<Self>,
179-
) -> Option<Entity<Self>>
179+
) -> Task<Option<Entity<Self>>>
180180
where
181181
Self: Sized,
182182
{
183-
Some(cx.new(|cx| Self {
183+
Task::ready(Some(cx.new(|cx| Self {
184184
image_item: self.image_item.clone(),
185185
project: self.project.clone(),
186186
focus_handle: cx.focus_handle(),
187-
}))
187+
})))
188188
}
189189

190190
fn has_deleted_file(&self, cx: &App) -> bool {

0 commit comments

Comments
 (0)