on master help sign in
Use which to resolve lsp/dap binaries

This resolves the following issue: https://github.com/helix-editor/helix/discussions/962#discussioncomment-1580046

commit9712bbb23b19a957aaba9080ec5ee5f3134e526e authorBlaž Hrastnik <blaz@mxxn.io> dateThu 24 Feb 2022, 11:38 (5 years ago) parent4526216
6 files changed+12−21
Cargo.lock+2 helix-dap/Cargo.toml+1 helix-dap/src/client.rs+3 helix-lsp/Cargo.toml+1 helix-lsp/src/client.rs+3 helix-term/src/application.rs+2−21
Cargo.lock+2
@@ -393,6 +393,7 @@ dependencies = [
393393 "serde_json",
394394 "thiserror",
395395 "tokio",
396+ "which",
396397]
397398
398399[[package]]
@@ -411,6 +412,7 @@ dependencies = [
411412 "thiserror",
412413 "tokio",
413414 "tokio-stream",
415+ "which",
414416]
415417
416418[[package]]
helix-dap/Cargo.toml+1
@@ -19,6 +19,7 @@ serde = { version = "1.0", features = ["derive"] }
1919serde_json = "1.0"
2020thiserror = "1.0"
2121tokio = { version = "1", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot", "net", "sync"] }
22+which = "4.2"
2223
2324[dev-dependencies]
2425fern = "0.6"
helix-dap/src/client.rs+3
@@ -105,6 +105,9 @@ impl Client {
105105 args: Vec<&str>,
106106 id: usize,
107107 ) -> Result<(Self, UnboundedReceiver<Payload>)> {
108+ // Resolve path to the binary
109+ let cmd = which::which(cmd).map_err(|err| anyhow::anyhow!(err))?;
110+
108111 let process = Command::new(cmd)
109112 .args(args)
110113 .stdin(Stdio::piped())
helix-lsp/Cargo.toml+1
@@ -25,3 +25,4 @@ serde_json = "1.0"
2525thiserror = "1.0"
2626tokio = { version = "1.17", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot", "sync"] }
2727tokio-stream = "0.1.8"
28+which = "4.2"
helix-lsp/src/client.rs+3
@@ -43,6 +43,9 @@ impl Client {
4343 root_markers: Vec<String>,
4444 id: usize,
4545 ) -> Result<(Self, UnboundedReceiver<(usize, Call)>, Arc<Notify>)> {
46+ // Resolve path to the binary
47+ let cmd = which::which(cmd).map_err(|err| anyhow::anyhow!(err))?;
48+
4649 let process = Command::new(cmd)
4750 .args(args)
4851 .stdin(Stdio::piped())
helix-term/src/application.rs+2−21
@@ -479,32 +479,13 @@ impl Application {
479479 Payload::Response(_) => unreachable!(),
480480 Payload::Request(request) => match request.command.as_str() {
481481 RunInTerminal::COMMAND => {
482− let mut arguments: dap::requests::RunInTerminalArguments =
482+ let arguments: dap::requests::RunInTerminalArguments =
483483 serde_json::from_value(request.arguments.unwrap_or_default()).unwrap();
484484 // TODO: no unwrap
485485
486− log::error!("run_in_terminal {:?}", arguments);
487−
488− // HAXX: lldb-vscode uses $CWD/lldb-vscode which is wrong
489− let program = arguments.args[0]
490− .strip_prefix(
491− std::env::current_dir()
492− .expect("Couldn't get current working directory")
493− .as_path()
494− .to_str()
495− .unwrap(),
496− )
497− .and_then(|arg| arg.strip_prefix('/'))
498− .map(|arg| arg.to_owned())
499− .unwrap_or_else(|| arguments.args[0].clone());
500− arguments.args[0] = program;
501−
502− log::error!("{}", arguments.args.join(" "));
503−
504− // TODO: handle cwd
505486 let process = std::process::Command::new("tmux")
506487 .arg("split-window")
507− .arg(arguments.args.join(" ")) // TODO: first arg is wrong, it uses current dir
488+ .arg(arguments.args.join(" "))
508489 .spawn()
509490 .unwrap();
510491