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