Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion examples/hello_client.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 9 additions & 9 deletions src/lsp.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -1273,34 +1273,34 @@ 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);
}

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 {}
};
};
}
Expand Down