extensions: Yet another PR for debugger touchups (#32822)

We'll now clean up DAP locators for unloaded extensions and load schemas
proper

I can now load a custom Ruby extensions with all bells and whistles and
use it as my debugger.

Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2025-06-17 09:34:55 +02:00 committed by GitHub
parent d92d52b508
commit 0e794fa0ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 262 additions and 45 deletions

View file

@ -1,7 +1,7 @@
mod extension_dap_adapter;
mod extension_locator_adapter;
use std::sync::Arc;
use std::{path::Path, sync::Arc};
use dap::DapRegistry;
use extension::{ExtensionDebugAdapterProviderProxy, ExtensionHostProxy};
@ -34,8 +34,11 @@ impl ExtensionDebugAdapterProviderProxy for DebugAdapterRegistryProxy {
&self,
extension: Arc<dyn extension::Extension>,
debug_adapter_name: Arc<str>,
schema_path: &Path,
) {
if let Some(adapter) = ExtensionDapAdapter::new(extension, debug_adapter_name).log_err() {
if let Some(adapter) =
ExtensionDapAdapter::new(extension, debug_adapter_name, schema_path).log_err()
{
self.debug_adapter_registry.add_adapter(Arc::new(adapter));
}
}
@ -51,4 +54,13 @@ impl ExtensionDebugAdapterProviderProxy for DebugAdapterRegistryProxy {
locator_name,
)));
}
fn unregister_debug_adapter(&self, debug_adapter_name: Arc<str>) {
self.debug_adapter_registry
.remove_adapter(&debug_adapter_name);
}
fn unregister_debug_locator(&self, locator_name: Arc<str>) {
self.debug_adapter_registry.remove_locator(&locator_name);
}
}

View file

@ -26,11 +26,13 @@ impl ExtensionDapAdapter {
pub(crate) fn new(
extension: Arc<dyn extension::Extension>,
debug_adapter_name: Arc<str>,
schema_path: &Path,
) -> Result<Self> {
let schema = std::fs::read_to_string(extension.path_from_extension(
&Path::new("debug_adapter_schemas").join(debug_adapter_name.as_ref()),
))
.with_context(|| format!("Failed to read debug adapter schema for {debug_adapter_name}"))?;
let schema = std::fs::read_to_string(&schema_path).with_context(|| {
format!(
"Failed to read debug adapter schema for {debug_adapter_name} (from path: `{schema_path:?}`)"
)
})?;
let schema = serde_json::Value::from_str(&schema).with_context(|| {
format!("Debug adapter schema for {debug_adapter_name} is not a valid JSON")
})?;