Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/proc-macro-api/src/lib.rs11
-rw-r--r--crates/proc-macro-api/src/msg.rs19
-rw-r--r--crates/proc-macro-srv-cli/src/main.rs7
-rw-r--r--crates/proc-macro-srv/src/server/rust_analyzer_span.rs6
-rw-r--r--crates/proc-macro-srv/src/server/token_id.rs2
-rw-r--r--crates/rust-analyzer/tests/slow-tests/main.rs2
6 files changed, 41 insertions, 6 deletions
diff --git a/crates/proc-macro-api/src/lib.rs b/crates/proc-macro-api/src/lib.rs
index be68f6eff6..a87becd63e 100644
--- a/crates/proc-macro-api/src/lib.rs
+++ b/crates/proc-macro-api/src/lib.rs
@@ -21,8 +21,8 @@ use serde::{Deserialize, Serialize};
use crate::{
msg::{
- flat::serialize_span_data_index_map, ExpandMacro, ExpnGlobals, FlatTree, PanicMessage,
- HAS_GLOBAL_SPANS, RUST_ANALYZER_SPAN_SUPPORT,
+ deserialize_span_data_index_map, flat::serialize_span_data_index_map, ExpandMacro,
+ ExpnGlobals, FlatTree, PanicMessage, HAS_GLOBAL_SPANS, RUST_ANALYZER_SPAN_SUPPORT,
},
process::ProcMacroProcessSrv,
};
@@ -186,6 +186,13 @@ impl ProcMacro {
msg::Response::ExpandMacro(it) => {
Ok(it.map(|tree| FlatTree::to_subtree_resolved(tree, version, &span_data_table)))
}
+ msg::Response::ExpandMacroExtended(it) => Ok(it.map(|resp| {
+ FlatTree::to_subtree_resolved(
+ resp.tree,
+ version,
+ &deserialize_span_data_index_map(&resp.span_data_table),
+ )
+ })),
_ => Err(ServerError { message: "unexpected response".to_string(), io: None }),
}
}
diff --git a/crates/proc-macro-api/src/msg.rs b/crates/proc-macro-api/src/msg.rs
index 7ef6d5b055..c8faa88e09 100644
--- a/crates/proc-macro-api/src/msg.rs
+++ b/crates/proc-macro-api/src/msg.rs
@@ -26,10 +26,14 @@ pub const CURRENT_API_VERSION: u32 = RUST_ANALYZER_SPAN_SUPPORT;
#[derive(Debug, Serialize, Deserialize)]
pub enum Request {
+ /// Since [`NO_VERSION_CHECK_VERSION`]
ListMacros { dylib_path: PathBuf },
+ /// Since [`NO_VERSION_CHECK_VERSION`]
ExpandMacro(ExpandMacro),
- SetSpanMode(SpanMode),
+ /// Since [`VERSION_CHECK_VERSION`]
ApiVersionCheck {},
+ /// Since [`RUST_ANALYZER_SPAN_SUPPORT`]
+ SetSpanMode(SpanMode),
}
#[derive(Copy, Clone, Default, Debug, Serialize, Deserialize)]
@@ -41,11 +45,22 @@ pub enum SpanMode {
#[derive(Debug, Serialize, Deserialize)]
pub enum Response {
+ /// Since [`NO_VERSION_CHECK_VERSION`]
ListMacros(Result<Vec<(String, ProcMacroKind)>, String>),
+ /// Since [`NO_VERSION_CHECK_VERSION`]
ExpandMacro(Result<FlatTree, PanicMessage>),
- ExpandMacroSpans(Result<(FlatTree, Vec<u32>), PanicMessage>),
+ /// Since [`NO_VERSION_CHECK_VERSION`]
ApiVersionCheck(u32),
+ /// Since [`RUST_ANALYZER_SPAN_SUPPORT`]
SetSpanMode(SpanMode),
+ /// Since [`RUST_ANALYZER_SPAN_SUPPORT`]
+ ExpandMacroExtended(Result<ExpandMacroExtended, PanicMessage>),
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct ExpandMacroExtended {
+ pub tree: FlatTree,
+ pub span_data_table: Vec<u32>,
}
#[derive(Debug, Serialize, Deserialize)]
diff --git a/crates/proc-macro-srv-cli/src/main.rs b/crates/proc-macro-srv-cli/src/main.rs
index f4e88ed437..52882d8345 100644
--- a/crates/proc-macro-srv-cli/src/main.rs
+++ b/crates/proc-macro-srv-cli/src/main.rs
@@ -41,7 +41,12 @@ fn run() -> io::Result<()> {
}
msg::Request::ExpandMacro(task) => match srv.span_mode() {
msg::SpanMode::Id => msg::Response::ExpandMacro(srv.expand(task).map(|(it, _)| it)),
- msg::SpanMode::RustAnalyzer => msg::Response::ExpandMacroSpans(srv.expand(task)),
+ msg::SpanMode::RustAnalyzer => msg::Response::ExpandMacroExtended(
+ srv.expand(task).map(|(tree, span_data_table)| msg::ExpandMacroExtended {
+ tree,
+ span_data_table,
+ }),
+ ),
},
msg::Request::ApiVersionCheck {} => {
msg::Response::ApiVersionCheck(proc_macro_api::msg::CURRENT_API_VERSION)
diff --git a/crates/proc-macro-srv/src/server/rust_analyzer_span.rs b/crates/proc-macro-srv/src/server/rust_analyzer_span.rs
index 59d492c6f6..1609816971 100644
--- a/crates/proc-macro-srv/src/server/rust_analyzer_span.rs
+++ b/crates/proc-macro-srv/src/server/rust_analyzer_span.rs
@@ -1,3 +1,9 @@
+//! proc-macro server backend based on rust-analyzer's internal span represention
+//! This backend is used solely by rust-analyzer as it ties into rust-analyzer internals.
+//!
+//! It is an unfortunate result of how the proc-macro API works that we need to look into the
+//! concrete representation of the spans, and as such, RustRover cannot make use of this unless they
+//! change their representation to be compatible with rust-analyzer's.
use std::{
collections::{HashMap, HashSet},
iter,
diff --git a/crates/proc-macro-srv/src/server/token_id.rs b/crates/proc-macro-srv/src/server/token_id.rs
index 01ca7488fa..d07bceb1c8 100644
--- a/crates/proc-macro-srv/src/server/token_id.rs
+++ b/crates/proc-macro-srv/src/server/token_id.rs
@@ -1,3 +1,5 @@
+//! proc-macro server backend based on [`proc_macro_api::msg::TokenId`] as the backing span.
+//! This backend is rather inflexible, used by RustRover and older rust-analyzer versions.
use std::{
iter,
ops::{Bound, Range},
diff --git a/crates/rust-analyzer/tests/slow-tests/main.rs b/crates/rust-analyzer/tests/slow-tests/main.rs
index ec8e5c6dd9..78411e2d58 100644
--- a/crates/rust-analyzer/tests/slow-tests/main.rs
+++ b/crates/rust-analyzer/tests/slow-tests/main.rs
@@ -832,7 +832,7 @@ fn main() {
}
#[test]
-#[cfg(feature = "sysroot-abi")]
+#[cfg(any(feature = "sysroot-abi", rust_analyzer))]
fn resolve_proc_macro() {
use expect_test::expect;
if skip_slow_tests() {