debugger: Allow locators to generate full debug scenarios (#30014)

Closes #ISSUE

Release Notes:

- N/A

---------

Co-authored-by: Anthony <anthony@zed.dev>
Co-authored-by: Remco Smits <djsmits12@gmail.com>
This commit is contained in:
Piotr Osiewicz 2025-05-06 18:39:49 +02:00 committed by GitHub
parent a378b3f300
commit bbfcd885ab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 197 additions and 146 deletions

View file

@ -1,9 +1,9 @@
use anyhow::Result;
use async_trait::async_trait;
use collections::FxHashMap;
use gpui::{App, Global};
use gpui::{App, Global, SharedString};
use parking_lot::RwLock;
use task::{DebugRequest, SpawnInTerminal};
use task::{DebugRequest, DebugScenario, SpawnInTerminal, TaskTemplate};
use crate::adapters::{DebugAdapter, DebugAdapterName};
use std::{collections::BTreeMap, sync::Arc};
@ -11,15 +11,17 @@ use std::{collections::BTreeMap, sync::Arc};
/// Given a user build configuration, locator creates a fill-in debug target ([DebugRequest]) on behalf of the user.
#[async_trait]
pub trait DapLocator: Send + Sync {
fn name(&self) -> SharedString;
/// Determines whether this locator can generate debug target for given task.
fn accepts(&self, build_config: &SpawnInTerminal) -> bool;
fn create_scenario(&self, build_config: &TaskTemplate, adapter: &str) -> Option<DebugScenario>;
async fn run(&self, build_config: SpawnInTerminal) -> Result<DebugRequest>;
}
#[derive(Default)]
struct DapRegistryState {
adapters: BTreeMap<DebugAdapterName, Arc<dyn DebugAdapter>>,
locators: FxHashMap<String, Arc<dyn DapLocator>>,
locators: FxHashMap<SharedString, Arc<dyn DapLocator>>,
}
#[derive(Clone, Default)]
@ -48,15 +50,15 @@ impl DapRegistry {
);
}
pub fn add_locator(&self, name: String, locator: Arc<dyn DapLocator>) {
let _previous_value = self.0.write().locators.insert(name, locator);
pub fn add_locator(&self, locator: Arc<dyn DapLocator>) {
let _previous_value = self.0.write().locators.insert(locator.name(), locator);
debug_assert!(
_previous_value.is_none(),
"Attempted to insert a new debug locator when one is already registered"
);
}
pub fn locators(&self) -> FxHashMap<String, Arc<dyn DapLocator>> {
pub fn locators(&self) -> FxHashMap<SharedString, Arc<dyn DapLocator>> {
self.0.read().locators.clone()
}