debugger: Add extensions support (#30625)
Closes #ISSUE Release Notes: - N/A --------- Co-authored-by: Anthony <anthony@zed.dev>
This commit is contained in:
parent
6fc9036063
commit
9826b7b5c1
21 changed files with 402 additions and 13 deletions
20
crates/debug_adapter_extension/Cargo.toml
Normal file
20
crates/debug_adapter_extension/Cargo.toml
Normal file
|
@ -0,0 +1,20 @@
|
|||
[package]
|
||||
name = "debug_adapter_extension"
|
||||
version = "0.1.0"
|
||||
license = "GPL-3.0-or-later"
|
||||
publish.workspace = true
|
||||
edition.workspace = true
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
async-trait.workspace = true
|
||||
dap.workspace = true
|
||||
extension.workspace = true
|
||||
gpui.workspace = true
|
||||
workspace-hack = { version = "0.1", path = "../../tooling/workspace-hack" }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[lib]
|
||||
path = "src/debug_adapter_extension.rs"
|
1
crates/debug_adapter_extension/LICENSE-GPL
Symbolic link
1
crates/debug_adapter_extension/LICENSE-GPL
Symbolic link
|
@ -0,0 +1 @@
|
|||
../../LICENSE-GPL
|
|
@ -0,0 +1,40 @@
|
|||
mod extension_dap_adapter;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use dap::DapRegistry;
|
||||
use extension::{ExtensionDebugAdapterProviderProxy, ExtensionHostProxy};
|
||||
use extension_dap_adapter::ExtensionDapAdapter;
|
||||
use gpui::App;
|
||||
|
||||
pub fn init(extension_host_proxy: Arc<ExtensionHostProxy>, cx: &mut App) {
|
||||
let language_server_registry_proxy = DebugAdapterRegistryProxy::new(cx);
|
||||
extension_host_proxy.register_debug_adapter_proxy(language_server_registry_proxy);
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct DebugAdapterRegistryProxy {
|
||||
debug_adapter_registry: DapRegistry,
|
||||
}
|
||||
|
||||
impl DebugAdapterRegistryProxy {
|
||||
fn new(cx: &mut App) -> Self {
|
||||
Self {
|
||||
debug_adapter_registry: DapRegistry::global(cx).clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ExtensionDebugAdapterProviderProxy for DebugAdapterRegistryProxy {
|
||||
fn register_debug_adapter(
|
||||
&self,
|
||||
extension: Arc<dyn extension::Extension>,
|
||||
debug_adapter_name: Arc<str>,
|
||||
) {
|
||||
self.debug_adapter_registry
|
||||
.add_adapter(Arc::new(ExtensionDapAdapter::new(
|
||||
extension,
|
||||
debug_adapter_name,
|
||||
)));
|
||||
}
|
||||
}
|
49
crates/debug_adapter_extension/src/extension_dap_adapter.rs
Normal file
49
crates/debug_adapter_extension/src/extension_dap_adapter.rs
Normal file
|
@ -0,0 +1,49 @@
|
|||
use std::{path::PathBuf, sync::Arc};
|
||||
|
||||
use anyhow::Result;
|
||||
use async_trait::async_trait;
|
||||
use dap::adapters::{
|
||||
DapDelegate, DebugAdapter, DebugAdapterBinary, DebugAdapterName, DebugTaskDefinition,
|
||||
};
|
||||
use extension::Extension;
|
||||
use gpui::AsyncApp;
|
||||
|
||||
pub(crate) struct ExtensionDapAdapter {
|
||||
extension: Arc<dyn Extension>,
|
||||
debug_adapter_name: Arc<str>,
|
||||
}
|
||||
|
||||
impl ExtensionDapAdapter {
|
||||
pub(crate) fn new(
|
||||
extension: Arc<dyn extension::Extension>,
|
||||
debug_adapter_name: Arc<str>,
|
||||
) -> Self {
|
||||
Self {
|
||||
extension,
|
||||
debug_adapter_name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait(?Send)]
|
||||
impl DebugAdapter for ExtensionDapAdapter {
|
||||
fn name(&self) -> DebugAdapterName {
|
||||
self.debug_adapter_name.as_ref().into()
|
||||
}
|
||||
|
||||
async fn get_binary(
|
||||
&self,
|
||||
_: &dyn DapDelegate,
|
||||
config: &DebugTaskDefinition,
|
||||
user_installed_path: Option<PathBuf>,
|
||||
_cx: &mut AsyncApp,
|
||||
) -> Result<DebugAdapterBinary> {
|
||||
self.extension
|
||||
.get_dap_binary(
|
||||
self.debug_adapter_name.clone(),
|
||||
config.clone(),
|
||||
user_installed_path,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue