debugger: Allow locators to generate full debug scenarios (#30014)

Closes #ISSUE

Release Notes:

- N/A

---------

Co-authored-by: Anthony <anthony@zed.dev>
Co-authored-by: Remco Smits <djsmits12@gmail.com>
This commit is contained in:
Piotr Osiewicz 2025-05-06 18:39:49 +02:00 committed by GitHub
parent a378b3f300
commit bbfcd885ab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 197 additions and 146 deletions

View file

@ -6,6 +6,8 @@ use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use std::{net::Ipv4Addr, path::Path};
use crate::TaskTemplate;
/// Represents the host information of the debug adapter
#[derive(Default, Deserialize, Serialize, PartialEq, Eq, JsonSchema, Clone, Debug)]
pub struct TcpArgumentsTemplate {
@ -171,6 +173,18 @@ impl From<AttachRequest> for DebugRequest {
}
}
#[derive(Deserialize, Serialize, PartialEq, Eq, JsonSchema, Clone, Debug)]
#[serde(untagged)]
#[allow(clippy::large_enum_variant)]
pub enum BuildTaskDefinition {
ByName(SharedString),
Template {
#[serde(flatten)]
task_template: TaskTemplate,
#[serde(skip)]
locator_name: Option<SharedString>,
},
}
/// This struct represent a user created debug task
#[derive(Deserialize, Serialize, PartialEq, Eq, JsonSchema, Clone, Debug)]
#[serde(rename_all = "snake_case")]
@ -180,7 +194,7 @@ pub struct DebugScenario {
pub label: SharedString,
/// A task to run prior to spawning the debuggee.
#[serde(default)]
pub build: Option<SharedString>,
pub build: Option<BuildTaskDefinition>,
#[serde(flatten)]
pub request: Option<DebugRequest>,
/// Additional initialization arguments to be sent on DAP initialization

View file

@ -16,7 +16,8 @@ use std::path::PathBuf;
use std::str::FromStr;
pub use debug_format::{
AttachRequest, DebugRequest, DebugScenario, DebugTaskFile, LaunchRequest, TcpArgumentsTemplate,
AttachRequest, BuildTaskDefinition, DebugRequest, DebugScenario, DebugTaskFile, LaunchRequest,
TcpArgumentsTemplate,
};
pub use task_template::{
DebugArgsRequest, HideStrategy, RevealStrategy, TaskTemplate, TaskTemplates,
@ -341,6 +342,7 @@ enum WindowsShellType {
pub struct ShellBuilder {
program: String,
args: Vec<String>,
interactive: bool,
}
pub static DEFAULT_REMOTE_SHELL: &str = "\"${SHELL:-sh}\"";
@ -359,7 +361,15 @@ impl ShellBuilder {
Shell::Program(shell) => (shell.clone(), Vec::new()),
Shell::WithArguments { program, args, .. } => (program.clone(), args.clone()),
};
Self { program, args }
Self {
program,
args,
interactive: true,
}
}
pub fn non_interactive(mut self) -> Self {
self.interactive = false;
self
}
}
@ -367,7 +377,8 @@ impl ShellBuilder {
impl ShellBuilder {
/// Returns the label to show in the terminal tab
pub fn command_label(&self, command_label: &str) -> String {
format!("{} -i -c '{}'", self.program, command_label)
let interactivity = self.interactive.then_some("-i ").unwrap_or_default();
format!("{} {interactivity}-c '{}'", self.program, command_label)
}
/// Returns the program and arguments to run this task in a shell.
@ -379,8 +390,12 @@ impl ShellBuilder {
command.push_str(&arg);
command
});
self.args
.extend(["-i".to_owned(), "-c".to_owned(), combined_command]);
self.args.extend(
self.interactive
.then(|| "-i".to_owned())
.into_iter()
.chain(["-c".to_owned(), combined_command]),
);
(self.program, self.args)
}