@@ -71,7 +71,7 @@ pub fn main(init: std.process.Init) !void {
7171 //
7272 // The `lsp.Transport.Stdio` implements the necessary logic to read and write messages over stdio.
7373 var read_buffer : [256 ]u8 = undefined ;
74- var stdio_transport : lsp.Transport.Stdio = .init (io , & read_buffer , .{ .handle = child_process .stdout .? .handle }, child_process .stdin .? );
74+ var stdio_transport : lsp.Transport.Stdio = .init (& read_buffer , .{ .handle = child_process .stdout .? .handle }, child_process .stdin .? );
7575 const transport : * lsp.Transport = & stdio_transport .transport ;
7676
7777 // The order of exchanged messages will look similar to this:
@@ -84,6 +84,7 @@ pub fn main(init: std.process.Init) !void {
8484
8585 std .log .debug ("sending 'initialize' request to server" , .{});
8686 try transport .writeRequest (
87+ io ,
8788 gpa ,
8889 .{ .number = 0 },
8990 "initialize" , // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#initialize
@@ -95,7 +96,7 @@ pub fn main(init: std.process.Init) !void {
9596 // Wait for the response from the server
9697 // For the sake of simplicity, we will block here and read messages until the response to our request has been found. All other messages will be ignored.
9798 // A more sophisticated client implementation will need to handle messages asynchronously.
98- const initialize_response = try readAndIgnoreUntilResponse (gpa , transport , .{ .number = 0 }, "initialize" );
99+ const initialize_response = try readAndIgnoreUntilResponse (io , gpa , transport , .{ .number = 0 }, "initialize" );
99100 defer initialize_response .deinit ();
100101
101102 const initialize_result : lsp.types.InitializeResult = initialize_response .value ;
@@ -120,6 +121,7 @@ pub fn main(init: std.process.Init) !void {
120121
121122 std .log .debug ("sending 'initialized' notification to server" , .{});
122123 try transport .writeNotification (
124+ io ,
123125 gpa ,
124126 "initialized" , // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#initialized
125127 lsp .types .InitializedParams ,
@@ -132,6 +134,7 @@ pub fn main(init: std.process.Init) !void {
132134 std .log .info ("This document recently came in by the CLI." , .{});
133135 std .log .debug ("sending 'textDocument/didOpen' notification to server" , .{});
134136 try transport .writeNotification (
137+ io ,
135138 gpa ,
136139 "textDocument/didOpen" , // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_didOpen
137140 lsp .types .TextDocument .DidOpenParams ,
@@ -149,6 +152,7 @@ pub fn main(init: std.process.Init) !void {
149152 std .log .info ("Just to double check, could you verify that it is formatted correctly?" , .{});
150153 std .log .debug ("sending 'textDocument/formatting' request to server" , .{});
151154 try transport .writeRequest (
155+ io ,
152156 gpa ,
153157 .{ .number = 1 },
154158 "textDocument/formatting" , // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_formatting
@@ -160,7 +164,7 @@ pub fn main(init: std.process.Init) !void {
160164 .{ .emit_null_optional_fields = false },
161165 );
162166
163- const formatting_response = try readAndIgnoreUntilResponse (gpa , transport , .{ .number = 1 }, "textDocument/formatting" );
167+ const formatting_response = try readAndIgnoreUntilResponse (io , gpa , transport , .{ .number = 1 }, "textDocument/formatting" );
164168 defer formatting_response .deinit ();
165169
166170 const text_edits = formatting_response .value orelse &.{};
@@ -177,6 +181,7 @@ pub fn main(init: std.process.Init) !void {
177181 // Even though this is a request, we do not wait for a response because we are going to close the server anyway.
178182 std .log .debug ("sending 'shutdown' request to server" , .{});
179183 try transport .writeRequest (
184+ io ,
180185 gpa ,
181186 .{ .number = 2 },
182187 "shutdown" , // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#shutdown
@@ -187,6 +192,7 @@ pub fn main(init: std.process.Init) !void {
187192
188193 std .log .debug ("sending 'exit' notification to server" , .{});
189194 try transport .writeNotification (
195+ io ,
190196 gpa ,
191197 "exit" , // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#exit
192198 void ,
@@ -215,14 +221,15 @@ fn fatal(comptime format: []const u8, args: anytype) noreturn {
215221
216222/// Do not use such a function in an actual implementation.
217223fn readAndIgnoreUntilResponse (
224+ io : std.Io ,
218225 allocator : std.mem.Allocator ,
219226 transport : * lsp.Transport ,
220227 id : lsp.JsonRPCMessage.ID ,
221228 comptime method : []const u8 ,
222229) ! std.json. Parsed (lsp .ResultType (method )) {
223230 while (true ) {
224231 // read the unparsed JSON-RPC message
225- const json_message = try transport .readJsonMessage (allocator );
232+ const json_message = try transport .readJsonMessage (io , allocator );
226233 defer allocator .free (json_message );
227234 std .log .debug ("received message from server: {s}" , .{json_message });
228235
0 commit comments