extension: Add debug_adapters to extension manifest (#30676)

Also pass worktree to the get_dap_binary.

Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2025-05-20 11:01:33 +02:00 committed by GitHub
parent b1c7fa1dac
commit a092e2dc03
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 147 additions and 59 deletions

View file

@ -10,13 +10,15 @@ use crate::{
terminals::{SshCommand, wrap_for_ssh},
worktree_store::WorktreeStore,
};
use anyhow::{Result, anyhow};
use anyhow::{Context as _, Result, anyhow};
use async_trait::async_trait;
use collections::HashMap;
use dap::{
Capabilities, CompletionItem, CompletionsArguments, DapRegistry, DebugRequest,
EvaluateArguments, EvaluateArgumentsContext, EvaluateResponse, Source, StackFrameId,
adapters::{DebugAdapterBinary, DebugAdapterName, DebugTaskDefinition, TcpArguments},
adapters::{
DapDelegate, DebugAdapterBinary, DebugAdapterName, DebugTaskDefinition, TcpArguments,
},
client::SessionId,
inline_value::VariableLookupKind,
messages::Message,
@ -488,14 +490,14 @@ impl DapStore {
worktree: &Entity<Worktree>,
console: UnboundedSender<String>,
cx: &mut App,
) -> DapAdapterDelegate {
) -> Arc<dyn DapDelegate> {
let Some(local_store) = self.as_local() else {
unimplemented!("Starting session on remote side");
};
DapAdapterDelegate::new(
Arc::new(DapAdapterDelegate::new(
local_store.fs.clone(),
worktree.read(cx).id(),
worktree.read(cx).snapshot(),
console,
local_store.node_runtime.clone(),
local_store.http_client.clone(),
@ -503,7 +505,7 @@ impl DapStore {
local_store.environment.update(cx, |env, cx| {
env.get_worktree_environment(worktree.clone(), cx)
}),
)
))
}
pub fn evaluate(
@ -811,7 +813,7 @@ impl DapStore {
pub struct DapAdapterDelegate {
fs: Arc<dyn Fs>,
console: mpsc::UnboundedSender<String>,
worktree_id: WorktreeId,
worktree: worktree::Snapshot,
node_runtime: NodeRuntime,
http_client: Arc<dyn HttpClient>,
toolchain_store: Arc<dyn LanguageToolchainStore>,
@ -821,7 +823,7 @@ pub struct DapAdapterDelegate {
impl DapAdapterDelegate {
pub fn new(
fs: Arc<dyn Fs>,
worktree_id: WorktreeId,
worktree: worktree::Snapshot,
status: mpsc::UnboundedSender<String>,
node_runtime: NodeRuntime,
http_client: Arc<dyn HttpClient>,
@ -831,7 +833,7 @@ impl DapAdapterDelegate {
Self {
fs,
console: status,
worktree_id,
worktree,
http_client,
node_runtime,
toolchain_store,
@ -840,12 +842,15 @@ impl DapAdapterDelegate {
}
}
#[async_trait(?Send)]
#[async_trait]
impl dap::adapters::DapDelegate for DapAdapterDelegate {
fn worktree_id(&self) -> WorktreeId {
self.worktree_id
self.worktree.id()
}
fn worktree_root_path(&self) -> &Path {
&self.worktree.abs_path()
}
fn http_client(&self) -> Arc<dyn HttpClient> {
self.http_client.clone()
}
@ -862,7 +867,7 @@ impl dap::adapters::DapDelegate for DapAdapterDelegate {
self.console.unbounded_send(msg).ok();
}
fn which(&self, command: &OsStr) -> Option<PathBuf> {
async fn which(&self, command: &OsStr) -> Option<PathBuf> {
which::which(command).ok()
}
@ -874,4 +879,16 @@ impl dap::adapters::DapDelegate for DapAdapterDelegate {
fn toolchain_store(&self) -> Arc<dyn LanguageToolchainStore> {
self.toolchain_store.clone()
}
async fn read_text_file(&self, path: PathBuf) -> Result<String> {
let entry = self
.worktree
.entry_for_path(&path)
.with_context(|| format!("no worktree entry for path {path:?}"))?;
let abs_path = self
.worktree
.absolutize(&entry.path)
.with_context(|| format!("cannot absolutize path {path:?}"))?;
self.fs.load(&abs_path).await
}
}