attach lifetime to ProcMacroClientHandle and make necessary changes to proc-macro-srv
This commit is contained in:
parent
d494dbcf97
commit
462b4a02cf
5 changed files with 38 additions and 36 deletions
|
|
@ -37,7 +37,7 @@ impl Expander {
|
|||
Ok(Expander { inner: library, modified_time })
|
||||
}
|
||||
|
||||
pub(crate) fn expand<S: ProcMacroSrvSpan>(
|
||||
pub(crate) fn expand<'a, S: ProcMacroSrvSpan>(
|
||||
&self,
|
||||
macro_name: &str,
|
||||
macro_body: TokenStream<S>,
|
||||
|
|
@ -45,10 +45,10 @@ impl Expander {
|
|||
def_site: S,
|
||||
call_site: S,
|
||||
mixed_site: S,
|
||||
callback: Option<ProcMacroClientHandle>,
|
||||
callback: Option<ProcMacroClientHandle<'_>>,
|
||||
) -> Result<TokenStream<S>, PanicMessage>
|
||||
where
|
||||
<S::Server as bridge::server::Types>::TokenStream: Default,
|
||||
<S::Server<'a> as bridge::server::Types>::TokenStream: Default,
|
||||
{
|
||||
self.inner
|
||||
.proc_macros
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ impl ProcMacros {
|
|||
def_site: S,
|
||||
call_site: S,
|
||||
mixed_site: S,
|
||||
callback: Option<ProcMacroClientHandle>,
|
||||
callback: Option<ProcMacroClientHandle<'_>>,
|
||||
) -> Result<TokenStream<S>, crate::PanicMessage> {
|
||||
let parsed_attributes = attribute.unwrap_or_default();
|
||||
|
||||
|
|
|
|||
|
|
@ -91,10 +91,10 @@ impl<'env> ProcMacroSrv<'env> {
|
|||
}
|
||||
}
|
||||
|
||||
pub type ProcMacroClientHandle = Box<dyn ProcMacroClientInterface + Send>;
|
||||
pub type ProcMacroClientHandle<'a> = Box<dyn ProcMacroClientInterface + Send + 'a>;
|
||||
|
||||
pub trait ProcMacroClientInterface {
|
||||
fn source_text(&self, file_id: u32, start: u32, end: u32) -> Option<String>;
|
||||
fn source_text(&mut self, file_id: u32, start: u32, end: u32) -> Option<String>;
|
||||
}
|
||||
|
||||
const EXPANDER_STACK_SIZE: usize = 8 * 1024 * 1024;
|
||||
|
|
@ -111,7 +111,7 @@ impl ProcMacroSrv<'_> {
|
|||
def_site: S,
|
||||
call_site: S,
|
||||
mixed_site: S,
|
||||
callback: Option<ProcMacroClientHandle>,
|
||||
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 {
|
||||
|
|
@ -178,24 +178,26 @@ impl ProcMacroSrv<'_> {
|
|||
}
|
||||
|
||||
pub trait ProcMacroSrvSpan: Copy + Send + Sync {
|
||||
type Server: proc_macro::bridge::server::Server<TokenStream = crate::token_stream::TokenStream<Self>>;
|
||||
fn make_server(
|
||||
type Server<'a>: proc_macro::bridge::server::Server<TokenStream = crate::token_stream::TokenStream<Self>>
|
||||
where
|
||||
Self: 'a;
|
||||
fn make_server<'a>(
|
||||
call_site: Self,
|
||||
def_site: Self,
|
||||
mixed_site: Self,
|
||||
callback: Option<ProcMacroClientHandle>,
|
||||
) -> Self::Server;
|
||||
callback: Option<ProcMacroClientHandle<'a>>,
|
||||
) -> Self::Server<'a>;
|
||||
}
|
||||
|
||||
impl ProcMacroSrvSpan for SpanId {
|
||||
type Server = server_impl::token_id::SpanIdServer;
|
||||
type Server<'a> = server_impl::token_id::SpanIdServer<'a>;
|
||||
|
||||
fn make_server(
|
||||
fn make_server<'a>(
|
||||
call_site: Self,
|
||||
def_site: Self,
|
||||
mixed_site: Self,
|
||||
callback: Option<ProcMacroClientHandle>,
|
||||
) -> Self::Server {
|
||||
callback: Option<ProcMacroClientHandle<'a>>,
|
||||
) -> Self::Server<'a> {
|
||||
Self::Server {
|
||||
call_site,
|
||||
def_site,
|
||||
|
|
@ -208,13 +210,13 @@ impl ProcMacroSrvSpan for SpanId {
|
|||
}
|
||||
|
||||
impl ProcMacroSrvSpan for Span {
|
||||
type Server = server_impl::rust_analyzer_span::RaSpanServer;
|
||||
fn make_server(
|
||||
type Server<'a> = server_impl::rust_analyzer_span::RaSpanServer<'a>;
|
||||
fn make_server<'a>(
|
||||
call_site: Self,
|
||||
def_site: Self,
|
||||
mixed_site: Self,
|
||||
callback: Option<ProcMacroClientHandle>,
|
||||
) -> Self::Server {
|
||||
callback: Option<ProcMacroClientHandle<'a>>,
|
||||
) -> Self::Server<'a> {
|
||||
Self::Server {
|
||||
call_site,
|
||||
def_site,
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ use crate::{
|
|||
|
||||
pub struct FreeFunctions;
|
||||
|
||||
pub struct RaSpanServer {
|
||||
pub struct RaSpanServer<'a> {
|
||||
// FIXME: Report this back to the caller to track as dependencies
|
||||
pub tracked_env_vars: HashMap<Box<str>, Option<Box<str>>>,
|
||||
// FIXME: Report this back to the caller to track as dependencies
|
||||
|
|
@ -29,17 +29,17 @@ pub struct RaSpanServer {
|
|||
pub call_site: Span,
|
||||
pub def_site: Span,
|
||||
pub mixed_site: Span,
|
||||
pub callback: Option<ProcMacroClientHandle>,
|
||||
pub callback: Option<ProcMacroClientHandle<'a>>,
|
||||
}
|
||||
|
||||
impl server::Types for RaSpanServer {
|
||||
impl server::Types for RaSpanServer<'_> {
|
||||
type FreeFunctions = FreeFunctions;
|
||||
type TokenStream = crate::token_stream::TokenStream<Span>;
|
||||
type Span = Span;
|
||||
type Symbol = Symbol;
|
||||
}
|
||||
|
||||
impl server::FreeFunctions for RaSpanServer {
|
||||
impl server::FreeFunctions for RaSpanServer<'_> {
|
||||
fn injected_env_var(&mut self, _: &str) -> Option<std::string::String> {
|
||||
None
|
||||
}
|
||||
|
|
@ -60,7 +60,7 @@ impl server::FreeFunctions for RaSpanServer {
|
|||
}
|
||||
}
|
||||
|
||||
impl server::TokenStream for RaSpanServer {
|
||||
impl server::TokenStream for RaSpanServer<'_> {
|
||||
fn is_empty(&mut self, stream: &Self::TokenStream) -> bool {
|
||||
stream.is_empty()
|
||||
}
|
||||
|
|
@ -123,7 +123,7 @@ impl server::TokenStream for RaSpanServer {
|
|||
}
|
||||
}
|
||||
|
||||
impl server::Span for RaSpanServer {
|
||||
impl server::Span for RaSpanServer<'_> {
|
||||
fn debug(&mut self, span: Self::Span) -> String {
|
||||
format!("{:?}", span)
|
||||
}
|
||||
|
|
@ -156,7 +156,7 @@ impl server::Span for RaSpanServer {
|
|||
let start: u32 = span.range.start().into();
|
||||
let end: u32 = span.range.end().into();
|
||||
|
||||
self.callback.as_ref()?.source_text(file_id.file_id().index(), start, end)
|
||||
self.callback.as_mut()?.source_text(file_id.file_id().index(), start, end)
|
||||
}
|
||||
|
||||
fn parent(&mut self, _span: Self::Span) -> Option<Self::Span> {
|
||||
|
|
@ -274,14 +274,14 @@ impl server::Span for RaSpanServer {
|
|||
}
|
||||
}
|
||||
|
||||
impl server::Symbol for RaSpanServer {
|
||||
impl server::Symbol for RaSpanServer<'_> {
|
||||
fn normalize_and_validate_ident(&mut self, string: &str) -> Result<Self::Symbol, ()> {
|
||||
// FIXME: nfc-normalize and validate idents
|
||||
Ok(<Self as server::Server>::intern_symbol(string))
|
||||
}
|
||||
}
|
||||
|
||||
impl server::Server for RaSpanServer {
|
||||
impl server::Server for RaSpanServer<'_> {
|
||||
fn globals(&mut self) -> ExpnGlobals<Self::Span> {
|
||||
ExpnGlobals {
|
||||
def_site: self.def_site,
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ type Span = SpanId;
|
|||
|
||||
pub struct FreeFunctions;
|
||||
|
||||
pub struct SpanIdServer {
|
||||
pub struct SpanIdServer<'a> {
|
||||
// FIXME: Report this back to the caller to track as dependencies
|
||||
pub tracked_env_vars: HashMap<Box<str>, Option<Box<str>>>,
|
||||
// FIXME: Report this back to the caller to track as dependencies
|
||||
|
|
@ -35,17 +35,17 @@ pub struct SpanIdServer {
|
|||
pub call_site: Span,
|
||||
pub def_site: Span,
|
||||
pub mixed_site: Span,
|
||||
pub callback: Option<ProcMacroClientHandle>,
|
||||
pub callback: Option<ProcMacroClientHandle<'a>>,
|
||||
}
|
||||
|
||||
impl server::Types for SpanIdServer {
|
||||
impl server::Types for SpanIdServer<'_> {
|
||||
type FreeFunctions = FreeFunctions;
|
||||
type TokenStream = crate::token_stream::TokenStream<Span>;
|
||||
type Span = Span;
|
||||
type Symbol = Symbol;
|
||||
}
|
||||
|
||||
impl server::FreeFunctions for SpanIdServer {
|
||||
impl server::FreeFunctions for SpanIdServer<'_> {
|
||||
fn injected_env_var(&mut self, _: &str) -> Option<std::string::String> {
|
||||
None
|
||||
}
|
||||
|
|
@ -63,7 +63,7 @@ impl server::FreeFunctions for SpanIdServer {
|
|||
fn emit_diagnostic(&mut self, _: Diagnostic<Self::Span>) {}
|
||||
}
|
||||
|
||||
impl server::TokenStream for SpanIdServer {
|
||||
impl server::TokenStream for SpanIdServer<'_> {
|
||||
fn is_empty(&mut self, stream: &Self::TokenStream) -> bool {
|
||||
stream.is_empty()
|
||||
}
|
||||
|
|
@ -120,7 +120,7 @@ impl server::TokenStream for SpanIdServer {
|
|||
}
|
||||
}
|
||||
|
||||
impl server::Span for SpanIdServer {
|
||||
impl server::Span for SpanIdServer<'_> {
|
||||
fn debug(&mut self, span: Self::Span) -> String {
|
||||
format!("{:?}", span.0)
|
||||
}
|
||||
|
|
@ -187,14 +187,14 @@ impl server::Span for SpanIdServer {
|
|||
}
|
||||
}
|
||||
|
||||
impl server::Symbol for SpanIdServer {
|
||||
impl server::Symbol for SpanIdServer<'_> {
|
||||
fn normalize_and_validate_ident(&mut self, string: &str) -> Result<Self::Symbol, ()> {
|
||||
// FIXME: nfc-normalize and validate idents
|
||||
Ok(<Self as server::Server>::intern_symbol(string))
|
||||
}
|
||||
}
|
||||
|
||||
impl server::Server for SpanIdServer {
|
||||
impl server::Server for SpanIdServer<'_> {
|
||||
fn globals(&mut self) -> ExpnGlobals<Self::Span> {
|
||||
ExpnGlobals {
|
||||
def_site: self.def_site,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue