debugger: Fix DebugAdapterDelegate::worktree_root always using the first visible worktree (#32585)

Closes #32577

Release Notes:

- Fixed debugger malfunctioning when using ZED_WORKTREE_ROOT env
variable in multi-worktree workspaces.
This commit is contained in:
Piotr Osiewicz 2025-06-12 01:40:41 +02:00 committed by GitHub
parent 1083c0ac53
commit 04223f304b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 45 additions and 15 deletions

View file

@ -180,15 +180,12 @@ impl DapStore {
&mut self,
definition: DebugTaskDefinition,
session_id: SessionId,
worktree: &Entity<Worktree>,
console: UnboundedSender<String>,
cx: &mut Context<Self>,
) -> Task<Result<DebugAdapterBinary>> {
match &self.mode {
DapStoreMode::Local(_) => {
let Some(worktree) = self.worktree_store.read(cx).visible_worktrees(cx).next()
else {
return Task::ready(Err(anyhow!("Failed to find a worktree")));
};
let Some(adapter) = DapRegistry::global(cx).adapter(&definition.adapter) else {
return Task::ready(Err(anyhow!("Failed to find a debug adapter")));
};
@ -229,6 +226,7 @@ impl DapStore {
let request = ssh.upstream_client.request(proto::GetDebugAdapterBinary {
session_id: session_id.to_proto(),
project_id: ssh.upstream_project_id,
worktree_id: worktree.read(cx).id().to_proto(),
definition: Some(definition.to_proto()),
});
let ssh_client = ssh.ssh_client.clone();
@ -401,12 +399,9 @@ impl DapStore {
&self,
session: Entity<Session>,
definition: DebugTaskDefinition,
worktree: Entity<Worktree>,
cx: &mut Context<Self>,
) -> Task<Result<()>> {
let Some(worktree) = self.worktree_store.read(cx).visible_worktrees(cx).next() else {
return Task::ready(Err(anyhow!("Failed to find a worktree")));
};
let dap_store = cx.weak_entity();
let console = session.update(cx, |session, cx| session.console_output(cx));
let session_id = session.read(cx).session_id();
@ -416,7 +411,13 @@ impl DapStore {
async move |this, cx| {
let binary = this
.update(cx, |this, cx| {
this.get_debug_adapter_binary(definition.clone(), session_id, console, cx)
this.get_debug_adapter_binary(
definition.clone(),
session_id,
&worktree,
console,
cx,
)
})?
.await?;
session
@ -780,9 +781,22 @@ impl DapStore {
})
.detach();
let worktree = this
.update(&mut cx, |this, cx| {
this.worktree_store
.read(cx)
.worktree_for_id(WorktreeId::from_proto(envelope.payload.worktree_id), cx)
})?
.context("Failed to find worktree with a given ID")?;
let binary = this
.update(&mut cx, |this, cx| {
this.get_debug_adapter_binary(definition, SessionId::from_proto(session_id), tx, cx)
this.get_debug_adapter_binary(
definition,
SessionId::from_proto(session_id),
&worktree,
tx,
cx,
)
})?
.await?;
Ok(binary.to_proto())