Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
debugger: Fix Rust debugger runnable (#28801)
Anthony Eide34fee55a05e
diff --git a/crates/project/src/debugger/dap_store.rs b/crates/project/src/debugger/dap_store.rsindex d0891bd30ac..dce63fa4c0b 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<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 {@@ -335,7 +349,7 @@ impl DapStore {pub fn new_session(&mut self,binary: DebugAdapterBinary,- mut config: DebugTaskDefinition,+ config: DebugTaskDefinition,parent_session: Option<Entity<Session>>,cx: &mut Context<Self>,) -> (SessionId, Task<Result<Entity<Session>>>) {@@ -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.rsindex ee7a60337e0..e6e65c506d1 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.rsindex 083dcfe8a2f..e1d40105761 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?;