mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
Auto merge of #14432 - Veykril:proc-macro-srv, r=lnicola
Drop support for non-syroot proc macro ABIs This makes some bigger changes to how we handle the proc-macro-srv things, for one it is now an empty crate if built without the `sysroot-abi` feature, this simplifies some things dropping the need to put the feature cfg in various places. The cli wrapper now actually depends on the server, instead of being part of the server that is just exported, that way we can have a true dummy server that just errors on each request if no sysroot support was specified.
This commit is contained in:
commit
e3e324d830
32 changed files with 255 additions and 4687 deletions
|
@ -67,7 +67,7 @@ ide-db.workspace = true
|
|||
ide-ssr.workspace = true
|
||||
ide.workspace = true
|
||||
proc-macro-api.workspace = true
|
||||
proc-macro-srv.workspace = true
|
||||
proc-macro-srv-cli.workspace = true
|
||||
profile.workspace = true
|
||||
project-model.workspace = true
|
||||
stdx.workspace = true
|
||||
|
@ -95,8 +95,9 @@ mbe.workspace = true
|
|||
[features]
|
||||
jemalloc = ["jemallocator", "profile/jemalloc"]
|
||||
force-always-assert = ["always-assert/force"]
|
||||
sysroot-abi = ["proc-macro-srv-cli/sysroot-abi"]
|
||||
in-rust-tree = [
|
||||
"proc-macro-srv/sysroot-abi",
|
||||
"sysroot-abi",
|
||||
"ide/in-rust-tree",
|
||||
"syntax/in-rust-tree",
|
||||
]
|
||||
|
|
|
@ -77,7 +77,7 @@ fn try_main(flags: flags::RustAnalyzer) -> Result<()> {
|
|||
with_extra_thread("LspServer", run_server)?;
|
||||
}
|
||||
flags::RustAnalyzerCmd::ProcMacro(flags::ProcMacro) => {
|
||||
with_extra_thread("MacroExpander", || proc_macro_srv::cli::run().map_err(Into::into))?;
|
||||
with_extra_thread("MacroExpander", || proc_macro_srv_cli::run().map_err(Into::into))?;
|
||||
}
|
||||
flags::RustAnalyzerCmd::Parse(cmd) => cmd.run()?,
|
||||
flags::RustAnalyzerCmd::Symbols(cmd) => cmd.run()?,
|
||||
|
|
|
@ -114,6 +114,10 @@ impl GlobalState {
|
|||
status.health = lsp_ext::Health::Warning;
|
||||
message.push_str("Failed to run build scripts of some packages.\n\n");
|
||||
}
|
||||
if self.proc_macro_clients.iter().any(|it| it.is_err()) {
|
||||
status.health = lsp_ext::Health::Warning;
|
||||
message.push_str("Failed to spawn one or more proc-macro servers.\n\n");
|
||||
}
|
||||
if !self.config.cargo_autoreload()
|
||||
&& self.is_quiescent()
|
||||
&& self.fetch_workspaces_queue.op_requested()
|
||||
|
@ -384,18 +388,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| {
|
||||
|
|
|
@ -59,7 +59,7 @@ use std::collections::Spam;
|
|||
"#,
|
||||
)
|
||||
.with_config(serde_json::json!({
|
||||
"cargo": { "sysroot": "discover" }
|
||||
"cargo": { "sysroot": "discover" },
|
||||
}))
|
||||
.server()
|
||||
.wait_until_workspace_is_loaded();
|
||||
|
@ -508,7 +508,7 @@ fn main() {}
|
|||
#[test]
|
||||
fn test_missing_module_code_action_in_json_project() {
|
||||
if skip_slow_tests() {
|
||||
// return;
|
||||
return;
|
||||
}
|
||||
|
||||
let tmp_dir = TestDir::new();
|
||||
|
@ -612,7 +612,7 @@ fn main() {{}}
|
|||
"#
|
||||
))
|
||||
.with_config(serde_json::json!({
|
||||
"cargo": { "sysroot": "discover" }
|
||||
"cargo": { "sysroot": "discover" },
|
||||
}))
|
||||
.server()
|
||||
.wait_until_workspace_is_loaded();
|
||||
|
@ -685,7 +685,7 @@ version = \"0.0.0\"
|
|||
#[test]
|
||||
fn out_dirs_check() {
|
||||
if skip_slow_tests() {
|
||||
// return;
|
||||
return;
|
||||
}
|
||||
|
||||
let server = Project::with_fixture(
|
||||
|
@ -711,10 +711,21 @@ 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 {}
|
||||
#![allow(warnings)]
|
||||
#![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"));
|
||||
|
||||
|
@ -749,7 +760,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(30, 10),
|
||||
),
|
||||
work_done_progress_params: Default::default(),
|
||||
});
|
||||
|
@ -758,7 +769,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(31, 10),
|
||||
),
|
||||
work_done_progress_params: Default::default(),
|
||||
});
|
||||
|
@ -768,23 +779,23 @@ fn main() {
|
|||
GotoDefinitionParams {
|
||||
text_document_position_params: TextDocumentPositionParams::new(
|
||||
server.doc_id("src/main.rs"),
|
||||
Position::new(17, 9),
|
||||
Position::new(28, 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": 28 },
|
||||
"start": { "character": 8, "line": 28 }
|
||||
},
|
||||
"targetRange": {
|
||||
"end": { "character": 9, "line": 8 },
|
||||
"start": { "character": 0, "line": 7 }
|
||||
"end": { "character": 9, "line": 19 },
|
||||
"start": { "character": 0, "line": 18 }
|
||||
},
|
||||
"targetSelectionRange": {
|
||||
"end": { "character": 8, "line": 8 },
|
||||
"start": { "character": 7, "line": 8 }
|
||||
"end": { "character": 8, "line": 19 },
|
||||
"start": { "character": 7, "line": 19 }
|
||||
},
|
||||
"targetUri": "file:///[..]src/main.rs"
|
||||
}]),
|
||||
|
@ -794,23 +805,23 @@ fn main() {
|
|||
GotoDefinitionParams {
|
||||
text_document_position_params: TextDocumentPositionParams::new(
|
||||
server.doc_id("src/main.rs"),
|
||||
Position::new(18, 9),
|
||||
Position::new(29, 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": 29 },
|
||||
"start": { "character": 8, "line": 29 }
|
||||
},
|
||||
"targetRange": {
|
||||
"end": { "character": 9, "line": 12 },
|
||||
"start": { "character": 0, "line":11 }
|
||||
"end": { "character": 9, "line": 23 },
|
||||
"start": { "character": 0, "line": 22 }
|
||||
},
|
||||
"targetSelectionRange": {
|
||||
"end": { "character": 8, "line": 12 },
|
||||
"start": { "character": 7, "line": 12 }
|
||||
"end": { "character": 8, "line": 23 },
|
||||
"start": { "character": 7, "line": 23 }
|
||||
},
|
||||
"targetUri": "file:///[..]src/main.rs"
|
||||
}]),
|
||||
|
@ -818,8 +829,7 @@ fn main() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
// FIXME: Re-enable once we can run proc-macro tests on rust-lang/rust-analyzer again
|
||||
#[cfg(any())]
|
||||
#[cfg(feature = "sysroot-abi")]
|
||||
fn resolve_proc_macro() {
|
||||
use expect_test::expect;
|
||||
if skip_slow_tests() {
|
||||
|
@ -837,6 +847,7 @@ edition = "2021"
|
|||
bar = {path = "../bar"}
|
||||
|
||||
//- /foo/src/main.rs
|
||||
#![feature(rustc_attrs, decl_macro)]
|
||||
use bar::Bar;
|
||||
|
||||
#[rustc_builtin_macro]
|
||||
|
@ -913,7 +924,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(),
|
||||
});
|
||||
|
@ -1083,10 +1094,18 @@ version = "0.0.0"
|
|||
|
||||
//- /bar/src/lib.rs
|
||||
pub fn bar() {}
|
||||
|
||||
//- /baz/Cargo.toml
|
||||
[package]
|
||||
name = "baz"
|
||||
version = "0.0.0"
|
||||
|
||||
//- /baz/src/lib.rs
|
||||
"#,
|
||||
)
|
||||
.root("foo")
|
||||
.root("bar")
|
||||
.root("baz")
|
||||
.with_config(json!({
|
||||
"files": {
|
||||
"excludeDirs": ["foo", "bar"]
|
||||
|
|
|
@ -37,8 +37,12 @@ impl<'a> Project<'a> {
|
|||
"sysroot": null,
|
||||
// Can't use test binary as rustc wrapper.
|
||||
"buildScripts": {
|
||||
"useRustcWrapper": false
|
||||
"useRustcWrapper": false,
|
||||
"enable": false,
|
||||
},
|
||||
},
|
||||
"procMacro": {
|
||||
"enable": false,
|
||||
}
|
||||
}),
|
||||
}
|
||||
|
@ -251,6 +255,9 @@ impl Server {
|
|||
.clone()
|
||||
.extract::<lsp_ext::ServerStatusParams>("experimental/serverStatus")
|
||||
.unwrap();
|
||||
if status.health != lsp_ext::Health::Ok {
|
||||
panic!("server errored/warned while loading workspace: {:?}", status.message);
|
||||
}
|
||||
status.quiescent
|
||||
}
|
||||
_ => false,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue