debugger: More tidy up for SSH (#28993)

Split `locator` out of DebugTaskDefinition to make it clearer when
location needs to happen.

Release Notes:

- N/A

---------

Co-authored-by: Anthony Eid <hello@anthonyeid.me>
Co-authored-by: Anthony <anthony@zed.dev>
Co-authored-by: Cole Miller <m@cole-miller.net>
This commit is contained in:
Conrad Irwin 2025-04-21 10:00:03 -06:00 committed by GitHub
parent d13cd007a2
commit 9d35f0389d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
57 changed files with 1146 additions and 884 deletions

View file

@ -1,75 +1,132 @@
use gpui::Context;
use std::process::ExitStatus;
use anyhow::{Result, anyhow};
use gpui::{Context, Task};
use project::TaskSourceKind;
use remote::ConnectionState;
use task::{ResolvedTask, TaskContext, TaskTemplate};
use task::{ResolvedTask, SpawnInTerminal, TaskContext, TaskTemplate};
use ui::Window;
use crate::Workspace;
pub fn schedule_task(
workspace: &mut Workspace,
task_source_kind: TaskSourceKind,
task_to_resolve: &TaskTemplate,
task_cx: &TaskContext,
omit_history: bool,
cx: &mut Context<Workspace>,
) {
match workspace.project.read(cx).ssh_connection_state(cx) {
None | Some(ConnectionState::Connected) => {}
Some(
ConnectionState::Connecting
| ConnectionState::Disconnected
| ConnectionState::HeartbeatMissed
| ConnectionState::Reconnecting,
) => {
log::warn!("Cannot schedule tasks when disconnected from a remote host");
impl Workspace {
pub fn schedule_task(
self: &mut Workspace,
task_source_kind: TaskSourceKind,
task_to_resolve: &TaskTemplate,
task_cx: &TaskContext,
omit_history: bool,
window: &mut Window,
cx: &mut Context<Self>,
) {
match self.project.read(cx).ssh_connection_state(cx) {
None | Some(ConnectionState::Connected) => {}
Some(
ConnectionState::Connecting
| ConnectionState::Disconnected
| ConnectionState::HeartbeatMissed
| ConnectionState::Reconnecting,
) => {
log::warn!("Cannot schedule tasks when disconnected from a remote host");
return;
}
}
if let Some(spawn_in_terminal) =
task_to_resolve.resolve_task(&task_source_kind.to_id_base(), task_cx)
{
self.schedule_resolved_task(
task_source_kind,
spawn_in_terminal,
omit_history,
window,
cx,
);
}
}
pub fn schedule_resolved_task(
self: &mut Workspace,
task_source_kind: TaskSourceKind,
mut resolved_task: ResolvedTask,
omit_history: bool,
window: &mut Window,
cx: &mut Context<Workspace>,
) {
if let Some(spawn_in_terminal) = resolved_task.resolved.take() {
if !omit_history {
resolved_task.resolved = Some(spawn_in_terminal.clone());
self.project().update(cx, |project, cx| {
if let Some(task_inventory) =
project.task_store().read(cx).task_inventory().cloned()
{
task_inventory.update(cx, |inventory, _| {
inventory.task_scheduled(task_source_kind, resolved_task);
})
}
});
}
if let Some(terminal_provider) = self.terminal_provider.as_ref() {
terminal_provider
.spawn(spawn_in_terminal, window, cx)
.detach_and_log_err(cx);
}
}
}
pub fn schedule_debug_task(
&mut self,
task: ResolvedTask,
window: &mut Window,
cx: &mut Context<Workspace>,
) {
let Some(debug_config) = task.resolved_debug_adapter_config() else {
log::error!("Debug task has no debug adapter config");
return;
}
}
};
if let Some(spawn_in_terminal) =
task_to_resolve.resolve_task(&task_source_kind.to_id_base(), task_cx)
{
schedule_resolved_task(
workspace,
task_source_kind,
spawn_in_terminal,
omit_history,
cx,
);
}
}
let project = self.project().clone();
cx.spawn_in(window, async move |workspace, cx| {
let config = if debug_config.locator.is_some() {
let task = workspace.update_in(cx, |workspace, window, cx| {
workspace.spawn_in_terminal(task.resolved.unwrap(), window, cx)
})?;
pub fn schedule_resolved_task(
workspace: &mut Workspace,
task_source_kind: TaskSourceKind,
mut resolved_task: ResolvedTask,
omit_history: bool,
cx: &mut Context<Workspace>,
) {
let debug_config = resolved_task.resolved_debug_adapter_config();
if let Some(spawn_in_terminal) = resolved_task.resolved.take() {
if let Some(debug_config) = debug_config {
workspace
.debug_task_queue
.insert(resolved_task.id.clone(), debug_config);
}
if !omit_history {
resolved_task.resolved = Some(spawn_in_terminal.clone());
workspace.project().update(cx, |project, cx| {
if let Some(task_inventory) =
project.task_store().read(cx).task_inventory().cloned()
{
task_inventory.update(cx, |inventory, _| {
inventory.task_scheduled(task_source_kind, resolved_task);
})
let exit_code = task.await?;
if !exit_code.success() {
return anyhow::Ok(());
}
});
}
let ret = project
.update(cx, |project, cx| {
project.dap_store().update(cx, |dap_store, cx| {
dap_store.run_debug_locator(debug_config, cx)
})
})?
.await?;
ret
} else {
debug_config.definition
};
cx.emit(crate::Event::SpawnTask {
action: Box::new(spawn_in_terminal),
});
project
.update(cx, |project, cx| project.start_debug_session(config, cx))?
.await?;
anyhow::Ok(())
})
.detach_and_log_err(cx);
}
pub fn spawn_in_terminal(
self: &mut Workspace,
spawn_in_terminal: SpawnInTerminal,
window: &mut Window,
cx: &mut Context<Workspace>,
) -> Task<Result<ExitStatus>> {
if let Some(terminal_provider) = self.terminal_provider.as_ref() {
terminal_provider.spawn(spawn_in_terminal, window, cx)
} else {
Task::ready(Err(anyhow!("No terminal provider")))
}
}
}