@@ -15,7 +15,7 @@ use span::{FIXUP_ERASED_FILE_AST_ID_MARKER, Span, TextRange, TextSize};
1515
1616use crate :: {
1717 ProcMacroClientHandle ,
18- bridge:: { Diagnostic , ExpnGlobals , Literal , TokenTree } ,
18+ bridge:: { Diagnostic , ExpnGlobals , Literal } ,
1919 server_impl:: literal_from_str,
2020} ;
2121
@@ -30,8 +30,10 @@ pub struct RaSpanServer<'a> {
3030 pub callback : Option < ProcMacroClientHandle < ' a > > ,
3131}
3232
33+ type TokenStream = crate :: token_stream:: TokenStream < Span > ;
34+ type BridgeTokenStream = crate :: bridge:: TokenStream < Span > ;
35+
3336impl server:: Server for RaSpanServer < ' _ > {
34- type TokenStream = crate :: token_stream:: TokenStream < Span > ;
3537 type Span = Span ;
3638 type Symbol = Symbol ;
3739
@@ -70,73 +72,26 @@ impl server::Server for RaSpanServer<'_> {
7072 // FIXME handle diagnostic
7173 }
7274
73- fn ts_drop ( & mut self , stream : Self :: TokenStream ) {
74- drop ( stream) ;
75- }
76-
77- fn ts_clone ( & mut self , stream : & Self :: TokenStream ) -> Self :: TokenStream {
78- stream. clone ( )
79- }
80-
81- fn ts_is_empty ( & mut self , stream : & Self :: TokenStream ) -> bool {
82- stream. is_empty ( )
83- }
84- fn ts_from_str ( & mut self , src : & str ) -> Self :: TokenStream {
85- Self :: TokenStream :: from_str ( src, self . call_site ) . unwrap_or_else ( |e| {
86- Self :: TokenStream :: from_str (
75+ fn ts_from_str ( & mut self , src : & str ) -> BridgeTokenStream {
76+ TokenStream :: from_str ( src, self . call_site ) . unwrap_or_else ( |e| {
77+ TokenStream :: from_str (
8778 & format ! ( "compile_error!(\" failed to parse str to token stream: {e}\" )" ) ,
8879 self . call_site ,
8980 )
9081 . unwrap ( )
91- } )
82+ } ) . into_bridge ( )
9283 }
93- fn ts_to_string ( & mut self , stream : & Self :: TokenStream ) -> String {
94- stream. to_string ( )
84+ fn ts_to_string ( & mut self , stream : BridgeTokenStream ) -> String {
85+ TokenStream :: from_bridge ( stream) . to_string ( )
9586 }
9687
97- fn ts_from_token_tree ( & mut self , tree : TokenTree < Self :: Span > ) -> Self :: TokenStream {
98- Self :: TokenStream :: new ( vec ! [ tree] )
99- }
100-
101- fn ts_expand_expr ( & mut self , self_ : & Self :: TokenStream ) -> Result < Self :: TokenStream , ( ) > {
88+ fn ts_expand_expr ( & mut self , self_ : BridgeTokenStream ) -> Result < BridgeTokenStream , ( ) > {
10289 // FIXME: requires db, more importantly this requires name resolution so we would need to
10390 // eagerly expand this proc-macro, but we can't know that this proc-macro is eager until we
10491 // expand it ...
10592 // This calls for some kind of marker that a proc-macro wants to access this eager API,
10693 // otherwise we need to treat every proc-macro eagerly / or not support this.
107- Ok ( self_. clone ( ) )
108- }
109-
110- fn ts_concat_trees (
111- & mut self ,
112- base : Option < Self :: TokenStream > ,
113- trees : Vec < TokenTree < Self :: Span > > ,
114- ) -> Self :: TokenStream {
115- match base {
116- Some ( mut base) => {
117- for tt in trees {
118- base. push_tree ( tt) ;
119- }
120- base
121- }
122- None => Self :: TokenStream :: new ( trees) ,
123- }
124- }
125-
126- fn ts_concat_streams (
127- & mut self ,
128- base : Option < Self :: TokenStream > ,
129- streams : Vec < Self :: TokenStream > ,
130- ) -> Self :: TokenStream {
131- let mut stream = base. unwrap_or_default ( ) ;
132- for s in streams {
133- stream. push_stream ( s) ;
134- }
135- stream
136- }
137-
138- fn ts_into_trees ( & mut self , stream : Self :: TokenStream ) -> Vec < TokenTree < Self :: Span > > {
139- ( * stream. 0 ) . clone ( )
94+ Ok ( self_)
14095 }
14196
14297 fn span_debug ( & mut self , span : Self :: Span ) -> String {
0 commit comments