11//! The main loop of the proc-macro server.
22use proc_macro_api:: {
3- Codec , ProtocolFormat ,
4- bidirectional_protocol:: msg as bidirectional,
5- legacy_protocol:: msg as legacy,
6- transport:: codec:: { json:: JsonProtocol , postcard:: PostcardProtocol } ,
3+ ProtocolFormat , bidirectional_protocol:: msg as bidirectional, legacy_protocol:: msg as legacy,
74 version:: CURRENT_API_VERSION ,
85} ;
96use std:: {
@@ -40,14 +37,12 @@ pub fn run(
4037 format : ProtocolFormat ,
4138) -> io:: Result < ( ) > {
4239 match format {
43- ProtocolFormat :: JsonLegacy => run_old :: < JsonProtocol > ( stdin, stdout) ,
44- ProtocolFormat :: BidirectionalPostcardPrototype => {
45- run_new :: < PostcardProtocol > ( stdin, stdout)
46- }
40+ ProtocolFormat :: JsonLegacy => run_old ( stdin, stdout) ,
41+ ProtocolFormat :: BidirectionalPostcardPrototype => run_new ( stdin, stdout) ,
4742 }
4843}
4944
50- fn run_new < C : Codec > (
45+ fn run_new (
5146 stdin : & mut ( dyn BufRead + Send + Sync ) ,
5247 stdout : & mut ( dyn Write + Send + Sync ) ,
5348) -> io:: Result < ( ) > {
@@ -61,15 +56,15 @@ fn run_new<C: Codec>(
6156 }
6257 }
6358
64- let mut buf = C :: Buf :: default ( ) ;
59+ let mut buf = Vec :: default ( ) ;
6560
6661 let env_snapshot = EnvSnapshot :: default ( ) ;
6762 let srv = proc_macro_srv:: ProcMacroSrv :: new ( & env_snapshot) ;
6863
6964 let mut span_mode = legacy:: SpanMode :: Id ;
7065
7166 ' outer: loop {
72- let req_opt = bidirectional:: BidirectionalMessage :: read :: < C > ( stdin, & mut buf) ?;
67+ let req_opt = bidirectional:: BidirectionalMessage :: read ( stdin, & mut buf) ?;
7368 let Some ( req) = req_opt else {
7469 break ' outer;
7570 } ;
@@ -84,22 +79,22 @@ fn run_new<C: Codec>(
8479 . collect ( )
8580 } ) ;
8681
87- send_response :: < C > ( stdout, bidirectional:: Response :: ListMacros ( res) ) ?;
82+ send_response ( stdout, bidirectional:: Response :: ListMacros ( res) ) ?;
8883 }
8984
9085 bidirectional:: Request :: ApiVersionCheck { } => {
91- send_response :: < C > (
86+ send_response (
9287 stdout,
9388 bidirectional:: Response :: ApiVersionCheck ( CURRENT_API_VERSION ) ,
9489 ) ?;
9590 }
9691
9792 bidirectional:: Request :: SetConfig ( config) => {
9893 span_mode = config. span_mode ;
99- send_response :: < C > ( stdout, bidirectional:: Response :: SetConfig ( config) ) ?;
94+ send_response ( stdout, bidirectional:: Response :: SetConfig ( config) ) ?;
10095 }
10196 bidirectional:: Request :: ExpandMacro ( task) => {
102- handle_expand :: < C > ( & srv, stdin, stdout, & mut buf, span_mode, * task) ?;
97+ handle_expand ( & srv, stdin, stdout, & mut buf, span_mode, * task) ?;
10398 }
10499 } ,
105100 _ => continue ,
@@ -109,21 +104,21 @@ fn run_new<C: Codec>(
109104 Ok ( ( ) )
110105}
111106
112- fn handle_expand < C : Codec > (
107+ fn handle_expand (
113108 srv : & proc_macro_srv:: ProcMacroSrv < ' _ > ,
114109 stdin : & mut ( dyn BufRead + Send + Sync ) ,
115110 stdout : & mut ( dyn Write + Send + Sync ) ,
116- buf : & mut C :: Buf ,
111+ buf : & mut Vec < u8 > ,
117112 span_mode : legacy:: SpanMode ,
118113 task : bidirectional:: ExpandMacro ,
119114) -> io:: Result < ( ) > {
120115 match span_mode {
121- legacy:: SpanMode :: Id => handle_expand_id :: < C > ( srv, stdout, task) ,
122- legacy:: SpanMode :: RustAnalyzer => handle_expand_ra :: < C > ( srv, stdin, stdout, buf, task) ,
116+ legacy:: SpanMode :: Id => handle_expand_id ( srv, stdout, task) ,
117+ legacy:: SpanMode :: RustAnalyzer => handle_expand_ra ( srv, stdin, stdout, buf, task) ,
123118 }
124119}
125120
126- fn handle_expand_id < C : Codec > (
121+ fn handle_expand_id (
127122 srv : & proc_macro_srv:: ProcMacroSrv < ' _ > ,
128123 stdout : & mut dyn Write ,
129124 task : bidirectional:: ExpandMacro ,
@@ -164,34 +159,34 @@ fn handle_expand_id<C: Codec>(
164159 } )
165160 . map_err ( |e| legacy:: PanicMessage ( e. into_string ( ) . unwrap_or_default ( ) ) ) ;
166161
167- send_response :: < C > ( stdout, bidirectional:: Response :: ExpandMacro ( res) )
162+ send_response ( stdout, bidirectional:: Response :: ExpandMacro ( res) )
168163}
169164
170- struct ProcMacroClientHandle < ' a , C : Codec > {
165+ struct ProcMacroClientHandle < ' a > {
171166 stdin : & ' a mut ( dyn BufRead + Send + Sync ) ,
172167 stdout : & ' a mut ( dyn Write + Send + Sync ) ,
173- buf : & ' a mut C :: Buf ,
168+ buf : & ' a mut Vec < u8 > ,
174169}
175170
176- impl < ' a , C : Codec > ProcMacroClientHandle < ' a , C > {
171+ impl < ' a > ProcMacroClientHandle < ' a > {
177172 fn roundtrip (
178173 & mut self ,
179174 req : bidirectional:: SubRequest ,
180175 ) -> Option < bidirectional:: BidirectionalMessage > {
181176 let msg = bidirectional:: BidirectionalMessage :: SubRequest ( req) ;
182177
183- if msg. write :: < C > ( & mut * self . stdout ) . is_err ( ) {
178+ if msg. write ( & mut * self . stdout ) . is_err ( ) {
184179 return None ;
185180 }
186181
187- match bidirectional:: BidirectionalMessage :: read :: < C > ( & mut * self . stdin , self . buf ) {
182+ match bidirectional:: BidirectionalMessage :: read ( & mut * self . stdin , self . buf ) {
188183 Ok ( Some ( msg) ) => Some ( msg) ,
189184 _ => None ,
190185 }
191186 }
192187}
193188
194- impl < C : Codec > proc_macro_srv:: ProcMacroClientInterface for ProcMacroClientHandle < ' _ , C > {
189+ impl proc_macro_srv:: ProcMacroClientInterface for ProcMacroClientHandle < ' _ > {
195190 fn file ( & mut self , file_id : proc_macro_srv:: span:: FileId ) -> String {
196191 match self . roundtrip ( bidirectional:: SubRequest :: FilePath { file_id : file_id. index ( ) } ) {
197192 Some ( bidirectional:: BidirectionalMessage :: SubResponse (
@@ -260,11 +255,11 @@ impl<C: Codec> proc_macro_srv::ProcMacroClientInterface for ProcMacroClientHandl
260255 }
261256}
262257
263- fn handle_expand_ra < C : Codec > (
258+ fn handle_expand_ra (
264259 srv : & proc_macro_srv:: ProcMacroSrv < ' _ > ,
265260 stdin : & mut ( dyn BufRead + Send + Sync ) ,
266261 stdout : & mut ( dyn Write + Send + Sync ) ,
267- buf : & mut C :: Buf ,
262+ buf : & mut Vec < u8 > ,
268263 task : bidirectional:: ExpandMacro ,
269264) -> io:: Result < ( ) > {
270265 let bidirectional:: ExpandMacro {
@@ -309,7 +304,7 @@ fn handle_expand_ra<C: Codec>(
309304 def_site,
310305 call_site,
311306 mixed_site,
312- Some ( & mut ProcMacroClientHandle :: < C > { stdin, stdout, buf } ) ,
307+ Some ( & mut ProcMacroClientHandle { stdin, stdout, buf } ) ,
313308 )
314309 . map ( |it| {
315310 (
@@ -325,10 +320,10 @@ fn handle_expand_ra<C: Codec>(
325320 . map ( |( tree, span_data_table) | bidirectional:: ExpandMacroExtended { tree, span_data_table } )
326321 . map_err ( |e| legacy:: PanicMessage ( e. into_string ( ) . unwrap_or_default ( ) ) ) ;
327322
328- send_response :: < C > ( stdout, bidirectional:: Response :: ExpandMacroExtended ( res) )
323+ send_response ( stdout, bidirectional:: Response :: ExpandMacroExtended ( res) )
329324}
330325
331- fn run_old < C : Codec > (
326+ fn run_old (
332327 stdin : & mut ( dyn BufRead + Send + Sync ) ,
333328 stdout : & mut ( dyn Write + Send + Sync ) ,
334329) -> io:: Result < ( ) > {
@@ -342,9 +337,9 @@ fn run_old<C: Codec>(
342337 }
343338 }
344339
345- let mut buf = C :: Buf :: default ( ) ;
346- let mut read_request = || legacy:: Request :: read :: < C > ( stdin, & mut buf) ;
347- let mut write_response = |msg : legacy:: Response | msg. write :: < C > ( stdout) ;
340+ let mut buf = String :: default ( ) ;
341+ let mut read_request = || legacy:: Request :: read ( stdin, & mut buf) ;
342+ let mut write_response = |msg : legacy:: Response | msg. write ( stdout) ;
348343
349344 let env = EnvSnapshot :: default ( ) ;
350345 let srv = proc_macro_srv:: ProcMacroSrv :: new ( & env) ;
@@ -473,10 +468,7 @@ fn run_old<C: Codec>(
473468 Ok ( ( ) )
474469}
475470
476- fn send_response < C : Codec > (
477- stdout : & mut dyn Write ,
478- resp : bidirectional:: Response ,
479- ) -> io:: Result < ( ) > {
471+ fn send_response ( stdout : & mut dyn Write , resp : bidirectional:: Response ) -> io:: Result < ( ) > {
480472 let resp = bidirectional:: BidirectionalMessage :: Response ( resp) ;
481- resp. write :: < C > ( stdout)
473+ resp. write ( stdout)
482474}
0 commit comments