extension: Update DAP extension API (#32448)

- DAP schemas will be stored in `debug_adapters_schemas` subdirectory in
extension work dir.
- Added Debug Config integration and such.

Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2025-06-16 16:25:32 +02:00 committed by GitHub
parent 41e9f3148c
commit 8df6ce2aac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 620 additions and 47 deletions

View file

@ -7,10 +7,14 @@ mod since_v0_3_0;
mod since_v0_4_0;
mod since_v0_5_0;
mod since_v0_6_0;
use dap::DebugRequest;
use extension::{DebugTaskDefinition, KeyValueStoreDelegate, WorktreeDelegate};
use language::LanguageName;
use lsp::LanguageServerName;
use release_channel::ReleaseChannel;
use task::{DebugScenario, SpawnInTerminal, TaskTemplate, ZedDebugConfig};
use crate::wasm_host::wit::since_v0_6_0::dap::StartDebuggingRequestArgumentsRequest;
use super::{WasmState, wasm_engine};
use anyhow::{Context as _, Result, anyhow};
@ -922,18 +926,88 @@ impl Extension {
_ => anyhow::bail!("`get_dap_binary` not available prior to v0.6.0"),
}
}
pub async fn call_dap_schema(&self, store: &mut Store<WasmState>) -> Result<String, String> {
pub async fn call_dap_request_kind(
&self,
store: &mut Store<WasmState>,
adapter_name: Arc<str>,
config: serde_json::Value,
) -> Result<Result<StartDebuggingRequestArgumentsRequest, String>> {
match self {
Extension::V0_6_0(ext) => {
let schema = ext
.call_dap_schema(store)
.await
.map_err(|err| err.to_string())?;
let config =
serde_json::to_string(&config).context("Adapter config is not a valid JSON")?;
let dap_binary = ext
.call_dap_request_kind(store, &adapter_name, &config)
.await?
.map_err(|e| anyhow!("{e:?}"))?;
schema
Ok(Ok(dap_binary))
}
_ => Err("`get_dap_binary` not available prior to v0.6.0".to_string()),
_ => anyhow::bail!("`dap_request_kind` not available prior to v0.6.0"),
}
}
pub async fn call_dap_config_to_scenario(
&self,
store: &mut Store<WasmState>,
config: ZedDebugConfig,
resource: Resource<Arc<dyn WorktreeDelegate>>,
) -> Result<Result<DebugScenario, String>> {
match self {
Extension::V0_6_0(ext) => {
let config = config.into();
let dap_binary = ext
.call_dap_config_to_scenario(store, &config, resource)
.await?
.map_err(|e| anyhow!("{e:?}"))?;
Ok(Ok(dap_binary.try_into()?))
}
_ => anyhow::bail!("`dap_config_to_scenario` not available prior to v0.6.0"),
}
}
pub async fn call_dap_locator_create_scenario(
&self,
store: &mut Store<WasmState>,
locator_name: String,
build_config_template: TaskTemplate,
resolved_label: String,
debug_adapter_name: String,
) -> Result<Option<DebugScenario>> {
match self {
Extension::V0_6_0(ext) => {
let build_config_template = build_config_template.into();
let dap_binary = ext
.call_dap_locator_create_scenario(
store,
&locator_name,
&build_config_template,
&resolved_label,
&debug_adapter_name,
)
.await?;
Ok(dap_binary.map(TryInto::try_into).transpose()?)
}
_ => anyhow::bail!("`dap_locator_create_scenario` not available prior to v0.6.0"),
}
}
pub async fn call_run_dap_locator(
&self,
store: &mut Store<WasmState>,
locator_name: String,
resolved_build_task: SpawnInTerminal,
) -> Result<Result<DebugRequest, String>> {
match self {
Extension::V0_6_0(ext) => {
let build_config_template = resolved_build_task.into();
let dap_request = ext
.call_run_dap_locator(store, &locator_name, &build_config_template)
.await?
.map_err(|e| anyhow!("{e:?}"))?;
Ok(Ok(dap_request.into()))
}
_ => anyhow::bail!("`dap_locator_create_scenario` not available prior to v0.6.0"),
}
}
}