debugger: Mark DapLocator::create_scenario as an async function (#32680)

Paves way for locators in extensions.

Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2025-06-13 13:19:03 +02:00 committed by GitHub
parent 2c491d3a66
commit d5b8c21a75
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 290 additions and 218 deletions

View file

@ -287,11 +287,17 @@ impl DapStore {
adapter: DebugAdapterName,
label: SharedString,
cx: &mut App,
) -> Option<DebugScenario> {
DapRegistry::global(cx)
.locators()
.values()
.find_map(|locator| locator.create_scenario(&build, &label, adapter.clone()))
) -> Task<Option<DebugScenario>> {
let locators = DapRegistry::global(cx).locators();
cx.background_spawn(async move {
for locator in locators.values() {
if let Some(scenario) = locator.create_scenario(&build, &label, &adapter).await {
return Some(scenario);
}
}
None
})
}
pub fn run_debug_locator(

View file

@ -41,11 +41,11 @@ impl DapLocator for CargoLocator {
fn name(&self) -> SharedString {
SharedString::new_static("rust-cargo-locator")
}
fn create_scenario(
async fn create_scenario(
&self,
build_config: &TaskTemplate,
resolved_label: &str,
adapter: DebugAdapterName,
adapter: &DebugAdapterName,
) -> Option<DebugScenario> {
if build_config.command != "cargo" {
return None;
@ -77,7 +77,7 @@ impl DapLocator for CargoLocator {
}
Some(DebugScenario {
adapter: adapter.0,
adapter: adapter.0.clone(),
label: resolved_label.to_string().into(),
build: Some(BuildTaskDefinition::Template {
task_template,

View file

@ -89,11 +89,11 @@ impl DapLocator for GoLocator {
SharedString::new_static("go-debug-locator")
}
fn create_scenario(
async fn create_scenario(
&self,
build_config: &TaskTemplate,
resolved_label: &str,
adapter: DebugAdapterName,
adapter: &DebugAdapterName,
) -> Option<DebugScenario> {
if build_config.command != "go" {
return None;
@ -170,7 +170,7 @@ impl DapLocator for GoLocator {
Some(DebugScenario {
label: resolved_label.to_string().into(),
adapter: adapter.0,
adapter: adapter.0.clone(),
build: None,
config: config,
tcp_connection: None,
@ -214,7 +214,7 @@ impl DapLocator for GoLocator {
Some(DebugScenario {
label: resolved_label.to_string().into(),
adapter: adapter.0,
adapter: adapter.0.clone(),
build: None,
config,
tcp_connection: None,
@ -232,10 +232,11 @@ impl DapLocator for GoLocator {
#[cfg(test)]
mod tests {
use super::*;
use gpui::TestAppContext;
use task::{HideStrategy, RevealStrategy, RevealTarget, Shell, TaskTemplate};
#[test]
fn test_create_scenario_for_go_build() {
#[gpui::test]
async fn test_create_scenario_for_go_build(_: &mut TestAppContext) {
let locator = GoLocator;
let task = TaskTemplate {
label: "go build".into(),
@ -254,14 +255,15 @@ mod tests {
show_command: true,
};
let scenario =
locator.create_scenario(&task, "test label", DebugAdapterName("Delve".into()));
let scenario = locator
.create_scenario(&task, "test label", &DebugAdapterName("Delve".into()))
.await;
assert!(scenario.is_none());
}
#[test]
fn test_skip_non_go_commands_with_non_delve_adapter() {
#[gpui::test]
async fn test_skip_non_go_commands_with_non_delve_adapter(_: &mut TestAppContext) {
let locator = GoLocator;
let task = TaskTemplate {
label: "cargo build".into(),
@ -280,19 +282,22 @@ mod tests {
show_command: true,
};
let scenario = locator.create_scenario(
&task,
"test label",
DebugAdapterName("SomeOtherAdapter".into()),
);
let scenario = locator
.create_scenario(
&task,
"test label",
&DebugAdapterName("SomeOtherAdapter".into()),
)
.await;
assert!(scenario.is_none());
let scenario =
locator.create_scenario(&task, "test label", DebugAdapterName("Delve".into()));
let scenario = locator
.create_scenario(&task, "test label", &DebugAdapterName("Delve".into()))
.await;
assert!(scenario.is_none());
}
#[test]
fn test_go_locator_run() {
#[gpui::test]
async fn test_go_locator_run(_: &mut TestAppContext) {
let locator = GoLocator;
let delve = DebugAdapterName("Delve".into());
@ -319,7 +324,8 @@ mod tests {
};
let scenario = locator
.create_scenario(&task, "test run label", delve)
.create_scenario(&task, "test run label", &delve)
.await
.unwrap();
let config: DelveLaunchRequest = serde_json::from_value(scenario.config).unwrap();
@ -350,8 +356,8 @@ mod tests {
);
}
#[test]
fn test_go_locator_test() {
#[gpui::test]
async fn test_go_locator_test(_: &mut TestAppContext) {
let locator = GoLocator;
let delve = DebugAdapterName("Delve".into());
@ -370,7 +376,8 @@ mod tests {
..Default::default()
};
let result = locator
.create_scenario(&task_with_tags, "", delve.clone())
.create_scenario(&task_with_tags, "", &delve)
.await
.unwrap();
let config: DelveLaunchRequest = serde_json::from_value(result.config).unwrap();
@ -393,8 +400,8 @@ mod tests {
);
}
#[test]
fn test_skip_unsupported_go_commands() {
#[gpui::test]
async fn test_skip_unsupported_go_commands(_: &mut TestAppContext) {
let locator = GoLocator;
let task = TaskTemplate {
label: "go clean".into(),
@ -413,8 +420,9 @@ mod tests {
show_command: true,
};
let scenario =
locator.create_scenario(&task, "test label", DebugAdapterName("Delve".into()));
let scenario = locator
.create_scenario(&task, "test label", &DebugAdapterName("Delve".into()))
.await;
assert!(scenario.is_none());
}
}

View file

@ -19,11 +19,11 @@ impl DapLocator for NodeLocator {
}
/// Determines whether this locator can generate debug target for given task.
fn create_scenario(
async fn create_scenario(
&self,
build_config: &TaskTemplate,
resolved_label: &str,
adapter: DebugAdapterName,
adapter: &DebugAdapterName,
) -> Option<DebugScenario> {
if adapter.0.as_ref() != "JavaScript" {
return None;
@ -68,7 +68,7 @@ impl DapLocator for NodeLocator {
});
Some(DebugScenario {
adapter: adapter.0,
adapter: adapter.0.clone(),
label: resolved_label.to_string().into(),
build: None,
config,

View file

@ -16,11 +16,11 @@ impl DapLocator for PythonLocator {
}
/// Determines whether this locator can generate debug target for given task.
fn create_scenario(
async fn create_scenario(
&self,
build_config: &TaskTemplate,
resolved_label: &str,
adapter: DebugAdapterName,
adapter: &DebugAdapterName,
) -> Option<DebugScenario> {
if adapter.0.as_ref() != "Debugpy" {
return None;
@ -92,7 +92,7 @@ impl DapLocator for PythonLocator {
}
Some(DebugScenario {
adapter: adapter.0,
adapter: adapter.0.clone(),
label: resolved_label.to_string().into(),
build: None,
config,