Skip to content

Commit

Permalink
Fix proc-macro server spawning behavior when the server is r-a itself
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Mar 29, 2023
1 parent 0522503 commit 3d6087f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 26 deletions.
13 changes: 9 additions & 4 deletions crates/rust-analyzer/src/reload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,18 +376,23 @@ impl GlobalState {
.workspaces
.iter()
.map(|ws| {
let (path, args): (_, &[_]) = if path_manually_set {
let path = if path_manually_set {
tracing::debug!(
"Pro-macro server path explicitly set: {}",
path.display()
);
(path.clone(), &[])
path.clone()
} else {
match ws.find_sysroot_proc_macro_srv() {
Some(server_path) => (server_path, &[]),
None => (path.clone(), &["proc-macro"]),
Some(server_path) => server_path,
None => path.clone(),
}
};
let args: &[_] = if path.file_stem() == Some("rust-analyzer".as_ref()) {
&["proc-macro"]
} else {
&[]
};

tracing::info!(?args, "Using proc-macro server at {}", path.display(),);
ProcMacroServer::spawn(path.clone(), args).map_err(|err| {
Expand Down
55 changes: 33 additions & 22 deletions crates/rust-analyzer/tests/slow-tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ version = \"0.0.0\"
#[test]
fn out_dirs_check() {
if skip_slow_tests() {
// return;
return;
}

let server = Project::with_fixture(
Expand All @@ -711,10 +711,20 @@ fn main() {
println!("cargo:rerun-if-changed=build.rs");
}
//- /src/main.rs
#[rustc_builtin_macro] macro_rules! include {}
#[rustc_builtin_macro] macro_rules! include_str {}
#[rustc_builtin_macro] macro_rules! concat {}
#[rustc_builtin_macro] macro_rules! env {}
#![feature(rustc_attrs)]
#[rustc_builtin_macro] macro_rules! include {
($file:expr $(,)?) => {{ /* compiler built-in */ }};
}
#[rustc_builtin_macro] macro_rules! include_str {
($file:expr $(,)?) => {{ /* compiler built-in */ }};
}
#[rustc_builtin_macro] macro_rules! concat {
($($e:ident),+ $(,)?) => {{ /* compiler built-in */ }};
}
#[rustc_builtin_macro] macro_rules! env {
($name:expr $(,)?) => {{ /* compiler built-in */ }};
($name:expr, $error_msg:expr $(,)?) => {{ /* compiler built-in */ }};
}
include!(concat!(env!("OUT_DIR"), "/hello.rs"));
Expand Down Expand Up @@ -749,7 +759,7 @@ fn main() {
let res = server.send_request::<HoverRequest>(HoverParams {
text_document_position_params: TextDocumentPositionParams::new(
server.doc_id("src/main.rs"),
Position::new(19, 10),
Position::new(29, 10),
),
work_done_progress_params: Default::default(),
});
Expand All @@ -758,7 +768,7 @@ fn main() {
let res = server.send_request::<HoverRequest>(HoverParams {
text_document_position_params: TextDocumentPositionParams::new(
server.doc_id("src/main.rs"),
Position::new(20, 10),
Position::new(30, 10),
),
work_done_progress_params: Default::default(),
});
Expand All @@ -768,23 +778,23 @@ fn main() {
GotoDefinitionParams {
text_document_position_params: TextDocumentPositionParams::new(
server.doc_id("src/main.rs"),
Position::new(17, 9),
Position::new(27, 9),
),
work_done_progress_params: Default::default(),
partial_result_params: Default::default(),
},
json!([{
"originSelectionRange": {
"end": { "character": 10, "line": 17 },
"start": { "character": 8, "line": 17 }
"end": { "character": 10, "line": 27 },
"start": { "character": 8, "line": 27 }
},
"targetRange": {
"end": { "character": 9, "line": 8 },
"start": { "character": 0, "line": 7 }
"end": { "character": 9, "line": 18 },
"start": { "character": 0, "line": 17 }
},
"targetSelectionRange": {
"end": { "character": 8, "line": 8 },
"start": { "character": 7, "line": 8 }
"end": { "character": 8, "line": 18 },
"start": { "character": 7, "line": 18 }
},
"targetUri": "file:///[..]src/main.rs"
}]),
Expand All @@ -794,23 +804,23 @@ fn main() {
GotoDefinitionParams {
text_document_position_params: TextDocumentPositionParams::new(
server.doc_id("src/main.rs"),
Position::new(18, 9),
Position::new(28, 9),
),
work_done_progress_params: Default::default(),
partial_result_params: Default::default(),
},
json!([{
"originSelectionRange": {
"end": { "character": 10, "line": 18 },
"start": { "character": 8, "line": 18 }
"end": { "character": 10, "line": 28 },
"start": { "character": 8, "line": 28 }
},
"targetRange": {
"end": { "character": 9, "line": 12 },
"start": { "character": 0, "line":11 }
"end": { "character": 9, "line": 22 },
"start": { "character": 0, "line": 21 }
},
"targetSelectionRange": {
"end": { "character": 8, "line": 12 },
"start": { "character": 7, "line": 12 }
"end": { "character": 8, "line": 22 },
"start": { "character": 7, "line": 22 }
},
"targetUri": "file:///[..]src/main.rs"
}]),
Expand All @@ -836,6 +846,7 @@ edition = "2021"
bar = {path = "../bar"}
//- /foo/src/main.rs
#![feature(rustc_attrs, decl_macro)]
use bar::Bar;
#[rustc_builtin_macro]
Expand Down Expand Up @@ -912,7 +923,7 @@ pub fn foo(_input: TokenStream) -> TokenStream {
let res = server.send_request::<HoverRequest>(HoverParams {
text_document_position_params: TextDocumentPositionParams::new(
server.doc_id("foo/src/main.rs"),
Position::new(10, 9),
Position::new(11, 9),
),
work_done_progress_params: Default::default(),
});
Expand Down

0 comments on commit 3d6087f

Please sign in to comment.