## Summary This PR starts the process of adding debug task locators to Zed's debugger system. A task locator is a secondary resolution phase that allows a debug task to run a command before starting a debug session and then uses the output of the run command to configure itself. Locators are most applicable when debugging a compiled language but will be helpful for any language as well. ## Architecture At a high level, this works by adding a debug task queue to `Workspace`. Which add's a debug configuration associated with a `TaskId` whenever a resolved task with a debug config is added to `TaskInventory`'s queue. Then, when the `SpawnInTerminal` task finishes running, it emits its task_id and the result of the ran task. When a ran task exits successfully, `Workspace` tells `Project` to start a debug session using its stored debug config, then `DapStore` queries the `LocatorStore` to configure the debug configuration if it has a valid locator argument. Release Notes: - N/A
76 lines
2.2 KiB
Rust
76 lines
2.2 KiB
Rust
use gpui::Context;
|
|
use project::TaskSourceKind;
|
|
use remote::ConnectionState;
|
|
use task::{ResolvedTask, TaskContext, TaskTemplate};
|
|
|
|
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");
|
|
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,
|
|
);
|
|
}
|
|
}
|
|
|
|
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);
|
|
})
|
|
}
|
|
});
|
|
}
|
|
|
|
cx.emit(crate::Event::SpawnTask {
|
|
action: Box::new(spawn_in_terminal),
|
|
});
|
|
}
|
|
}
|