rename handler's to be context specific

This commit is contained in:
bit-aloo 2025-12-27 09:21:32 +05:30
parent 91b5c3c664
commit 76ea9828a7
No known key found for this signature in database
6 changed files with 18 additions and 18 deletions

View File

@ -169,12 +169,12 @@ fn handle_expand_id<W: std::io::Write, C: Codec>(
send_response::<_, C>(stdout, bidirectional::Response::ExpandMacro(res))
}
struct BidirectionalProxy {
struct ProcMacroClientHandle {
subreq_tx: mpsc::Sender<bidirectional::SubRequest>,
subresp_rx: mpsc::Receiver<bidirectional::SubResponse>,
}
impl proc_macro_srv::BidirectionalHandler for BidirectionalProxy {
impl proc_macro_srv::ProcMacroClientInterface for ProcMacroClientHandle {
fn source_text(&mut self, file_id: u32, start: u32, end: u32) -> Option<String> {
self.subreq_tx.send(bidirectional::SubRequest::SourceText { file_id, start, end }).ok()?;
@ -228,7 +228,7 @@ fn handle_expand_ra<W: io::Write, R: io::BufRead, C: Codec>(
std::thread::scope(|s| {
s.spawn(|| {
let callback = BidirectionalProxy { subreq_tx, subresp_rx };
let callback = ProcMacroClientHandle { subreq_tx, subresp_rx };
let res = srv
.expand(

View File

@ -12,8 +12,8 @@ use object::Object;
use paths::{Utf8Path, Utf8PathBuf};
use crate::{
PanicMessage, ProcMacroKind, ProcMacroSrvSpan, SubCallback, dylib::proc_macros::ProcMacros,
token_stream::TokenStream,
PanicMessage, ProcMacroClientHandle, ProcMacroKind, ProcMacroSrvSpan,
dylib::proc_macros::ProcMacros, token_stream::TokenStream,
};
pub(crate) struct Expander {
@ -45,7 +45,7 @@ impl Expander {
def_site: S,
call_site: S,
mixed_site: S,
callback: Option<SubCallback>,
callback: Option<ProcMacroClientHandle>,
) -> Result<TokenStream<S>, PanicMessage>
where
<S::Server as bridge::server::Types>::TokenStream: Default,

View File

@ -1,5 +1,5 @@
//! Proc macro ABI
use crate::{ProcMacroKind, ProcMacroSrvSpan, SubCallback, token_stream::TokenStream};
use crate::{ProcMacroClientHandle, ProcMacroKind, ProcMacroSrvSpan, token_stream::TokenStream};
use proc_macro::bridge;
#[repr(transparent)]
@ -20,7 +20,7 @@ impl ProcMacros {
def_site: S,
call_site: S,
mixed_site: S,
callback: Option<SubCallback>,
callback: Option<ProcMacroClientHandle>,
) -> Result<TokenStream<S>, crate::PanicMessage> {
let parsed_attributes = attribute.unwrap_or_default();

View File

@ -91,9 +91,9 @@ impl<'env> ProcMacroSrv<'env> {
}
}
pub type SubCallback = Box<dyn BidirectionalHandler + Send>;
pub type ProcMacroClientHandle = Box<dyn ProcMacroClientInterface + Send>;
pub trait BidirectionalHandler {
pub trait ProcMacroClientInterface {
fn source_text(&mut self, file_id: u32, start: u32, end: u32) -> Option<String>;
}
@ -111,7 +111,7 @@ impl ProcMacroSrv<'_> {
def_site: S,
call_site: S,
mixed_site: S,
callback: Option<SubCallback>,
callback: Option<ProcMacroClientHandle>,
) -> Result<token_stream::TokenStream<S>, PanicMessage> {
let snapped_env = self.env;
let expander = self.expander(lib.as_ref()).map_err(|err| PanicMessage {
@ -183,7 +183,7 @@ pub trait ProcMacroSrvSpan: Copy + Send + Sync {
call_site: Self,
def_site: Self,
mixed_site: Self,
callback: Option<SubCallback>,
callback: Option<ProcMacroClientHandle>,
) -> Self::Server;
}
@ -194,7 +194,7 @@ impl ProcMacroSrvSpan for SpanId {
call_site: Self,
def_site: Self,
mixed_site: Self,
callback: Option<SubCallback>,
callback: Option<ProcMacroClientHandle>,
) -> Self::Server {
Self::Server {
call_site,
@ -213,7 +213,7 @@ impl ProcMacroSrvSpan for Span {
call_site: Self,
def_site: Self,
mixed_site: Self,
callback: Option<SubCallback>,
callback: Option<ProcMacroClientHandle>,
) -> Self::Server {
Self::Server {
call_site,

View File

@ -14,7 +14,7 @@ use proc_macro::bridge::server;
use span::{FIXUP_ERASED_FILE_AST_ID_MARKER, Span, TextRange, TextSize};
use crate::{
SubCallback,
ProcMacroClientHandle,
bridge::{Diagnostic, ExpnGlobals, Literal, TokenTree},
server_impl::literal_from_str,
};
@ -29,7 +29,7 @@ pub struct RaSpanServer {
pub call_site: Span,
pub def_site: Span,
pub mixed_site: Span,
pub callback: Option<SubCallback>,
pub callback: Option<ProcMacroClientHandle>,
}
impl server::Types for RaSpanServer {

View File

@ -9,7 +9,7 @@ use intern::Symbol;
use proc_macro::bridge::server;
use crate::{
SubCallback,
ProcMacroClientHandle,
bridge::{Diagnostic, ExpnGlobals, Literal, TokenTree},
server_impl::literal_from_str,
};
@ -35,7 +35,7 @@ pub struct SpanIdServer {
pub call_site: Span,
pub def_site: Span,
pub mixed_site: Span,
pub callback: Option<SubCallback>,
pub callback: Option<ProcMacroClientHandle>,
}
impl server::Types for SpanIdServer {