debugger/tasks: Remove TaskType enum (#29208)
Closes #ISSUE Release Notes: - N/A --------- Co-authored-by: Cole Miller <m@cole-miller.net> Co-authored-by: Anthony Eid <hello@anthonyeid.me> Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com> Co-authored-by: Anthony <anthony@zed.dev> Co-authored-by: Conrad <conrad@zed.dev>
This commit is contained in:
parent
053fafa90e
commit
67615b968b
53 changed files with 1272 additions and 1114 deletions
|
@ -1,11 +1,11 @@
|
|||
use anyhow::Result;
|
||||
use collections::FxHashMap;
|
||||
use gpui::SharedString;
|
||||
use schemars::{JsonSchema, r#gen::SchemaSettings};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
use std::{net::Ipv4Addr, path::Path};
|
||||
|
||||
use crate::{TaskTemplate, TaskType, task_template::DebugArgs};
|
||||
|
||||
/// Represents the host information of the debug adapter
|
||||
#[derive(Default, Deserialize, Serialize, PartialEq, Eq, JsonSchema, Clone, Debug)]
|
||||
pub struct TcpArgumentsTemplate {
|
||||
|
@ -63,6 +63,8 @@ pub struct LaunchRequest {
|
|||
/// Arguments to pass to a debuggee
|
||||
#[serde(default)]
|
||||
pub args: Vec<String>,
|
||||
#[serde(default)]
|
||||
pub env: FxHashMap<String, String>,
|
||||
}
|
||||
|
||||
/// Represents the type that will determine which request to call on the debug adapter
|
||||
|
@ -75,6 +77,64 @@ pub enum DebugRequest {
|
|||
Attach(AttachRequest),
|
||||
}
|
||||
|
||||
impl DebugRequest {
|
||||
pub fn to_proto(&self) -> proto::DebugRequest {
|
||||
match self {
|
||||
DebugRequest::Launch(launch_request) => proto::DebugRequest {
|
||||
request: Some(proto::debug_request::Request::DebugLaunchRequest(
|
||||
proto::DebugLaunchRequest {
|
||||
program: launch_request.program.clone(),
|
||||
cwd: launch_request
|
||||
.cwd
|
||||
.as_ref()
|
||||
.map(|cwd| cwd.to_string_lossy().into_owned()),
|
||||
args: launch_request.args.clone(),
|
||||
env: launch_request
|
||||
.env
|
||||
.iter()
|
||||
.map(|(k, v)| (k.clone(), v.clone()))
|
||||
.collect(),
|
||||
},
|
||||
)),
|
||||
},
|
||||
DebugRequest::Attach(attach_request) => proto::DebugRequest {
|
||||
request: Some(proto::debug_request::Request::DebugAttachRequest(
|
||||
proto::DebugAttachRequest {
|
||||
process_id: attach_request
|
||||
.process_id
|
||||
.expect("The process ID to be already filled out."),
|
||||
},
|
||||
)),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_proto(val: proto::DebugRequest) -> Result<DebugRequest> {
|
||||
let request = val
|
||||
.request
|
||||
.ok_or_else(|| anyhow::anyhow!("Missing debug request"))?;
|
||||
match request {
|
||||
proto::debug_request::Request::DebugLaunchRequest(proto::DebugLaunchRequest {
|
||||
program,
|
||||
cwd,
|
||||
args,
|
||||
env,
|
||||
}) => Ok(DebugRequest::Launch(LaunchRequest {
|
||||
program,
|
||||
cwd: cwd.map(From::from),
|
||||
args,
|
||||
env: env.into_iter().collect(),
|
||||
})),
|
||||
|
||||
proto::debug_request::Request::DebugAttachRequest(proto::DebugAttachRequest {
|
||||
process_id,
|
||||
}) => Ok(DebugRequest::Attach(AttachRequest {
|
||||
process_id: Some(process_id),
|
||||
})),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LaunchRequest> for DebugRequest {
|
||||
fn from(launch_config: LaunchRequest) -> Self {
|
||||
DebugRequest::Launch(launch_config)
|
||||
|
@ -87,180 +147,46 @@ impl From<AttachRequest> for DebugRequest {
|
|||
}
|
||||
}
|
||||
|
||||
impl TryFrom<TaskTemplate> for DebugTaskTemplate {
|
||||
type Error = ();
|
||||
|
||||
fn try_from(value: TaskTemplate) -> Result<Self, Self::Error> {
|
||||
let TaskType::Debug(debug_args) = value.task_type else {
|
||||
return Err(());
|
||||
};
|
||||
|
||||
let request = match debug_args.request {
|
||||
crate::DebugArgsRequest::Launch => DebugRequest::Launch(LaunchRequest {
|
||||
program: value.command,
|
||||
cwd: value.cwd.map(PathBuf::from),
|
||||
args: value.args,
|
||||
}),
|
||||
crate::DebugArgsRequest::Attach(attach_config) => DebugRequest::Attach(attach_config),
|
||||
};
|
||||
|
||||
Ok(DebugTaskTemplate {
|
||||
locator: debug_args.locator,
|
||||
definition: DebugTaskDefinition {
|
||||
adapter: debug_args.adapter,
|
||||
request,
|
||||
label: value.label,
|
||||
initialize_args: debug_args.initialize_args,
|
||||
tcp_connection: debug_args.tcp_connection,
|
||||
stop_on_entry: debug_args.stop_on_entry,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl DebugTaskTemplate {
|
||||
/// Translate from debug definition to a task template
|
||||
pub fn to_zed_format(self) -> TaskTemplate {
|
||||
let (command, cwd, request) = match self.definition.request {
|
||||
DebugRequest::Launch(launch_config) => (
|
||||
launch_config.program,
|
||||
launch_config
|
||||
.cwd
|
||||
.map(|cwd| cwd.to_string_lossy().to_string()),
|
||||
crate::task_template::DebugArgsRequest::Launch,
|
||||
),
|
||||
DebugRequest::Attach(attach_config) => (
|
||||
"".to_owned(),
|
||||
None,
|
||||
crate::task_template::DebugArgsRequest::Attach(attach_config),
|
||||
),
|
||||
};
|
||||
|
||||
let task_type = TaskType::Debug(DebugArgs {
|
||||
adapter: self.definition.adapter,
|
||||
request,
|
||||
initialize_args: self.definition.initialize_args,
|
||||
locator: self.locator,
|
||||
tcp_connection: self.definition.tcp_connection,
|
||||
stop_on_entry: self.definition.stop_on_entry,
|
||||
});
|
||||
|
||||
let label = self.definition.label.clone();
|
||||
|
||||
TaskTemplate {
|
||||
label,
|
||||
command,
|
||||
args: vec![],
|
||||
task_type,
|
||||
cwd,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, PartialEq, Eq, JsonSchema, Clone, Debug)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct DebugTaskTemplate {
|
||||
pub locator: Option<String>,
|
||||
#[serde(flatten)]
|
||||
pub definition: DebugTaskDefinition,
|
||||
}
|
||||
|
||||
/// This struct represent a user created debug task
|
||||
#[derive(Deserialize, Serialize, PartialEq, Eq, JsonSchema, Clone, Debug)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct DebugTaskDefinition {
|
||||
/// The adapter to run
|
||||
pub adapter: String,
|
||||
/// The type of request that should be called on the debug adapter
|
||||
#[serde(flatten)]
|
||||
pub request: DebugRequest,
|
||||
pub struct DebugScenario {
|
||||
pub adapter: SharedString,
|
||||
/// Name of the debug task
|
||||
pub label: String,
|
||||
pub label: SharedString,
|
||||
/// A task to run prior to spawning the debuggee.
|
||||
pub build: Option<SharedString>,
|
||||
#[serde(flatten)]
|
||||
pub request: Option<DebugRequest>,
|
||||
/// Additional initialization arguments to be sent on DAP initialization
|
||||
#[serde(default)]
|
||||
pub initialize_args: Option<serde_json::Value>,
|
||||
/// Optional TCP connection information
|
||||
///
|
||||
/// If provided, this will be used to connect to the debug adapter instead of
|
||||
/// spawning a new process. This is useful for connecting to a debug adapter
|
||||
/// that is already running or is started by another process.
|
||||
#[serde(default)]
|
||||
pub tcp_connection: Option<TcpArgumentsTemplate>,
|
||||
/// Whether to tell the debug adapter to stop on entry
|
||||
#[serde(default)]
|
||||
pub stop_on_entry: Option<bool>,
|
||||
}
|
||||
|
||||
impl DebugTaskDefinition {
|
||||
impl DebugScenario {
|
||||
pub fn cwd(&self) -> Option<&Path> {
|
||||
if let DebugRequest::Launch(config) = &self.request {
|
||||
config.cwd.as_deref()
|
||||
if let Some(DebugRequest::Launch(config)) = &self.request {
|
||||
config.cwd.as_ref().map(Path::new)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
pub fn to_proto(&self) -> proto::DebugTaskDefinition {
|
||||
proto::DebugTaskDefinition {
|
||||
adapter: self.adapter.clone(),
|
||||
request: Some(match &self.request {
|
||||
DebugRequest::Launch(config) => {
|
||||
proto::debug_task_definition::Request::DebugLaunchRequest(
|
||||
proto::DebugLaunchRequest {
|
||||
program: config.program.clone(),
|
||||
cwd: config.cwd.as_ref().map(|c| c.to_string_lossy().to_string()),
|
||||
args: config.args.clone(),
|
||||
},
|
||||
)
|
||||
}
|
||||
DebugRequest::Attach(attach_request) => {
|
||||
proto::debug_task_definition::Request::DebugAttachRequest(
|
||||
proto::DebugAttachRequest {
|
||||
process_id: attach_request.process_id.unwrap_or_default(),
|
||||
},
|
||||
)
|
||||
}
|
||||
}),
|
||||
label: self.label.clone(),
|
||||
initialize_args: self.initialize_args.as_ref().map(|v| v.to_string()),
|
||||
tcp_connection: self.tcp_connection.as_ref().map(|t| t.to_proto()),
|
||||
stop_on_entry: self.stop_on_entry,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_proto(proto: proto::DebugTaskDefinition) -> Result<Self> {
|
||||
let request = proto
|
||||
.request
|
||||
.ok_or_else(|| anyhow::anyhow!("request is required"))?;
|
||||
Ok(Self {
|
||||
label: proto.label,
|
||||
initialize_args: proto.initialize_args.map(|v| v.into()),
|
||||
tcp_connection: proto
|
||||
.tcp_connection
|
||||
.map(TcpArgumentsTemplate::from_proto)
|
||||
.transpose()?,
|
||||
stop_on_entry: proto.stop_on_entry,
|
||||
adapter: proto.adapter.clone(),
|
||||
request: match request {
|
||||
proto::debug_task_definition::Request::DebugAttachRequest(config) => {
|
||||
DebugRequest::Attach(AttachRequest {
|
||||
process_id: Some(config.process_id),
|
||||
})
|
||||
}
|
||||
|
||||
proto::debug_task_definition::Request::DebugLaunchRequest(config) => {
|
||||
DebugRequest::Launch(LaunchRequest {
|
||||
program: config.program,
|
||||
cwd: config.cwd.map(|cwd| cwd.into()),
|
||||
args: config.args,
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// A group of Debug Tasks defined in a JSON file.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(transparent)]
|
||||
pub struct DebugTaskFile(pub Vec<DebugTaskTemplate>);
|
||||
pub struct DebugTaskFile(pub Vec<DebugScenario>);
|
||||
|
||||
impl DebugTaskFile {
|
||||
/// Generates JSON schema of Tasks JSON template format.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue