aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlaž Hrastnik2022-02-24 02:38:40 +0000
committerBlaž Hrastnik2022-02-24 02:38:40 +0000
commit9712bbb23b19a957aaba9080ec5ee5f3134e526e (patch)
tree1c0e76ce980651f4690d325f922786347c42cc89
parent45262161392fde814cf0da54d268d8f75366a4ee (diff)
Use which to resolve lsp/dap binaries
This resolves the following issue: https://github.com/helix-editor/helix/discussions/962#discussioncomment-1580046
-rw-r--r--Cargo.lock2
-rw-r--r--helix-dap/Cargo.toml1
-rw-r--r--helix-dap/src/client.rs3
-rw-r--r--helix-lsp/Cargo.toml1
-rw-r--r--helix-lsp/src/client.rs3
-rw-r--r--helix-term/src/application.rs23
6 files changed, 12 insertions, 21 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 306740bd..4446a99f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -393,6 +393,7 @@ dependencies = [
"serde_json",
"thiserror",
"tokio",
+ "which",
]
[[package]]
@@ -411,6 +412,7 @@ dependencies = [
"thiserror",
"tokio",
"tokio-stream",
+ "which",
]
[[package]]
diff --git a/helix-dap/Cargo.toml b/helix-dap/Cargo.toml
index 24288697..95a05905 100644
--- a/helix-dap/Cargo.toml
+++ b/helix-dap/Cargo.toml
@@ -19,6 +19,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0"
tokio = { version = "1", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot", "net", "sync"] }
+which = "4.2"
[dev-dependencies]
fern = "0.6"
diff --git a/helix-dap/src/client.rs b/helix-dap/src/client.rs
index 56254429..9498c64c 100644
--- a/helix-dap/src/client.rs
+++ b/helix-dap/src/client.rs
@@ -105,6 +105,9 @@ impl Client {
args: Vec<&str>,
id: usize,
) -> Result<(Self, UnboundedReceiver<Payload>)> {
+ // Resolve path to the binary
+ let cmd = which::which(cmd).map_err(|err| anyhow::anyhow!(err))?;
+
let process = Command::new(cmd)
.args(args)
.stdin(Stdio::piped())
diff --git a/helix-lsp/Cargo.toml b/helix-lsp/Cargo.toml
index 1a704125..755f49b5 100644
--- a/helix-lsp/Cargo.toml
+++ b/helix-lsp/Cargo.toml
@@ -25,3 +25,4 @@ serde_json = "1.0"
thiserror = "1.0"
tokio = { version = "1.17", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot", "sync"] }
tokio-stream = "0.1.8"
+which = "4.2"
diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs
index 15cbca0e..362498cb 100644
--- a/helix-lsp/src/client.rs
+++ b/helix-lsp/src/client.rs
@@ -43,6 +43,9 @@ impl Client {
root_markers: Vec<String>,
id: usize,
) -> Result<(Self, UnboundedReceiver<(usize, Call)>, Arc<Notify>)> {
+ // Resolve path to the binary
+ let cmd = which::which(cmd).map_err(|err| anyhow::anyhow!(err))?;
+
let process = Command::new(cmd)
.args(args)
.stdin(Stdio::piped())
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index db289f57..986df703 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -479,32 +479,13 @@ impl Application {
Payload::Response(_) => unreachable!(),
Payload::Request(request) => match request.command.as_str() {
RunInTerminal::COMMAND => {
- let mut arguments: dap::requests::RunInTerminalArguments =
+ let arguments: dap::requests::RunInTerminalArguments =
serde_json::from_value(request.arguments.unwrap_or_default()).unwrap();
// TODO: no unwrap
- log::error!("run_in_terminal {:?}", arguments);
-
- // HAXX: lldb-vscode uses $CWD/lldb-vscode which is wrong
- let program = arguments.args[0]
- .strip_prefix(
- std::env::current_dir()
- .expect("Couldn't get current working directory")
- .as_path()
- .to_str()
- .unwrap(),
- )
- .and_then(|arg| arg.strip_prefix('/'))
- .map(|arg| arg.to_owned())
- .unwrap_or_else(|| arguments.args[0].clone());
- arguments.args[0] = program;
-
- log::error!("{}", arguments.args.join(" "));
-
- // TODO: handle cwd
let process = std::process::Command::new("tmux")
.arg("split-window")
- .arg(arguments.args.join(" ")) // TODO: first arg is wrong, it uses current dir
+ .arg(arguments.args.join(" "))
.spawn()
.unwrap();