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:
parent
2c491d3a66
commit
d5b8c21a75
10 changed files with 290 additions and 218 deletions
|
@ -265,7 +265,7 @@ impl Inventory {
|
|||
current_resolved_tasks: Vec<(TaskSourceKind, task::ResolvedTask)>,
|
||||
add_current_language_tasks: bool,
|
||||
cx: &mut App,
|
||||
) -> (Vec<DebugScenario>, Vec<(TaskSourceKind, DebugScenario)>) {
|
||||
) -> Task<(Vec<DebugScenario>, Vec<(TaskSourceKind, DebugScenario)>)> {
|
||||
let mut scenarios = Vec::new();
|
||||
|
||||
if let Some(worktree_id) = task_contexts
|
||||
|
@ -279,9 +279,13 @@ impl Inventory {
|
|||
}
|
||||
scenarios.extend(self.global_debug_scenarios_from_settings());
|
||||
|
||||
if let Some(location) = task_contexts.location() {
|
||||
let file = location.buffer.read(cx).file();
|
||||
let language = location.buffer.read(cx).language();
|
||||
let last_scheduled_scenarios = self.last_scheduled_scenarios.iter().cloned().collect();
|
||||
|
||||
let adapter = task_contexts.location().and_then(|location| {
|
||||
let (file, language) = {
|
||||
let buffer = location.buffer.read(cx);
|
||||
(buffer.file(), buffer.language())
|
||||
};
|
||||
let language_name = language.as_ref().map(|l| l.name());
|
||||
let adapter = language_settings(language_name, file, cx)
|
||||
.debuggers
|
||||
|
@ -290,7 +294,10 @@ impl Inventory {
|
|||
.or_else(|| {
|
||||
language.and_then(|l| l.config().debuggers.first().map(SharedString::from))
|
||||
});
|
||||
if let Some(adapter) = adapter {
|
||||
adapter.map(|adapter| (adapter, DapRegistry::global(cx).locators()))
|
||||
});
|
||||
cx.background_spawn(async move {
|
||||
if let Some((adapter, locators)) = adapter {
|
||||
for (kind, task) in
|
||||
lsp_tasks
|
||||
.into_iter()
|
||||
|
@ -299,28 +306,21 @@ impl Inventory {
|
|||
|| !matches!(kind, TaskSourceKind::Language { .. })
|
||||
}))
|
||||
{
|
||||
if let Some(scenario) =
|
||||
DapRegistry::global(cx)
|
||||
.locators()
|
||||
.values()
|
||||
.find_map(|locator| {
|
||||
locator.create_scenario(
|
||||
&task.original_task().clone(),
|
||||
&task.display_label(),
|
||||
adapter.clone().into(),
|
||||
)
|
||||
})
|
||||
{
|
||||
scenarios.push((kind, scenario));
|
||||
let adapter = adapter.clone().into();
|
||||
|
||||
for locator in locators.values() {
|
||||
if let Some(scenario) = locator
|
||||
.create_scenario(&task.original_task(), &task.display_label(), &adapter)
|
||||
.await
|
||||
{
|
||||
scenarios.push((kind, scenario));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(
|
||||
self.last_scheduled_scenarios.iter().cloned().collect(),
|
||||
scenarios,
|
||||
)
|
||||
(last_scheduled_scenarios, scenarios)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn task_template_by_label(
|
||||
|
@ -1275,7 +1275,7 @@ mod tests {
|
|||
init_test(cx);
|
||||
let fs = FakeFs::new(cx.executor());
|
||||
let inventory = cx.update(|cx| Inventory::new(fs, cx));
|
||||
inventory.update(cx, |inventory, cx| {
|
||||
inventory.update(cx, |inventory, _| {
|
||||
inventory
|
||||
.update_file_based_scenarios(
|
||||
TaskSettingsLocation::Global(Path::new("")),
|
||||
|
@ -1291,31 +1291,40 @@ mod tests {
|
|||
),
|
||||
)
|
||||
.unwrap();
|
||||
});
|
||||
|
||||
let (_, scenario) = inventory
|
||||
.list_debug_scenarios(&TaskContexts::default(), vec![], vec![], false, cx)
|
||||
.1
|
||||
let (_, scenario) = inventory
|
||||
.update(cx, |this, cx| {
|
||||
this.list_debug_scenarios(&TaskContexts::default(), vec![], vec![], false, cx)
|
||||
})
|
||||
.await
|
||||
.1
|
||||
.first()
|
||||
.unwrap()
|
||||
.clone();
|
||||
|
||||
inventory.update(cx, |this, _| {
|
||||
this.scenario_scheduled(scenario.clone());
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
inventory
|
||||
.update(cx, |this, cx| {
|
||||
this.list_debug_scenarios(&TaskContexts::default(), vec![], vec![], false, cx)
|
||||
})
|
||||
.await
|
||||
.0
|
||||
.first()
|
||||
.unwrap()
|
||||
.clone();
|
||||
.clone(),
|
||||
scenario
|
||||
);
|
||||
|
||||
inventory.scenario_scheduled(scenario.clone());
|
||||
|
||||
assert_eq!(
|
||||
inventory
|
||||
.list_debug_scenarios(&TaskContexts::default(), vec![], vec![], false, cx)
|
||||
.0
|
||||
.first()
|
||||
.unwrap()
|
||||
.clone(),
|
||||
scenario
|
||||
);
|
||||
|
||||
inventory
|
||||
.update_file_based_scenarios(
|
||||
TaskSettingsLocation::Global(Path::new("")),
|
||||
Some(
|
||||
r#"
|
||||
inventory.update(cx, |this, _| {
|
||||
this.update_file_based_scenarios(
|
||||
TaskSettingsLocation::Global(Path::new("")),
|
||||
Some(
|
||||
r#"
|
||||
[{
|
||||
"label": "test scenario",
|
||||
"adapter": "Delve",
|
||||
|
@ -1323,25 +1332,29 @@ mod tests {
|
|||
"program": "wowzer",
|
||||
}]
|
||||
"#,
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
inventory
|
||||
.list_debug_scenarios(&TaskContexts::default(), vec![], vec![], false, cx)
|
||||
.0
|
||||
.first()
|
||||
.unwrap()
|
||||
.adapter,
|
||||
"Delve",
|
||||
);
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
inventory
|
||||
.update_file_based_scenarios(
|
||||
TaskSettingsLocation::Global(Path::new("")),
|
||||
Some(
|
||||
r#"
|
||||
.update(cx, |this, cx| {
|
||||
this.list_debug_scenarios(&TaskContexts::default(), vec![], vec![], false, cx)
|
||||
})
|
||||
.await
|
||||
.0
|
||||
.first()
|
||||
.unwrap()
|
||||
.adapter,
|
||||
"Delve",
|
||||
);
|
||||
|
||||
inventory.update(cx, |this, _| {
|
||||
this.update_file_based_scenarios(
|
||||
TaskSettingsLocation::Global(Path::new("")),
|
||||
Some(
|
||||
r#"
|
||||
[{
|
||||
"label": "testing scenario",
|
||||
"adapter": "Delve",
|
||||
|
@ -1349,18 +1362,21 @@ mod tests {
|
|||
"program": "wowzer",
|
||||
}]
|
||||
"#,
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
inventory
|
||||
.list_debug_scenarios(&TaskContexts::default(), vec![], vec![], false, cx)
|
||||
.0
|
||||
.first(),
|
||||
None
|
||||
);
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
inventory
|
||||
.update(cx, |this, cx| {
|
||||
this.list_debug_scenarios(&TaskContexts::default(), vec![], vec![], false, cx)
|
||||
})
|
||||
.await
|
||||
.0
|
||||
.first(),
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue