Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions crates/debugger_ui/src/session/running.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ use serde_json::Value;
use settings::Settings;
use stack_frame_list::StackFrameList;
use task::{
BuildTaskDefinition, DebugScenario, SharedTaskContext, Shell, ShellBuilder, SpawnInTerminal,
TaskContext, ZedDebugConfig, substitute_variables_in_str,
BuildTaskDefinition, DebugScenario, SharedTaskContext, Shell, ShellBuilder,
SpawnInTerminal,TaskContext, ZedDebugConfig, substitute_variables_in_str,
};
use terminal_view::TerminalView;
use ui::{
Expand Down Expand Up @@ -1145,6 +1145,9 @@ impl RunningState {
args,
..task.resolved.clone()
};

Workspace::save_for_task(&weak_workspace, task_with_shell.save, cx).await;

let terminal = project
.update(cx, |project, cx| {
project.create_terminal_task(
Expand Down
118 changes: 97 additions & 21 deletions crates/workspace/src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::process::ExitStatus;

use anyhow::Result;
use collections::HashSet;
use gpui::{AppContext, Context, Entity, Task};
use gpui::{AppContext, AsyncWindowContext, Context, Entity, Task, WeakEntity};
use language::Buffer;
use project::{TaskSourceKind, WorktreeId};
use remote::ConnectionState;
Expand Down Expand Up @@ -78,26 +78,7 @@ impl Workspace {

if self.terminal_provider.is_some() {
let task = cx.spawn_in(window, async move |workspace, cx| {
let save_action = match spawn_in_terminal.save {
SaveStrategy::All => {
let save_all = workspace.update_in(cx, |workspace, window, cx| {
let task = workspace.save_all_internal(SaveIntent::SaveAll, window, cx);
// Match the type of the other arm by ignoring the bool value returned
cx.background_spawn(async { task.await.map(|_| ()) })
});
save_all.ok()
}
SaveStrategy::Current => {
let save_current = workspace.update_in(cx, |workspace, window, cx| {
workspace.save_active_item(SaveIntent::SaveAll, window, cx)
});
save_current.ok()
}
SaveStrategy::None => None,
};
if let Some(save_action) = save_action {
save_action.log_err().await;
}
Self::save_for_task(&workspace, spawn_in_terminal.save, cx).await;

let spawn_task = workspace.update_in(cx, |workspace, window, cx| {
workspace
Expand Down Expand Up @@ -132,6 +113,32 @@ impl Workspace {
}
}

pub async fn save_for_task(
workspace: &WeakEntity<Self>,
save_strategy: SaveStrategy,
cx: &mut AsyncWindowContext,
) {
let save_action = match save_strategy {
SaveStrategy::All => {
let save_all = workspace.update_in(cx, |workspace, window, cx| {
let task = workspace.save_all_internal(SaveIntent::SaveAll, window, cx);
cx.background_spawn(async { task.await.map(|_| ()) })
});
save_all.ok()
}
SaveStrategy::Current => {
let save_current = workspace.update_in(cx, |workspace, window, cx| {
workspace.save_active_item(SaveIntent::SaveAll, window, cx)
});
save_current.ok()
}
SaveStrategy::None => None,
};
if let Some(save_action) = save_action {
save_action.log_err().await;
}
}

pub fn start_debug_session(
&mut self,
scenario: DebugScenario,
Expand Down Expand Up @@ -417,6 +424,75 @@ mod tests {
item
}

#[gpui::test]
async fn test_save_for_task_all(cx: &mut TestAppContext) {
let (fixture, cx) = create_fixture(cx, SaveStrategy::All).await;
let workspace = fixture.workspace.downgrade();
cx.run_until_parked();

assert!(cx.read(|cx| fixture.item.read(cx).is_dirty));
fixture
.workspace
.update_in(cx, |_workspace, window, cx| {
cx.spawn_in(window, {
let workspace = workspace.clone();
async move |_this, cx| {
Workspace::save_for_task(&workspace, SaveStrategy::All, cx).await;
}
})
.detach();
});
cx.run_until_parked();
assert!(cx.read(|cx| !fixture.item.read(cx).is_dirty));
}

#[gpui::test]
async fn test_save_for_task_none(cx: &mut TestAppContext) {
let (fixture, cx) = create_fixture(cx, SaveStrategy::None).await;
let workspace = fixture.workspace.downgrade();
cx.run_until_parked();

assert!(cx.read(|cx| fixture.item.read(cx).is_dirty));
fixture
.workspace
.update_in(cx, |_workspace, window, cx| {
cx.spawn_in(window, {
let workspace = workspace.clone();
async move |_this, cx| {
Workspace::save_for_task(&workspace, SaveStrategy::None, cx).await;
}
})
.detach();
});
cx.run_until_parked();
assert!(cx.read(|cx| fixture.item.read(cx).is_dirty));
}

#[gpui::test]
async fn test_save_for_task_current(cx: &mut TestAppContext) {
let (fixture, cx) = create_fixture(cx, SaveStrategy::Current).await;
let inactive = add_test_item(&fixture.workspace, "file2.txt", false, cx);
let workspace = fixture.workspace.downgrade();
cx.run_until_parked();

assert!(cx.read(|cx| fixture.item.read(cx).is_dirty));
assert!(cx.read(|cx| inactive.read(cx).is_dirty));
fixture
.workspace
.update_in(cx, |_workspace, window, cx| {
cx.spawn_in(window, {
let workspace = workspace.clone();
async move |_this, cx| {
Workspace::save_for_task(&workspace, SaveStrategy::Current, cx).await;
}
})
.detach();
});
cx.run_until_parked();
assert!(cx.read(|cx| !fixture.item.read(cx).is_dirty));
assert!(cx.read(|cx| inactive.read(cx).is_dirty));
}

struct TestTerminalProvider {
item: Entity<TestItem>,
dirty_before_spawn: Arc<Mutex<Option<bool>>>,
Expand Down
Loading