@@ -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(),
@@ -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);
@@ -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?;