diff --git a/src/tools/rust-analyzer/crates/proc-macro-api/src/bidirectional_protocol.rs b/src/tools/rust-analyzer/crates/proc-macro-api/src/bidirectional_protocol.rs index 25266c46fe89..b5f43e1d3726 100644 --- a/src/tools/rust-analyzer/crates/proc-macro-api/src/bidirectional_protocol.rs +++ b/src/tools/rust-analyzer/crates/proc-macro-api/src/bidirectional_protocol.rs @@ -182,7 +182,7 @@ pub(crate) fn expand( BidirectionalMessage::Response(Response::ExpandMacro(it)) => Ok(it .map(|tree| { let mut expanded = FlatTree::to_subtree_resolved(tree, version, &span_data_table); - if proc_macro.needs_fixup_change(process) { + if proc_macro.needs_fixup_change() { proc_macro.change_fixup_to_match_old_server(&mut expanded); } expanded @@ -195,7 +195,7 @@ pub(crate) fn expand( version, &deserialize_span_data_index_map(&resp.span_data_table), ); - if proc_macro.needs_fixup_change(process) { + if proc_macro.needs_fixup_change() { proc_macro.change_fixup_to_match_old_server(&mut expanded); } expanded diff --git a/src/tools/rust-analyzer/crates/proc-macro-api/src/legacy_protocol.rs b/src/tools/rust-analyzer/crates/proc-macro-api/src/legacy_protocol.rs index 412d20730324..eedf66d46086 100644 --- a/src/tools/rust-analyzer/crates/proc-macro-api/src/legacy_protocol.rs +++ b/src/tools/rust-analyzer/crates/proc-macro-api/src/legacy_protocol.rs @@ -120,7 +120,7 @@ pub(crate) fn expand( Response::ExpandMacro(it) => Ok(it .map(|tree| { let mut expanded = FlatTree::to_subtree_resolved(tree, version, &span_data_table); - if proc_macro.needs_fixup_change(process) { + if proc_macro.needs_fixup_change() { proc_macro.change_fixup_to_match_old_server(&mut expanded); } expanded @@ -133,7 +133,7 @@ pub(crate) fn expand( version, &deserialize_span_data_index_map(&resp.span_data_table), ); - if proc_macro.needs_fixup_change(process) { + if proc_macro.needs_fixup_change() { proc_macro.change_fixup_to_match_old_server(&mut expanded); } expanded diff --git a/src/tools/rust-analyzer/crates/proc-macro-api/src/lib.rs b/src/tools/rust-analyzer/crates/proc-macro-api/src/lib.rs index 09999ea5081a..4874e63244c4 100644 --- a/src/tools/rust-analyzer/crates/proc-macro-api/src/lib.rs +++ b/src/tools/rust-analyzer/crates/proc-macro-api/src/lib.rs @@ -209,8 +209,8 @@ impl ProcMacro { self.kind } - fn needs_fixup_change(&self, process: &ProcMacroServerProcess) -> bool { - let version = process.version(); + fn needs_fixup_change(&self) -> bool { + let version = self.pool.version(); (version::RUST_ANALYZER_SPAN_SUPPORT..version::HASHED_AST_ID).contains(&version) } @@ -240,6 +240,20 @@ impl ProcMacro { current_dir: String, callback: Option>, ) -> Result, ServerError> { + let (mut subtree, mut attr) = (subtree, attr); + let (mut subtree_changed, mut attr_changed); + if self.needs_fixup_change() { + subtree_changed = tt::TopSubtree::from_subtree(subtree); + self.change_fixup_to_match_old_server(&mut subtree_changed); + subtree = subtree_changed.view(); + + if let Some(attr) = &mut attr { + attr_changed = tt::TopSubtree::from_subtree(*attr); + self.change_fixup_to_match_old_server(&mut attr_changed); + *attr = attr_changed.view(); + } + } + self.pool.expand( self, subtree, diff --git a/src/tools/rust-analyzer/crates/proc-macro-api/src/pool.rs b/src/tools/rust-analyzer/crates/proc-macro-api/src/pool.rs index c75e9742a5d1..fd8b726f820e 100644 --- a/src/tools/rust-analyzer/crates/proc-macro-api/src/pool.rs +++ b/src/tools/rust-analyzer/crates/proc-macro-api/src/pool.rs @@ -1,4 +1,4 @@ -//! This module represents Process Pool +//! A pool of proc-macro server processes use std::sync::Arc; use tt::Span; @@ -11,11 +11,13 @@ use crate::{ #[derive(Debug, Clone)] pub(crate) struct ProcMacroServerPool { workers: Arc<[ProcMacroServerProcess]>, + version: u32, } impl ProcMacroServerPool { pub(crate) fn new(workers: Vec) -> Self { - Self { workers: workers.into() } + let version = workers[0].version(); + Self { workers: workers.into(), version } } } @@ -87,20 +89,6 @@ impl ProcMacroServerPool { ) -> Result, ServerError> { let process = self.pick_process()?; - let (mut subtree, mut attr) = (subtree, attr); - let (mut subtree_changed, mut attr_changed); - if proc_macro.needs_fixup_change(process) { - subtree_changed = tt::TopSubtree::from_subtree(subtree); - proc_macro.change_fixup_to_match_old_server(&mut subtree_changed); - subtree = subtree_changed.view(); - - if let Some(attr) = &mut attr { - attr_changed = tt::TopSubtree::from_subtree(*attr); - proc_macro.change_fixup_to_match_old_server(&mut attr_changed); - *attr = attr_changed.view(); - } - } - process.expand( proc_macro, subtree, @@ -113,6 +101,10 @@ impl ProcMacroServerPool { callback, ) } + + pub(crate) fn version(&self) -> u32 { + self.version + } } pub(crate) fn default_pool_size() -> usize {