@@ -11,6 +11,7 @@ const Header = @import("Header.zig");
11
11
const debug = @import ("debug.zig" );
12
12
13
13
const logger = std .log .scoped (.zls_main );
14
+ const message_logger = std .log .scoped (.message );
14
15
15
16
var actual_log_level : std.log.Level = switch (zig_builtin .mode ) {
16
17
.Debug = > .debug ,
@@ -60,6 +61,7 @@ fn loop(
60
61
const header = Header { .content_length = outgoing_message .len };
61
62
try header .write (true , writer );
62
63
try writer .writeAll (outgoing_message );
64
+ if (server .message_tracing_enabled ) message_logger .info ("sent: {s}\n " , .{outgoing_message });
63
65
}
64
66
try buffered_writer .flush ();
65
67
for (server .outgoing_messages .items ) | outgoing_message | {
@@ -78,6 +80,7 @@ fn loop(
78
80
try file .writeAll (json_message );
79
81
}
80
82
83
+ if (server .message_tracing_enabled ) message_logger .info ("received: {s}\n " , .{json_message });
81
84
server .processJsonRpc (json_message );
82
85
83
86
if (server .status == .exiting_success or server .status == .exiting_failure ) return ;
@@ -195,6 +198,7 @@ const ParseArgsResult = struct {
195
198
config_path : ? []const u8 ,
196
199
replay_enabled : bool ,
197
200
replay_session_path : ? []const u8 ,
201
+ message_tracing_enabled : bool ,
198
202
};
199
203
200
204
fn parseArgs (allocator : std.mem.Allocator ) ! ParseArgsResult {
@@ -203,13 +207,15 @@ fn parseArgs(allocator: std.mem.Allocator) !ParseArgsResult {
203
207
.config_path = null ,
204
208
.replay_enabled = false ,
205
209
.replay_session_path = null ,
210
+ .message_tracing_enabled = false ,
206
211
};
207
212
208
213
const ArgId = enum {
209
214
help ,
210
215
version ,
211
216
replay ,
212
217
@"enable-debug-log" ,
218
+ @"enable-message-tracing" ,
213
219
@"show-config-path" ,
214
220
@"config-path" ,
215
221
};
@@ -236,6 +242,7 @@ fn parseArgs(allocator: std.mem.Allocator) !ParseArgsResult {
236
242
.version = "Prints the compiler version with which the server was compiled." ,
237
243
.replay = "Replay a previous recorded zls session" ,
238
244
.@"enable-debug-log" = "Enables debug logs." ,
245
+ .@"enable-message-tracing" = "Enables message tracing." ,
239
246
.@"config-path" = "Specify the path to a configuration file specifying LSP behaviour." ,
240
247
.@"show-config-path" = "Prints the path to the configuration file to stdout" ,
241
248
});
@@ -281,6 +288,7 @@ fn parseArgs(allocator: std.mem.Allocator) !ParseArgsResult {
281
288
.help ,
282
289
.version ,
283
290
.@"enable-debug-log" ,
291
+ .@"enable-message-tracing" ,
284
292
.@"show-config-path" ,
285
293
= > {},
286
294
.@"config-path" = > {
@@ -310,6 +318,10 @@ fn parseArgs(allocator: std.mem.Allocator) !ParseArgsResult {
310
318
actual_log_level = .debug ;
311
319
logger .info ("Enabled debug logging.\n " , .{});
312
320
}
321
+ if (specified .get (.@"enable-message-tracing" )) {
322
+ result .message_tracing_enabled = true ;
323
+ logger .info ("Enabled message tracing.\n " , .{});
324
+ }
313
325
if (specified .get (.@"config-path" )) {
314
326
std .debug .assert (result .config_path != null );
315
327
}
@@ -390,6 +402,7 @@ pub fn main() !void {
390
402
config .config_path ,
391
403
record_file != null ,
392
404
replay_file != null ,
405
+ result .message_tracing_enabled ,
393
406
);
394
407
defer server .destroy ();
395
408
0 commit comments