debugger: Fix Rust debugger runnable (#28801)

We ran the locator after configuring the debugger binary which cause the
binary to never use the configuration from the cargo locator. This PR
fixes this by correcting the order of configuration.


co-authored-by Anthony Eid <anthony@zed.dev>

Release Notes:

- N/A

---------

Co-authored-by: piotr <piotr@zed.dev>
This commit is contained in:
Anthony Eid 2025-04-15 17:10:06 -04:00 committed by GitHub
parent dad6067e18
commit e34fee55a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 30 additions and 47 deletions

View file

@ -21,7 +21,10 @@ use futures::{
channel::{mpsc, oneshot}, channel::{mpsc, oneshot},
future::{Shared, join_all}, future::{Shared, join_all},
}; };
use gpui::{App, AppContext, AsyncApp, Context, Entity, EventEmitter, SharedString, Task}; use gpui::{
App, AppContext, AsyncApp, BackgroundExecutor, Context, Entity, EventEmitter, SharedString,
Task,
};
use http_client::HttpClient; use http_client::HttpClient;
use language::{BinaryStatus, LanguageRegistry, LanguageToolchainStore}; use language::{BinaryStatus, LanguageRegistry, LanguageToolchainStore};
use lsp::LanguageServerName; use lsp::LanguageServerName;
@ -90,6 +93,17 @@ impl LocalDapStore {
fn next_session_id(&self) -> SessionId { fn next_session_id(&self) -> SessionId {
SessionId(self.next_session_id.fetch_add(1, SeqCst)) SessionId(self.next_session_id.fetch_add(1, SeqCst))
} }
pub(crate) fn locate_binary(
&self,
mut definition: DebugTaskDefinition,
executor: BackgroundExecutor,
) -> Task<DebugTaskDefinition> {
let locator_store = self.locator_store.clone();
executor.spawn(async move {
let _ = locator_store.resolve_debug_config(&mut definition).await;
definition
})
}
} }
pub struct RemoteDapStore { pub struct RemoteDapStore {
@ -335,7 +349,7 @@ impl DapStore {
pub fn new_session( pub fn new_session(
&mut self, &mut self,
binary: DebugAdapterBinary, binary: DebugAdapterBinary,
mut config: DebugTaskDefinition, config: DebugTaskDefinition,
parent_session: Option<Entity<Session>>, parent_session: Option<Entity<Session>>,
cx: &mut Context<Self>, cx: &mut Context<Self>,
) -> (SessionId, Task<Result<Entity<Session>>>) { ) -> (SessionId, Task<Result<Entity<Session>>>) {
@ -352,22 +366,10 @@ impl DapStore {
} }
let (initialized_tx, initialized_rx) = oneshot::channel(); let (initialized_tx, initialized_rx) = oneshot::channel();
let locator_store = local_store.locator_store.clone();
let start_debugging_tx = local_store.start_debugging_tx.clone(); let start_debugging_tx = local_store.start_debugging_tx.clone();
let task = cx.spawn(async move |this, cx| { let task = cx.spawn(async move |this, cx| {
if config.locator.is_some() {
config = cx
.background_spawn(async move {
locator_store
.resolve_debug_config(&mut config)
.await
.map(|_| config)
})
.await?;
}
let start_client_task = this.update(cx, |this, cx| { let start_client_task = this.update(cx, |this, cx| {
Session::local( Session::local(
this.breakpoint_store.clone(), this.breakpoint_store.clone(),

View file

@ -1,13 +1,12 @@
use super::DapLocator; use super::DapLocator;
use anyhow::{Result, anyhow}; use anyhow::{Result, anyhow};
use async_trait::async_trait; use async_trait::async_trait;
use serde_json::{Value, json}; use serde_json::Value;
use smol::{ use smol::{
io::AsyncReadExt, io::AsyncReadExt,
process::{Command, Stdio}, process::{Command, Stdio},
}; };
use task::DebugTaskDefinition; use task::DebugTaskDefinition;
use util::maybe;
pub(super) struct CargoLocator; pub(super) struct CargoLocator;
@ -109,43 +108,13 @@ impl DapLocator for CargoLocator {
None None
} }
}; };
let Some(executable) = executable.or_else(|| executables.first().cloned()) else { let Some(executable) = executable.or_else(|| executables.first().cloned()) else {
return Err(anyhow!("Couldn't get executable in cargo locator")); return Err(anyhow!("Couldn't get executable in cargo locator"));
}; };
launch_config.program = executable; launch_config.program = executable;
if debug_config.adapter == "LLDB" && debug_config.initialize_args.is_none() {
// Find Rust pretty-printers in current toolchain's sysroot
let cwd = launch_config.cwd.clone();
debug_config.initialize_args = maybe!(async move {
let cwd = cwd?;
let output = Command::new("rustc")
.arg("--print")
.arg("sysroot")
.current_dir(cwd)
.output()
.await
.ok()?;
if !output.status.success() {
return None;
}
let sysroot_path = String::from_utf8(output.stdout).ok()?;
let sysroot_path = sysroot_path.trim_end();
let first_command = format!(
r#"command script import "{sysroot_path}/lib/rustlib/etc/lldb_lookup.py"#
);
let second_command =
format!(r#"command source -s 0 '{sysroot_path}/lib/rustlib/etc/lldb_commands"#);
Some(json!({"initCommands": [first_command, second_command]}))
})
.await;
}
launch_config.args.clear(); launch_config.args.clear();
if let Some(test_name) = test_name { if let Some(test_name) = test_name {
launch_config.args.push(test_name); launch_config.args.push(test_name);

View file

@ -1482,6 +1482,18 @@ impl Project {
.update(cx, |dap_store, cx| dap_store.delegate(&worktree, cx)) .update(cx, |dap_store, cx| dap_store.delegate(&worktree, cx))
})?; })?;
let task = this.update(cx, |project, cx| {
project.dap_store.read(cx).as_local().and_then(|local| {
config.locator.is_some().then(|| {
local.locate_binary(config.clone(), cx.background_executor().clone())
})
})
})?;
let config = if let Some(task) = task {
task.await
} else {
config
};
let binary = adapter let binary = adapter
.get_binary(&delegate, &config, user_installed_path, cx) .get_binary(&delegate, &config, user_installed_path, cx)
.await?; .await?;