diff --git a/README.md b/README.md index 97070bc..98bdd14 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Provides the necessary building blocks to develop Language Server Protocol imple # Installation > [!NOTE] -> The default branch requires Zig `0.16.0-dev.1976+8e091047b` or later. Checkout the `0.15.x` branch when using Zig 0.15 +> The default branch requires Zig `0.16.0-dev.2510+bcb5218a2` or later. Checkout the `0.15.x` branch when using Zig 0.15 ```bash # Initialize a `zig build` project if you haven't already diff --git a/build.zig.zon b/build.zig.zon index e2ffaf9..c13c199 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,7 +1,7 @@ .{ .name = .lsp_kit, .version = "0.1.0", - .minimum_zig_version = "0.16.0-dev.1976+8e091047b", + .minimum_zig_version = "0.16.0-dev.2510+bcb5218a2", .dependencies = .{}, .paths = .{ "build.zig", diff --git a/examples/hello_client.zig b/examples/hello_client.zig index 62ceae1..942999b 100644 --- a/examples/hello_client.zig +++ b/examples/hello_client.zig @@ -71,7 +71,7 @@ pub fn main(init: std.process.Init) !void { // // The `lsp.Transport.Stdio` implements the necessary logic to read and write messages over stdio. var read_buffer: [256]u8 = undefined; - var stdio_transport: lsp.Transport.Stdio = .init(&read_buffer, .{ .handle = child_process.stdout.?.handle }, child_process.stdin.?); + var stdio_transport: lsp.Transport.Stdio = .init(&read_buffer, child_process.stdout.?, child_process.stdin.?); const transport: *lsp.Transport = &stdio_transport.transport; // The order of exchanged messages will look similar to this: diff --git a/src/lsp.zig b/src/lsp.zig index 632ac2c..81b6c4c 100644 --- a/src/lsp.zig +++ b/src/lsp.zig @@ -1244,7 +1244,7 @@ pub const ThreadSafeTransportConfig = struct { thread_safe_read: bool, /// Makes `writeJsonMessage` thread-safe. thread_safe_write: bool, - MutexType: type = std.Thread.Mutex, + MutexType: type = std.Io.Mutex, }; /// Wraps a non-thread-safe transport and makes it thread-safe. @@ -1273,8 +1273,8 @@ pub fn ThreadSafeTransport(config: ThreadSafeTransportConfig) type { pub fn readJsonMessage(transport: *Transport, io: std.Io, allocator: std.mem.Allocator) Transport.ReadError![]u8 { const self: *Self = @fieldParentPtr("transport", transport); - self.in_mutex.lock(); - defer self.in_mutex.unlock(); + try self.in_mutex.lock(io); + defer self.in_mutex.unlock(io); return try self.child_transport.readJsonMessage(io, allocator); } @@ -1282,25 +1282,25 @@ pub fn ThreadSafeTransport(config: ThreadSafeTransportConfig) type { pub fn writeJsonMessage(transport: *Transport, io: std.Io, json_message: []const u8) Transport.WriteError!void { const self: *Self = @fieldParentPtr("transport", transport); - self.out_mutex.lock(); - defer self.out_mutex.unlock(); + try self.out_mutex.lock(io); + defer self.out_mutex.unlock(io); return try self.child_transport.writeJsonMessage(io, json_message); } const in_mutex_init = if (config.thread_safe_read) - config.MutexType{} + config.MutexType.init else DummyMutex{}; const out_mutex_init = if (config.thread_safe_write) - config.MutexType{} + config.MutexType.init else DummyMutex{}; const DummyMutex = struct { - fn lock(_: *DummyMutex) void {} - fn unlock(_: *DummyMutex) void {} + pub fn lock(_: *DummyMutex, _: std.Io) !void {} + pub fn unlock(_: *DummyMutex, _: std.Io) void {} }; }; }