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 @@
use crate::{
ExtensionLibraryKind, ExtensionManifest, GrammarManifestEntry, parse_wasm_extension_version,
};
use anyhow::{Context as _, Result, bail, ensure};
use anyhow::{Context as _, Result, bail};
use async_compression::futures::bufread::GzipDecoder;
use async_tar::Archive;
use futures::io::BufReader;
@ -98,21 +98,20 @@ impl ExtensionBuilder {
log::info!("compiled Rust extension {}", extension_dir.display());
}
let debug_adapters_dir = extension_dir.join("debug_adapter_schemas");
if !extension_manifest.debug_adapters.is_empty() {
ensure!(
debug_adapters_dir.exists(),
"Expected debug adapter schemas directory to exist"
);
}
for debug_adapter_name in &extension_manifest.debug_adapters {
let debug_adapter_schema_path = debug_adapters_dir.join(debug_adapter_name.as_ref());
for (debug_adapter_name, meta) in &mut extension_manifest.debug_adapters {
let debug_adapter_relative_schema_path =
meta.schema_path.clone().unwrap_or_else(|| {
Path::new("debug_adapter_schemas")
.join(Path::new(debug_adapter_name.as_ref()).with_extension("json"))
});
let debug_adapter_schema_path = extension_dir.join(debug_adapter_relative_schema_path);
let debug_adapter_schema = fs::read_to_string(&debug_adapter_schema_path)
.with_context(|| {
format!("failed to read debug adapter schema for `{debug_adapter_name}`")
format!("failed to read debug adapter schema for `{debug_adapter_name}` from `{debug_adapter_schema_path:?}`")
})?;
_ = serde_json::Value::from_str(&debug_adapter_schema).with_context(|| {
format!("Debug adapter schema for `{debug_adapter_name}` is not a valid JSON")
format!("Debug adapter schema for `{debug_adapter_name}` (path: `{debug_adapter_schema_path:?}`) is not a valid JSON")
})?;
}
for (grammar_name, grammar_metadata) in &extension_manifest.grammars {

View file

@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use anyhow::Result;
@ -411,17 +411,29 @@ impl ExtensionIndexedDocsProviderProxy for ExtensionHostProxy {
}
pub trait ExtensionDebugAdapterProviderProxy: Send + Sync + 'static {
fn register_debug_adapter(&self, extension: Arc<dyn Extension>, debug_adapter_name: Arc<str>);
fn register_debug_adapter(
&self,
extension: Arc<dyn Extension>,
debug_adapter_name: Arc<str>,
schema_path: &Path,
);
fn register_debug_locator(&self, extension: Arc<dyn Extension>, locator_name: Arc<str>);
fn unregister_debug_adapter(&self, debug_adapter_name: Arc<str>);
fn unregister_debug_locator(&self, locator_name: Arc<str>);
}
impl ExtensionDebugAdapterProviderProxy for ExtensionHostProxy {
fn register_debug_adapter(&self, extension: Arc<dyn Extension>, debug_adapter_name: Arc<str>) {
fn register_debug_adapter(
&self,
extension: Arc<dyn Extension>,
debug_adapter_name: Arc<str>,
schema_path: &Path,
) {
let Some(proxy) = self.debug_adapter_provider_proxy.read().clone() else {
return;
};
proxy.register_debug_adapter(extension, debug_adapter_name)
proxy.register_debug_adapter(extension, debug_adapter_name, schema_path)
}
fn register_debug_locator(&self, extension: Arc<dyn Extension>, locator_name: Arc<str>) {
@ -431,4 +443,18 @@ impl ExtensionDebugAdapterProviderProxy for ExtensionHostProxy {
proxy.register_debug_locator(extension, locator_name)
}
fn unregister_debug_adapter(&self, debug_adapter_name: Arc<str>) {
let Some(proxy) = self.debug_adapter_provider_proxy.read().clone() else {
return;
};
proxy.unregister_debug_adapter(debug_adapter_name)
}
fn unregister_debug_locator(&self, locator_name: Arc<str>) {
let Some(proxy) = self.debug_adapter_provider_proxy.read().clone() else {
return;
};
proxy.unregister_debug_locator(locator_name)
}
}

View file

@ -88,9 +88,9 @@ pub struct ExtensionManifest {
#[serde(default)]
pub capabilities: Vec<ExtensionCapability>,
#[serde(default)]
pub debug_adapters: Vec<Arc<str>>,
pub debug_adapters: BTreeMap<Arc<str>, DebugAdapterManifestEntry>,
#[serde(default)]
pub debug_locators: Vec<Arc<str>>,
pub debug_locators: BTreeMap<Arc<str>, DebugLocatorManifestEntry>,
}
impl ExtensionManifest {
@ -210,6 +210,14 @@ pub struct SlashCommandManifestEntry {
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
pub struct IndexedDocsProviderEntry {}
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
pub struct DebugAdapterManifestEntry {
pub schema_path: Option<PathBuf>,
}
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
pub struct DebugLocatorManifestEntry {}
impl ExtensionManifest {
pub async fn load(fs: Arc<dyn Fs>, extension_dir: &Path) -> Result<Self> {
let extension_name = extension_dir
@ -278,8 +286,8 @@ fn manifest_from_old_manifest(
indexed_docs_providers: BTreeMap::default(),
snippets: None,
capabilities: Vec::new(),
debug_adapters: vec![],
debug_locators: vec![],
debug_adapters: Default::default(),
debug_locators: Default::default(),
}
}