Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 2e52aa1

Browse files
committed
Clean up
1 parent ca957f4 commit 2e52aa1

File tree

6 files changed

+41
-6
lines changed

6 files changed

+41
-6
lines changed

crates/proc-macro-api/src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use serde::{Deserialize, Serialize};
2121

2222
use crate::{
2323
msg::{
24-
flat::serialize_span_data_index_map, ExpandMacro, ExpnGlobals, FlatTree, PanicMessage,
25-
HAS_GLOBAL_SPANS, RUST_ANALYZER_SPAN_SUPPORT,
24+
deserialize_span_data_index_map, flat::serialize_span_data_index_map, ExpandMacro,
25+
ExpnGlobals, FlatTree, PanicMessage, HAS_GLOBAL_SPANS, RUST_ANALYZER_SPAN_SUPPORT,
2626
},
2727
process::ProcMacroProcessSrv,
2828
};
@@ -186,6 +186,13 @@ impl ProcMacro {
186186
msg::Response::ExpandMacro(it) => {
187187
Ok(it.map(|tree| FlatTree::to_subtree_resolved(tree, version, &span_data_table)))
188188
}
189+
msg::Response::ExpandMacroExtended(it) => Ok(it.map(|resp| {
190+
FlatTree::to_subtree_resolved(
191+
resp.tree,
192+
version,
193+
&deserialize_span_data_index_map(&resp.span_data_table),
194+
)
195+
})),
189196
_ => Err(ServerError { message: "unexpected response".to_string(), io: None }),
190197
}
191198
}

crates/proc-macro-api/src/msg.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ pub const CURRENT_API_VERSION: u32 = RUST_ANALYZER_SPAN_SUPPORT;
2626

2727
#[derive(Debug, Serialize, Deserialize)]
2828
pub enum Request {
29+
/// Since [`NO_VERSION_CHECK_VERSION`]
2930
ListMacros { dylib_path: PathBuf },
31+
/// Since [`NO_VERSION_CHECK_VERSION`]
3032
ExpandMacro(ExpandMacro),
31-
SetSpanMode(SpanMode),
33+
/// Since [`VERSION_CHECK_VERSION`]
3234
ApiVersionCheck {},
35+
/// Since [`RUST_ANALYZER_SPAN_SUPPORT`]
36+
SetSpanMode(SpanMode),
3337
}
3438

3539
#[derive(Copy, Clone, Default, Debug, Serialize, Deserialize)]
@@ -41,11 +45,22 @@ pub enum SpanMode {
4145

4246
#[derive(Debug, Serialize, Deserialize)]
4347
pub enum Response {
48+
/// Since [`NO_VERSION_CHECK_VERSION`]
4449
ListMacros(Result<Vec<(String, ProcMacroKind)>, String>),
50+
/// Since [`NO_VERSION_CHECK_VERSION`]
4551
ExpandMacro(Result<FlatTree, PanicMessage>),
46-
ExpandMacroSpans(Result<(FlatTree, Vec<u32>), PanicMessage>),
52+
/// Since [`NO_VERSION_CHECK_VERSION`]
4753
ApiVersionCheck(u32),
54+
/// Since [`RUST_ANALYZER_SPAN_SUPPORT`]
4855
SetSpanMode(SpanMode),
56+
/// Since [`RUST_ANALYZER_SPAN_SUPPORT`]
57+
ExpandMacroExtended(Result<ExpandMacroExtended, PanicMessage>),
58+
}
59+
60+
#[derive(Debug, Serialize, Deserialize)]
61+
pub struct ExpandMacroExtended {
62+
pub tree: FlatTree,
63+
pub span_data_table: Vec<u32>,
4964
}
5065

5166
#[derive(Debug, Serialize, Deserialize)]

crates/proc-macro-srv-cli/src/main.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ fn run() -> io::Result<()> {
4141
}
4242
msg::Request::ExpandMacro(task) => match srv.span_mode() {
4343
msg::SpanMode::Id => msg::Response::ExpandMacro(srv.expand(task).map(|(it, _)| it)),
44-
msg::SpanMode::RustAnalyzer => msg::Response::ExpandMacroSpans(srv.expand(task)),
44+
msg::SpanMode::RustAnalyzer => msg::Response::ExpandMacroExtended(
45+
srv.expand(task).map(|(tree, span_data_table)| msg::ExpandMacroExtended {
46+
tree,
47+
span_data_table,
48+
}),
49+
),
4550
},
4651
msg::Request::ApiVersionCheck {} => {
4752
msg::Response::ApiVersionCheck(proc_macro_api::msg::CURRENT_API_VERSION)

crates/proc-macro-srv/src/server/rust_analyzer_span.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
//! proc-macro server backend based on rust-analyzer's internal span represention
2+
//! This backend is used solely by rust-analyzer as it ties into rust-analyzer internals.
3+
//!
4+
//! It is an unfortunate result of how the proc-macro API works that we need to look into the
5+
//! concrete representation of the spans, and as such, RustRover cannot make use of this unless they
6+
//! change their representation to be compatible with rust-analyzer's.
17
use std::{
28
collections::{HashMap, HashSet},
39
iter,

crates/proc-macro-srv/src/server/token_id.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! proc-macro server backend based on [`proc_macro_api::msg::TokenId`] as the backing span.
2+
//! This backend is rather inflexible, used by RustRover and older rust-analyzer versions.
13
use std::{
24
iter,
35
ops::{Bound, Range},

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ fn main() {
832832
}
833833

834834
#[test]
835-
#[cfg(feature = "sysroot-abi")]
835+
#[cfg(any(feature = "sysroot-abi", rust_analyzer))]
836836
fn resolve_proc_macro() {
837837
use expect_test::expect;
838838
if skip_slow_tests() {

0 commit comments

Comments
 (0)