debugger: Use DAP schema to configure daps (#30833)

This PR allows DAPs to define their own schema so users can see
completion items when editing their debug.json files.

Users facing this aren’t the biggest chance, but behind the scenes, this
affected a lot of code because we manually translated common fields from
Zed's config format to be adapter-specific. Now we store the raw JSON
from a user's configuration file and just send that.

I'm ignoring the Protobuf CICD error because the DebugTaskDefinition
message is not yet user facing and we need to deprecate some fields in
it.

Release Notes:

- debugger beta: Show completion items when editing debug.json
- debugger beta: Breaking change, debug.json schema now relays on what
DAP you have selected instead of always having the same based values.

---------

Co-authored-by: Remco Smits <djsmits12@gmail.com>
Co-authored-by: Cole Miller <m@cole-miller.net>
Co-authored-by: Cole Miller <cole@zed.dev>
This commit is contained in:
Anthony Eid 2025-05-22 05:48:26 -04:00 committed by GitHub
parent 0d7f4842f3
commit 1c9b818342
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
43 changed files with 2357 additions and 740 deletions

View file

@ -1,14 +1,10 @@
use std::path::PathBuf;
use anyhow::Context as _;
use collections::HashMap;
use gpui::SharedString;
use serde::Deserialize;
use util::ResultExt as _;
use crate::{
AttachRequest, DebugRequest, DebugScenario, DebugTaskFile, EnvVariableReplacer, LaunchRequest,
TcpArgumentsTemplate, VariableName,
DebugScenario, DebugTaskFile, EnvVariableReplacer, TcpArgumentsTemplate, VariableName,
};
#[derive(Clone, Debug, Deserialize, PartialEq)]
@ -40,7 +36,7 @@ struct VsCodeDebugTaskDefinition {
#[serde(default)]
stop_on_entry: Option<bool>,
#[serde(flatten)]
other_attributes: HashMap<String, serde_json_lenient::Value>,
other_attributes: serde_json::Value,
}
impl VsCodeDebugTaskDefinition {
@ -50,33 +46,6 @@ impl VsCodeDebugTaskDefinition {
let definition = DebugScenario {
label,
build: None,
request: match self.request {
Request::Launch => {
let cwd = self.cwd.map(|cwd| PathBuf::from(replacer.replace(&cwd)));
let program = self
.program
.context("vscode debug launch configuration does not define a program")?;
let program = replacer.replace(&program);
let args = self
.args
.into_iter()
.map(|arg| replacer.replace(&arg))
.collect();
let env = self
.env
.into_iter()
.filter_map(|(k, v)| v.map(|v| (k, v)))
.collect();
DebugRequest::Launch(LaunchRequest {
program,
cwd,
args,
env,
})
.into()
}
Request::Attach => DebugRequest::Attach(AttachRequest { process_id: None }).into(),
},
adapter: task_type_to_adapter_name(&self.r#type),
// TODO host?
tcp_connection: self.port.map(|port| TcpArgumentsTemplate {
@ -84,9 +53,7 @@ impl VsCodeDebugTaskDefinition {
host: None,
timeout: None,
}),
stop_on_entry: self.stop_on_entry,
// TODO
initialize_args: None,
config: self.other_attributes,
};
Ok(definition)
}
@ -135,10 +102,9 @@ fn task_type_to_adapter_name(task_type: &str) -> SharedString {
#[cfg(test)]
mod tests {
use serde_json::json;
use collections::FxHashMap;
use crate::{DebugRequest, DebugScenario, DebugTaskFile, LaunchRequest, TcpArgumentsTemplate};
use crate::{DebugScenario, DebugTaskFile, TcpArgumentsTemplate};
use super::VsCodeDebugTaskFile;
@ -173,19 +139,14 @@ mod tests {
DebugTaskFile(vec![DebugScenario {
label: "Debug my JS app".into(),
adapter: "JavaScript".into(),
stop_on_entry: Some(true),
initialize_args: None,
config: json!({
"showDevDebugOutput": false,
}),
tcp_connection: Some(TcpArgumentsTemplate {
port: Some(17),
host: None,
timeout: None,
}),
request: Some(DebugRequest::Launch(LaunchRequest {
program: "${ZED_WORKTREE_ROOT}/xyz.js".into(),
args: vec!["--foo".into(), "${ZED_WORKTREE_ROOT}/thing".into()],
cwd: Some("${ZED_WORKTREE_ROOT}/${FOO}/sub".into()),
env: FxHashMap::from_iter([("X".into(), "Y".into())])
})),
build: None
}])
);