From e34fee55a05e6ceb928b7d57f84c51cdd4fd323a Mon Sep 17 00:00:00 2001 From: Anthony Eid <56899983+Anthony-Eid@users.noreply.github.com> Date: Tue, 15 Apr 2025 17:10:06 -0400 Subject: [PATCH] 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 Release Notes: - N/A --------- Co-authored-by: piotr --- crates/project/src/debugger/dap_store.rs | 30 ++++++++-------- .../src/debugger/locator_store/cargo.rs | 35 ++----------------- crates/project/src/project.rs | 12 +++++++ 3 files changed, 30 insertions(+), 47 deletions(-) diff --git a/crates/project/src/debugger/dap_store.rs b/crates/project/src/debugger/dap_store.rs index d0891bd30a..dce63fa4c0 100644 --- a/crates/project/src/debugger/dap_store.rs +++ b/crates/project/src/debugger/dap_store.rs @@ -21,7 +21,10 @@ use futures::{ channel::{mpsc, oneshot}, 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 language::{BinaryStatus, LanguageRegistry, LanguageToolchainStore}; use lsp::LanguageServerName; @@ -90,6 +93,17 @@ impl LocalDapStore { fn next_session_id(&self) -> SessionId { SessionId(self.next_session_id.fetch_add(1, SeqCst)) } + pub(crate) fn locate_binary( + &self, + mut definition: DebugTaskDefinition, + executor: BackgroundExecutor, + ) -> Task { + let locator_store = self.locator_store.clone(); + executor.spawn(async move { + let _ = locator_store.resolve_debug_config(&mut definition).await; + definition + }) + } } pub struct RemoteDapStore { @@ -335,7 +349,7 @@ impl DapStore { pub fn new_session( &mut self, binary: DebugAdapterBinary, - mut config: DebugTaskDefinition, + config: DebugTaskDefinition, parent_session: Option>, cx: &mut Context, ) -> (SessionId, Task>>) { @@ -352,22 +366,10 @@ impl DapStore { } 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 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| { Session::local( this.breakpoint_store.clone(), diff --git a/crates/project/src/debugger/locator_store/cargo.rs b/crates/project/src/debugger/locator_store/cargo.rs index ee7a60337e..e6e65c506d 100644 --- a/crates/project/src/debugger/locator_store/cargo.rs +++ b/crates/project/src/debugger/locator_store/cargo.rs @@ -1,13 +1,12 @@ use super::DapLocator; use anyhow::{Result, anyhow}; use async_trait::async_trait; -use serde_json::{Value, json}; +use serde_json::Value; use smol::{ io::AsyncReadExt, process::{Command, Stdio}, }; use task::DebugTaskDefinition; -use util::maybe; pub(super) struct CargoLocator; @@ -109,43 +108,13 @@ impl DapLocator for CargoLocator { None } }; + let Some(executable) = executable.or_else(|| executables.first().cloned()) else { return Err(anyhow!("Couldn't get executable in cargo locator")); }; 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(); if let Some(test_name) = test_name { launch_config.args.push(test_name); diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 083dcfe8a2..e1d4010576 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -1482,6 +1482,18 @@ impl Project { .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 .get_binary(&delegate, &config, user_installed_path, cx) .await?;