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