add byte range to main loop and direct the request via callback and define the callback on client side

This commit is contained in:
bit-aloo 2026-01-07 17:20:37 +05:30
parent e909b4b282
commit e68a654dca
No known key found for this signature in database
2 changed files with 28 additions and 1 deletions

View file

@ -591,6 +591,16 @@ impl ProcMacroExpander for Expander {
Ok(SubResponse::FilePathResult { name })
}
SubRequest::ByteRange { file_id, ast_id, start, end } => {
let range = resolve_sub_span(
db,
file_id,
ast_id,
TextRange::new(TextSize::from(start), TextSize::from(end)),
);
Ok(SubResponse::ByteRangeResult { range: range.range.into() })
}
};
match self.0.expand(
subtree.view(),

View file

@ -6,7 +6,7 @@ use proc_macro_api::{
transport::codec::{json::JsonProtocol, postcard::PostcardProtocol},
version::CURRENT_API_VERSION,
};
use std::io::{self, BufRead, Write};
use std::{io, ops::Range};
use legacy::Message;
@ -240,6 +240,23 @@ impl<C: Codec> proc_macro_srv::ProcMacroClientInterface for ProcMacroClientHandl
_ => None,
}
}
fn byte_range(
&mut self,
proc_macro_srv::span::Span { range, anchor, ctx: _ }: proc_macro_srv::span::Span,
) -> Range<usize> {
match self.roundtrip(bidirectional::SubRequest::ByteRange {
file_id: anchor.file_id.as_u32(),
ast_id: anchor.ast_id.into_raw(),
start: range.start().into(),
end: range.end().into(),
}) {
Some(bidirectional::BidirectionalMessage::SubResponse(
bidirectional::SubResponse::ByteRangeResult { range },
)) => range,
_ => Range { start: range.start().into(), end: range.end().into() },
}
}
}
fn handle_expand_ra<C: Codec>(