Skip to content

Commit 1d4a410

Browse files
committed
update to zig 0.16.0-dev.1859+212968c57
1 parent 5f01937 commit 1d4a410

File tree

8 files changed

+28
-31
lines changed

8 files changed

+28
-31
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Provides the necessary building blocks to develop Language Server Protocol imple
1010
# Installation
1111

1212
> [!NOTE]
13-
> The default branch requires Zig `0.16.0-dev.1458+755a3d957` or later. Checkout the `0.15.x` branch when using Zig 0.15
13+
> The default branch requires Zig `0.16.0-dev.1859+212968c57` or later. Checkout the `0.15.x` branch when using Zig 0.15
1414
1515
```bash
1616
# Initialize a `zig build` project if you haven't already

build.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub fn build(b: *std.Build) void {
2929
.root_module = b.addModule("lsp-codegen", .{
3030
.root_source_file = b.path("src/codegen/codegen.zig"),
3131
.target = b.graph.host,
32+
.single_threaded = true,
3233
}),
3334
});
3435
// The metaModel.json file should be removed once https://github.com/ziglang/zig/issues/17895 has been resolved.

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.{
22
.name = .lsp_kit,
33
.version = "0.1.0",
4-
.minimum_zig_version = "0.16.0-dev.1458+755a3d957",
4+
.minimum_zig_version = "0.16.0-dev.1859+212968c57",
55
.dependencies = .{},
66
.paths = .{
77
"build.zig",

examples/hello_client.zig

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub fn main() !void {
5757
_ = debug_allocator.deinit();
5858
};
5959

60-
var threaded: std.Io.Threaded = .init(gpa);
60+
var threaded: std.Io.Threaded = .init(gpa, .{});
6161
defer threaded.deinit();
6262
const io = threaded.ioBasic();
6363

@@ -66,10 +66,7 @@ pub fn main() !void {
6666

6767
if (args.len < 3) fatalWithUsage("expected at least 2 arguments but got {d}", .{args.len - 1});
6868

69-
const input_file = (if (@hasDecl(std, "io"))
70-
std.fs.cwd().readFileAlloc(gpa, args[1], std.math.maxInt(u32))
71-
else
72-
std.fs.cwd().readFileAlloc(args[1], gpa, .limited(std.math.maxInt(u32)))) catch |err|
69+
const input_file = std.Io.Dir.cwd().readFileAlloc(io, args[1], gpa, .limited(std.math.maxInt(u32))) catch |err|
7370
fatal("failed to read file '{s}': {}", .{ args[1], err });
7471
defer gpa.free(input_file);
7572

@@ -79,7 +76,7 @@ pub fn main() !void {
7976
child_process.stdout_behavior = .Pipe;
8077
child_process.stderr_behavior = if (show_langauge_server_stderr) .Inherit else .Ignore;
8178

82-
child_process.spawn() catch |err| fatal("child process could not be created: {}", .{err});
79+
child_process.spawn(io) catch |err| fatal("child process could not be created: {}", .{err});
8380
child_process.waitForSpawn() catch |err| fatal("child process could not be created: {}", .{err});
8481

8582
// Language servers can support multiple communication channels (e.g. stdio, pipes, sockets).
@@ -211,14 +208,14 @@ pub fn main() !void {
211208
);
212209

213210
// The "exit" notification will ask the server to exit its process. Ideally we should wait with a timeout in case the server is not behaving correctly.
214-
_ = try child_process.wait();
211+
_ = try child_process.wait(io);
215212
}
216213

217214
fn fatalWithUsage(comptime format: []const u8, args: anytype) noreturn {
218215
{
219-
const stderr, _ = std.debug.lockStderrWriter(&.{});
220-
defer std.debug.unlockStderrWriter();
221-
stderr.writeAll(usage) catch {};
216+
const stderr = std.debug.lockStderr(&.{}).terminal();
217+
defer std.debug.unlockStderr();
218+
stderr.writer.writeAll(usage) catch {};
222219
}
223220
std.log.err(format, args);
224221
std.process.exit(1);

examples/hello_server.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub fn main() !void {
4141
_ = debug_allocator.deinit();
4242
};
4343

44-
var threaded: std.Io.Threaded = .init(gpa);
44+
var threaded: std.Io.Threaded = .init(gpa, .{});
4545
defer threaded.deinit();
4646
const io = threaded.ioBasic();
4747

examples/my_first_server.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub fn main() !void {
1515
_ = debug_allocator.deinit();
1616
};
1717

18-
var threaded: std.Io.Threaded = .init(gpa);
18+
var threaded: std.Io.Threaded = .init(gpa, .{});
1919
defer threaded.deinit();
2020
const io = threaded.ioBasic();
2121

src/codegen/codegen.zig

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ pub fn main() !u8 {
99

1010
const gpa = debug_allocator.allocator();
1111

12+
var threaded: std.Io.Threaded = .init_single_threaded;
13+
const io = threaded.ioBasic();
14+
1215
var arg_it: std.process.ArgIterator = try .initWithAllocator(gpa);
1316
defer arg_it.deinit();
1417

@@ -26,18 +29,18 @@ pub fn main() !u8 {
2629
var zig_tree: std.zig.Ast = try .parse(gpa, source, .zig);
2730
defer zig_tree.deinit(gpa);
2831

29-
std.fs.cwd().makePath(std.fs.path.dirname(out_file_path) orelse ".") catch {};
32+
std.Io.Dir.cwd().createDirPath(io, std.fs.path.dirname(out_file_path) orelse ".") catch {};
3033

31-
var out_file = try std.fs.cwd().createFile(out_file_path, .{});
32-
defer out_file.close();
34+
var out_file = try std.Io.Dir.cwd().createFile(io, out_file_path, .{});
35+
defer out_file.close(io);
3336

3437
if (zig_tree.errors.len != 0) {
3538
std.log.warn("generated file contains syntax errors! (cannot format file)", .{});
36-
try out_file.writeAll(source);
39+
try out_file.writeStreamingAll(io, source);
3740
return 1;
3841
} else {
3942
var buf: [1024]u8 = undefined;
40-
var out = out_file.writer(&buf);
43+
var out = out_file.writer(io, &buf);
4144
const w = &out.interface;
4245
try zig_tree.render(gpa, w, .{});
4346
try w.flush();

src/lsp.zig

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,22 +1089,22 @@ pub const Transport = struct {
10891089
writeJsonMessage: *const fn (transport: *Transport, json_message: []const u8) WriteError!void,
10901090
};
10911091

1092-
pub const ReadError = std.posix.ReadError || error{EndOfStream} || BaseProtocolHeader.ParseError || std.mem.Allocator.Error;
1093-
pub const WriteError = std.posix.WriteError;
1092+
pub const ReadError = std.Io.File.Reader.Error || error{EndOfStream} || BaseProtocolHeader.ParseError || std.mem.Allocator.Error;
1093+
pub const WriteError = std.Io.File.Writer.Error;
10941094

10951095
pub const Stdio = struct {
10961096
transport: Transport,
10971097
io: std.Io,
10981098
reader: std.Io.Reader,
10991099
read_from: std.Io.File,
1100-
write_to: std.fs.File,
1100+
write_to: std.Io.File,
11011101

11021102
pub fn init(
11031103
io: std.Io,
11041104
/// See `BaseProtocolHeader.parse`
11051105
read_buffer: []u8,
11061106
read_from: std.Io.File,
1107-
write_to: std.fs.File,
1107+
write_to: std.Io.File,
11081108
) Stdio {
11091109
return .{
11101110
.transport = .{
@@ -1122,12 +1122,8 @@ pub const Transport = struct {
11221122

11231123
fn readJsonMessage(transport: *Transport, allocator: std.mem.Allocator) ReadError![]u8 {
11241124
const stdio: *Stdio = @fieldParentPtr("transport", transport);
1125-
var file_reader: std.Io.File.Reader = .{
1126-
.io = stdio.io,
1127-
.file = stdio.read_from,
1128-
.mode = .streaming_reading,
1129-
.interface = stdio.reader,
1130-
};
1125+
var file_reader: std.Io.File.Reader = .initStreaming(stdio.read_from, stdio.io, stdio.reader.buffer);
1126+
file_reader.interface = stdio.reader;
11311127
defer stdio.reader = file_reader.interface;
11321128
return lsp.readJsonMessage(&file_reader.interface, allocator) catch |err| switch (err) {
11331129
error.ReadFailed => return file_reader.err.?,
@@ -1137,8 +1133,8 @@ pub const Transport = struct {
11371133

11381134
fn writeJsonMessage(transport: *Transport, json_message: []const u8) WriteError!void {
11391135
const stdio: *Stdio = @fieldParentPtr("transport", transport);
1140-
var file_writer: std.fs.File.Writer = .initStreaming(stdio.write_to, &.{});
1141-
return lsp.writeJsonMessage(&file_writer.interface, json_message) catch |err| switch (err) {
1136+
var file_writer: std.Io.File.Writer = .initStreaming(stdio.write_to, stdio.io, &.{});
1137+
lsp.writeJsonMessage(&file_writer.interface, json_message) catch |err| switch (err) {
11421138
error.WriteFailed => return file_writer.err.?,
11431139
};
11441140
}

0 commit comments

Comments
 (0)