1use anyhow::Result;
2use async_trait::async_trait;
3use dap::{DapLocator, DebugRequest, adapters::DebugAdapterName};
4use extension::Extension;
5use gpui::SharedString;
6use std::sync::Arc;
7use task::{DebugScenario, SpawnInTerminal, TaskTemplate};
8
9pub(crate) struct ExtensionLocatorAdapter {
10 extension: Arc<dyn Extension>,
11 locator_name: SharedString,
12}
13
14impl ExtensionLocatorAdapter {
15 pub(crate) fn new(extension: Arc<dyn extension::Extension>, locator_name: Arc<str>) -> Self {
16 Self {
17 extension,
18 locator_name: SharedString::from(locator_name),
19 }
20 }
21}
22
23#[async_trait]
24impl DapLocator for ExtensionLocatorAdapter {
25 fn name(&self) -> SharedString {
26 self.locator_name.clone()
27 }
28 /// Determines whether this locator can generate debug target for given task.
29 async fn create_scenario(
30 &self,
31 build_config: &TaskTemplate,
32 resolved_label: &str,
33 adapter: &DebugAdapterName,
34 ) -> Option<DebugScenario> {
35 self.extension
36 .dap_locator_create_scenario(
37 self.locator_name.as_ref().to_owned(),
38 build_config.clone(),
39 resolved_label.to_owned(),
40 adapter.0.as_ref().to_owned(),
41 )
42 .await
43 .ok()
44 .flatten()
45 }
46
47 async fn run(&self, build_config: SpawnInTerminal) -> Result<DebugRequest> {
48 self.extension
49 .run_dap_locator(self.locator_name.as_ref().to_owned(), build_config)
50 .await
51 }
52}