@@ -81,7 +81,6 @@ fn run_new<C: Codec>() -> io::Result<()> {
8181 }
8282
8383 bidirectional:: Request :: ApiVersionCheck { } => {
84- // bidirectional::Response::ApiVersionCheck(CURRENT_API_VERSION).write::<_, C>(stdout)
8584 send_response :: < C > (
8685 & stdout,
8786 bidirectional:: Response :: ApiVersionCheck ( CURRENT_API_VERSION ) ,
@@ -167,28 +166,48 @@ struct ProcMacroClientHandle<'a, C: Codec> {
167166 buf : & ' a mut C :: Buf ,
168167}
169168
170- impl < C : Codec > proc_macro_srv:: ProcMacroClientInterface for ProcMacroClientHandle < ' _ , C > {
171- fn source_text ( & mut self , file_id : u32 , start : u32 , end : u32 ) -> Option < String > {
172- let req = bidirectional:: BidirectionalMessage :: SubRequest (
173- bidirectional:: SubRequest :: SourceText { file_id, start, end } ,
174- ) ;
169+ impl < ' a , C : Codec > ProcMacroClientHandle < ' a , C > {
170+ fn roundtrip (
171+ & mut self ,
172+ req : bidirectional:: SubRequest ,
173+ ) -> Option < bidirectional:: BidirectionalMessage > {
174+ let msg = bidirectional:: BidirectionalMessage :: SubRequest ( req) ;
175175
176- if req . write :: < _ , C > ( & mut self . stdout . lock ( ) ) . is_err ( ) {
176+ if msg . write :: < _ , C > ( & mut self . stdout . lock ( ) ) . is_err ( ) {
177177 return None ;
178178 }
179179
180- let msg = match bidirectional:: BidirectionalMessage :: read :: < _ , C > (
181- & mut self . stdin . lock ( ) ,
182- self . buf ,
183- ) {
184- Ok ( Some ( msg) ) => msg,
185- _ => return None ,
186- } ;
180+ match bidirectional:: BidirectionalMessage :: read :: < _ , C > ( & mut self . stdin . lock ( ) , self . buf ) {
181+ Ok ( Some ( msg) ) => Some ( msg) ,
182+ _ => None ,
183+ }
184+ }
185+ }
186+
187+ impl < C : Codec > proc_macro_srv:: ProcMacroClientInterface for ProcMacroClientHandle < ' _ , C > {
188+ fn file ( & mut self , file_id : u32 ) -> String {
189+ match self . roundtrip ( bidirectional:: SubRequest :: FilePath { file_id } ) {
190+ Some ( bidirectional:: BidirectionalMessage :: SubResponse (
191+ bidirectional:: SubResponse :: FilePathResult { name } ,
192+ ) ) => name,
193+ _ => String :: new ( ) ,
194+ }
195+ }
187196
188- match msg {
189- bidirectional:: BidirectionalMessage :: SubResponse (
197+ fn source_text ( & mut self , file_id : u32 , start : u32 , end : u32 ) -> Option < String > {
198+ match self . roundtrip ( bidirectional:: SubRequest :: SourceText { file_id, start, end } ) {
199+ Some ( bidirectional:: BidirectionalMessage :: SubResponse (
190200 bidirectional:: SubResponse :: SourceTextResult { text } ,
191- ) => text,
201+ ) ) => text,
202+ _ => None ,
203+ }
204+ }
205+
206+ fn local_file ( & mut self , file_id : u32 ) -> Option < String > {
207+ match self . roundtrip ( bidirectional:: SubRequest :: LocalFilePath { file_id } ) {
208+ Some ( bidirectional:: BidirectionalMessage :: SubResponse (
209+ bidirectional:: SubResponse :: LocalFilePathResult { name } ,
210+ ) ) => name,
192211 _ => None ,
193212 }
194213 }
0 commit comments