Skip to content

Commit

Permalink
Use which to resolve lsp/dap binaries
Browse files Browse the repository at this point in the history
This resolves the following issue: #962 (comment)
  • Loading branch information
archseer committed Feb 24, 2022
1 parent 4526216 commit 9712bbb
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 21 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions helix-dap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 3 additions & 0 deletions helix-dap/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
1 change: 1 addition & 0 deletions helix-lsp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 3 additions & 0 deletions helix-lsp/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
23 changes: 2 additions & 21 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 9712bbb

Please sign in to comment.