diff options
author | Aleksey Kladov <[email protected]> | 2020-04-23 17:50:25 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-04-23 17:55:26 +0100 |
commit | ca6d7bfe617aa49fdd9c996d2680a94e24207b86 (patch) | |
tree | 47fb5ae530075e5e0130984542c58fea13850437 | |
parent | 278bf351e3d9bf074b76f89afa04c4727d55fba6 (diff) |
Cleanup proc_macro config
In general, there should be no reason to call `.to_string_lossy`.
If you want to display the path, use `.display()`.
If you want to pass the path to an OS API (like std::process::Command)
than use `PathBuf` or `OsString`.
-rw-r--r-- | crates/rust-analyzer/src/config.rs | 6 | ||||
-rw-r--r-- | crates/rust-analyzer/src/world.rs | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/tests/heavy_tests/main.rs | 11 |
3 files changed, 8 insertions, 11 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index fa0b1e226..642c34574 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs | |||
@@ -7,6 +7,8 @@ | |||
7 | //! configure the server itself, feature flags are passed into analysis, and | 7 | //! configure the server itself, feature flags are passed into analysis, and |
8 | //! tweak things like automatic insertion of `()` in completions. | 8 | //! tweak things like automatic insertion of `()` in completions. |
9 | 9 | ||
10 | use std::{ffi::OsString, path::PathBuf}; | ||
11 | |||
10 | use lsp_types::TextDocumentClientCapabilities; | 12 | use lsp_types::TextDocumentClientCapabilities; |
11 | use ra_flycheck::FlycheckConfig; | 13 | use ra_flycheck::FlycheckConfig; |
12 | use ra_ide::{CompletionConfig, InlayHintsConfig}; | 14 | use ra_ide::{CompletionConfig, InlayHintsConfig}; |
@@ -20,7 +22,7 @@ pub struct Config { | |||
20 | pub with_sysroot: bool, | 22 | pub with_sysroot: bool, |
21 | pub publish_diagnostics: bool, | 23 | pub publish_diagnostics: bool, |
22 | pub lru_capacity: Option<usize>, | 24 | pub lru_capacity: Option<usize>, |
23 | pub proc_macro_srv: Option<(String, Vec<String>)>, | 25 | pub proc_macro_srv: Option<(PathBuf, Vec<OsString>)>, |
24 | pub files: FilesConfig, | 26 | pub files: FilesConfig, |
25 | pub notifications: NotificationsConfig, | 27 | pub notifications: NotificationsConfig, |
26 | 28 | ||
@@ -135,7 +137,7 @@ impl Config { | |||
135 | match get(value, "/procMacro/enable") { | 137 | match get(value, "/procMacro/enable") { |
136 | Some(true) => { | 138 | Some(true) => { |
137 | if let Ok(path) = std::env::current_exe() { | 139 | if let Ok(path) = std::env::current_exe() { |
138 | self.proc_macro_srv = Some((path.to_string_lossy().to_string(), vec!["proc-macro".to_string()])); | 140 | self.proc_macro_srv = Some((path, vec!["proc-macro".into()])); |
139 | } | 141 | } |
140 | } | 142 | } |
141 | _ => self.proc_macro_srv = None, | 143 | _ => self.proc_macro_srv = None, |
diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs index 7c0bb42aa..34941931b 100644 --- a/crates/rust-analyzer/src/world.rs +++ b/crates/rust-analyzer/src/world.rs | |||
@@ -153,7 +153,7 @@ impl WorldState { | |||
153 | Err(err) => { | 153 | Err(err) => { |
154 | log::error!( | 154 | log::error!( |
155 | "Failed to run ra_proc_macro_srv from path {}, error: {:?}", | 155 | "Failed to run ra_proc_macro_srv from path {}, error: {:?}", |
156 | path, | 156 | path.display(), |
157 | err | 157 | err |
158 | ); | 158 | ); |
159 | ProcMacroClient::dummy() | 159 | ProcMacroClient::dummy() |
diff --git a/crates/rust-analyzer/tests/heavy_tests/main.rs b/crates/rust-analyzer/tests/heavy_tests/main.rs index 1dd2676b6..b31533e5e 100644 --- a/crates/rust-analyzer/tests/heavy_tests/main.rs +++ b/crates/rust-analyzer/tests/heavy_tests/main.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | mod support; | 1 | mod support; |
2 | 2 | ||
3 | use std::{collections::HashMap, time::Instant}; | 3 | use std::{collections::HashMap, path::PathBuf, time::Instant}; |
4 | 4 | ||
5 | use lsp_types::{ | 5 | use lsp_types::{ |
6 | CodeActionContext, DidOpenTextDocumentParams, DocumentFormattingParams, FormattingOptions, | 6 | CodeActionContext, DidOpenTextDocumentParams, DocumentFormattingParams, FormattingOptions, |
@@ -692,15 +692,10 @@ pub fn foo(_input: TokenStream) -> TokenStream { | |||
692 | "###, | 692 | "###, |
693 | ) | 693 | ) |
694 | .with_config(|config| { | 694 | .with_config(|config| { |
695 | // FIXME: Use env!("CARGO_BIN_EXE_ra-analyzer") instead after | 695 | let macro_srv_path = PathBuf::from(env!("CARGO_BIN_EXE_rust-analyzer")); |
696 | // https://github.com/rust-lang/cargo/pull/7697 landed | ||
697 | let macro_srv_path = std::path::Path::new(std::env!("CARGO_MANIFEST_DIR")) | ||
698 | .join("../../target/debug/rust-analyzer") | ||
699 | .to_string_lossy() | ||
700 | .to_string(); | ||
701 | 696 | ||
702 | config.cargo.load_out_dirs_from_check = true; | 697 | config.cargo.load_out_dirs_from_check = true; |
703 | config.proc_macro_srv = Some((macro_srv_path, vec!["proc-macro".to_string()])); | 698 | config.proc_macro_srv = Some((macro_srv_path, vec!["proc-macro".into()])); |
704 | }) | 699 | }) |
705 | .root("foo") | 700 | .root("foo") |
706 | .root("bar") | 701 | .root("bar") |