locator_store.rs

 1use anyhow::{Result, anyhow};
 2use cargo::CargoLocator;
 3use collections::HashMap;
 4use gpui::SharedString;
 5use locators::DapLocator;
 6use task::{DebugTaskDefinition, DebugTaskTemplate};
 7
 8mod cargo;
 9pub mod locators;
10
11pub(super) struct LocatorStore {
12    locators: HashMap<SharedString, Box<dyn DapLocator>>,
13}
14
15impl LocatorStore {
16    pub(super) fn new() -> Self {
17        Self { locators }
18    }
19
20    pub(super) async fn resolve_debug_config(
21        &self,
22        template: DebugTaskTemplate,
23    ) -> Result<DebugTaskDefinition> {
24        let Some(locator_name) = &template.locator else {
25            return Ok(template.definition);
26        };
27
28        if let Some(locator) = self.locators.get(locator_name as &str) {
29            locator.run_locator(template.definition).await
30        } else {
31            Err(anyhow!("Couldn't find locator {}", locator_name))
32        }
33    }
34}