add version to pool

This commit is contained in:
bit-aloo 2026-01-04 05:02:15 +05:30
parent 09c91b79a8
commit 0936597b3e
No known key found for this signature in database
4 changed files with 28 additions and 22 deletions

View file

@ -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

View file

@ -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

View file

@ -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,

View file

@ -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 {