Unnamed repository; edit this file 'description' to name the repository.
add version to pool
bit-aloo 3 months ago
parent d905d0f · commit 19a2994
-rw-r--r--crates/proc-macro-api/src/bidirectional_protocol.rs4
-rw-r--r--crates/proc-macro-api/src/legacy_protocol.rs4
-rw-r--r--crates/proc-macro-api/src/lib.rs18
-rw-r--r--crates/proc-macro-api/src/pool.rs24
4 files changed, 28 insertions, 22 deletions
diff --git a/crates/proc-macro-api/src/bidirectional_protocol.rs b/crates/proc-macro-api/src/bidirectional_protocol.rs
index 25266c46fe..b5f43e1d37 100644
--- a/crates/proc-macro-api/src/bidirectional_protocol.rs
+++ b/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/crates/proc-macro-api/src/legacy_protocol.rs b/crates/proc-macro-api/src/legacy_protocol.rs
index 412d207303..eedf66d460 100644
--- a/crates/proc-macro-api/src/legacy_protocol.rs
+++ b/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/crates/proc-macro-api/src/lib.rs b/crates/proc-macro-api/src/lib.rs
index 09999ea508..4874e63244 100644
--- a/crates/proc-macro-api/src/lib.rs
+++ b/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<SubCallback<'_>>,
) -> Result<Result<tt::TopSubtree, String>, 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/crates/proc-macro-api/src/pool.rs b/crates/proc-macro-api/src/pool.rs
index c75e9742a5..fd8b726f82 100644
--- a/crates/proc-macro-api/src/pool.rs
+++ b/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<ProcMacroServerProcess>) -> Self {
- Self { workers: workers.into() }
+ let version = workers[0].version();
+ Self { workers: workers.into(), version }
}
}
@@ -87,20 +89,6 @@ impl ProcMacroServerPool {
) -> Result<Result<tt::TopSubtree, String>, 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 {