locator_store.rs

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