From 9617bb4f07f724b25abd4040a960f5ccff97b569 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 27 Jun 2020 01:28:06 +0200 Subject: Try to find rustfmt in more places --- Cargo.lock | 1 + crates/ra_toolchain/src/lib.rs | 4 ++++ crates/rust-analyzer/Cargo.toml | 1 + crates/rust-analyzer/src/handlers.rs | 2 +- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index b2b624212..044314a8f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1395,6 +1395,7 @@ dependencies = [ "ra_project_model", "ra_syntax", "ra_text_edit", + "ra_toolchain", "ra_tt", "rand", "rustc-hash", diff --git a/crates/ra_toolchain/src/lib.rs b/crates/ra_toolchain/src/lib.rs index 3d2865e09..9532fb255 100644 --- a/crates/ra_toolchain/src/lib.rs +++ b/crates/ra_toolchain/src/lib.rs @@ -15,6 +15,10 @@ pub fn rustup() -> PathBuf { get_path_for_executable("rustup") } +pub fn rustfmt() -> PathBuf { + get_path_for_executable("rustfmt") +} + /// Return a `PathBuf` to use for the given executable. /// /// E.g., `get_path_for_executable("cargo")` may return just `cargo` if that diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml index 08c67ddd0..122a1605f 100644 --- a/crates/rust-analyzer/Cargo.toml +++ b/crates/rust-analyzer/Cargo.toml @@ -41,6 +41,7 @@ ra_text_edit = { path = "../ra_text_edit" } vfs = { path = "../vfs" } vfs-notify = { path = "../vfs-notify" } ra_cfg = { path = "../ra_cfg"} +ra_toolchain = { path = "../ra_toolchain" } # This should only be used in CLI ra_db = { path = "../ra_db" } diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index 6c21f25fe..38e3c3324 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs @@ -650,7 +650,7 @@ pub(crate) fn handle_formatting( let mut rustfmt = match &snap.config.rustfmt { RustfmtConfig::Rustfmt { extra_args } => { - let mut cmd = process::Command::new("rustfmt"); + let mut cmd = process::Command::new(ra_toolchain::rustfmt()); cmd.args(extra_args); if let Some(&crate_id) = crate_ids.first() { // Assume all crates are in the same edition -- cgit v1.2.3