@@ -143,11 +143,38 @@ impl ProcMacroServerProcess {
143
143
}
144
144
145
145
let state = & mut * self . state . lock ( ) . unwrap ( ) ;
146
- let mut buf = String :: new ( ) ;
147
- let mut client =
148
- JsonTaskClient { writer : & mut state. stdin , reader : & mut state. stdout , buf : & mut buf } ;
146
+
147
+ // Check environment variable to determine which protocol to use
148
+ let protocol = std:: env:: var ( "RUST_ANALYZER_PROC_MACRO_PROTOCOL" )
149
+ . unwrap_or_else ( |_| "json" . to_string ( ) ) ;
150
+
151
+ let result = match protocol. as_str ( ) {
152
+ "postcard" => {
153
+ // For now, still use JSON even when postcard is requested
154
+ // TODO: Implement full postcard protocol support
155
+ tracing:: warn!( "Postcard protocol requested but not fully implemented, using JSON" ) ;
156
+
157
+ let mut buf = String :: new ( ) ;
158
+ let mut client = JsonTaskClient {
159
+ writer : & mut state. stdin ,
160
+ reader : & mut state. stdout ,
161
+ buf : & mut buf
162
+ } ;
163
+ client. send_task ( req)
164
+ }
165
+ _ => {
166
+ // Default to JSON protocol
167
+ let mut buf = String :: new ( ) ;
168
+ let mut client = JsonTaskClient {
169
+ writer : & mut state. stdin ,
170
+ reader : & mut state. stdout ,
171
+ buf : & mut buf
172
+ } ;
173
+ client. send_task ( req)
174
+ }
175
+ } ;
149
176
150
- client . send_task ( req ) . map_err ( |e| {
177
+ result . map_err ( |e| {
151
178
if e. io . as_ref ( ) . map ( |it| it. kind ( ) ) == Some ( io:: ErrorKind :: BrokenPipe ) {
152
179
match state. process . child . try_wait ( ) {
153
180
Ok ( None ) | Err ( _) => e,
@@ -214,6 +241,26 @@ fn mk_child<'a>(
214
241
) -> io:: Result < Child > {
215
242
#[ allow( clippy:: disallowed_methods) ]
216
243
let mut cmd = Command :: new ( path) ;
244
+
245
+ // Check for protocol selection environment variable
246
+ if let Ok ( protocol) = std:: env:: var ( "RUST_ANALYZER_PROC_MACRO_PROTOCOL" ) {
247
+ match protocol. as_str ( ) {
248
+ "postcard" => {
249
+ cmd. args ( [ "--format" , "postcard" ] ) ;
250
+ }
251
+ "json" => {
252
+ cmd. args ( [ "--format" , "json" ] ) ;
253
+ }
254
+ _ => {
255
+ tracing:: warn!( "Unknown protocol '{}', defaulting to json" , protocol) ;
256
+ cmd. args ( [ "--format" , "json" ] ) ;
257
+ }
258
+ }
259
+ } else {
260
+ // Default to JSON protocol for backward compatibility
261
+ cmd. args ( [ "--format" , "json" ] ) ;
262
+ }
263
+
217
264
for env in extra_env {
218
265
match env {
219
266
( key, Some ( val) ) => cmd. env ( key, val) ,
0 commit comments