@@ -9,7 +9,7 @@ use paths::{AbsPath, AbsPathBuf};
99use stdx:: JodChild ;
1010
1111use crate :: {
12- msg:: { Message , Request , Response , CURRENT_API_VERSION } ,
12+ msg:: { Message , Request , Response , SpanMode , CURRENT_API_VERSION , RUST_ANALYZER_SPAN_SUPPORT } ,
1313 ProcMacroKind , ServerError ,
1414} ;
1515
@@ -19,6 +19,7 @@ pub(crate) struct ProcMacroProcessSrv {
1919 stdin : ChildStdin ,
2020 stdout : BufReader < ChildStdout > ,
2121 version : u32 ,
22+ mode : SpanMode ,
2223}
2324
2425impl ProcMacroProcessSrv {
@@ -27,7 +28,13 @@ impl ProcMacroProcessSrv {
2728 let mut process = Process :: run ( process_path. clone ( ) , null_stderr) ?;
2829 let ( stdin, stdout) = process. stdio ( ) . expect ( "couldn't access child stdio" ) ;
2930
30- io:: Result :: Ok ( ProcMacroProcessSrv { _process : process, stdin, stdout, version : 0 } )
31+ io:: Result :: Ok ( ProcMacroProcessSrv {
32+ _process : process,
33+ stdin,
34+ stdout,
35+ version : 0 ,
36+ mode : SpanMode :: Id ,
37+ } )
3138 } ;
3239 let mut srv = create_srv ( true ) ?;
3340 tracing:: info!( "sending version check" ) ;
@@ -43,6 +50,11 @@ impl ProcMacroProcessSrv {
4350 tracing:: info!( "got version {v}" ) ;
4451 srv = create_srv ( false ) ?;
4552 srv. version = v;
53+ if srv. version > RUST_ANALYZER_SPAN_SUPPORT {
54+ if let Ok ( mode) = srv. enable_rust_analyzer_spans ( ) {
55+ srv. mode = mode;
56+ }
57+ }
4658 Ok ( srv)
4759 }
4860 Err ( e) => {
@@ -62,9 +74,17 @@ impl ProcMacroProcessSrv {
6274
6375 match response {
6476 Response :: ApiVersionCheck ( version) => Ok ( version) ,
65- Response :: ExpandMacro { .. } | Response :: ListMacros { .. } => {
66- Err ( ServerError { message : "unexpected response" . to_string ( ) , io : None } )
67- }
77+ _ => Err ( ServerError { message : "unexpected response" . to_string ( ) , io : None } ) ,
78+ }
79+ }
80+
81+ fn enable_rust_analyzer_spans ( & mut self ) -> Result < SpanMode , ServerError > {
82+ let request = Request :: SetSpanMode ( crate :: msg:: SpanMode :: RustAnalyzer ) ;
83+ let response = self . send_task ( request) ?;
84+
85+ match response {
86+ Response :: SetSpanMode ( span_mode) => Ok ( span_mode) ,
87+ _ => Err ( ServerError { message : "unexpected response" . to_string ( ) , io : None } ) ,
6888 }
6989 }
7090
@@ -78,9 +98,7 @@ impl ProcMacroProcessSrv {
7898
7999 match response {
80100 Response :: ListMacros ( it) => Ok ( it) ,
81- Response :: ExpandMacro { .. } | Response :: ApiVersionCheck { .. } => {
82- Err ( ServerError { message : "unexpected response" . to_string ( ) , io : None } )
83- }
101+ _ => Err ( ServerError { message : "unexpected response" . to_string ( ) , io : None } ) ,
84102 }
85103 }
86104
0 commit comments