Skip to content

Commit 29bc218

Browse files
bors[bot]matklad
andauthored
Merge #4102
4102: Cleanup proc_macro config r=matklad a=matklad 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`. bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 9b53e79 + ca6d7bf commit 29bc218

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
//! configure the server itself, feature flags are passed into analysis, and
88
//! tweak things like automatic insertion of `()` in completions.
99
10+
use std::{ffi::OsString, path::PathBuf};
11+
1012
use lsp_types::TextDocumentClientCapabilities;
1113
use ra_flycheck::FlycheckConfig;
1214
use ra_ide::{CompletionConfig, InlayHintsConfig};
@@ -20,7 +22,7 @@ pub struct Config {
2022
pub with_sysroot: bool,
2123
pub publish_diagnostics: bool,
2224
pub lru_capacity: Option<usize>,
23-
pub proc_macro_srv: Option<(String, Vec<String>)>,
25+
pub proc_macro_srv: Option<(PathBuf, Vec<OsString>)>,
2426
pub files: FilesConfig,
2527
pub notifications: NotificationsConfig,
2628

@@ -135,7 +137,7 @@ impl Config {
135137
match get(value, "/procMacro/enable") {
136138
Some(true) => {
137139
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()]));
139141
}
140142
}
141143
_ => self.proc_macro_srv = None,

crates/rust-analyzer/src/world.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl WorldState {
153153
Err(err) => {
154154
log::error!(
155155
"Failed to run ra_proc_macro_srv from path {}, error: {:?}",
156-
path,
156+
path.display(),
157157
err
158158
);
159159
ProcMacroClient::dummy()

crates/rust-analyzer/tests/heavy_tests/main.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
mod support;
22

3-
use std::{collections::HashMap, time::Instant};
3+
use std::{collections::HashMap, path::PathBuf, time::Instant};
44

55
use lsp_types::{
66
CodeActionContext, DidOpenTextDocumentParams, DocumentFormattingParams, FormattingOptions,
@@ -692,15 +692,10 @@ pub fn foo(_input: TokenStream) -> TokenStream {
692692
"###,
693693
)
694694
.with_config(|config| {
695-
// FIXME: Use env!("CARGO_BIN_EXE_ra-analyzer") instead after
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();
695+
let macro_srv_path = PathBuf::from(env!("CARGO_BIN_EXE_rust-analyzer"));
701696

702697
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()]));
704699
})
705700
.root("foo")
706701
.root("bar")

0 commit comments

Comments
 (0)