From c4608f48f1131e83c672dab4b9f6f31350d01c88 Mon Sep 17 00:00:00 2001 From: Johan Persson Date: Sun, 4 Jan 2026 15:14:21 +0100 Subject: [PATCH 1/5] Fixes according to the new arguments to main See https://codeberg.org/ziglang/zig/pulls/30644 --- examples/hello_client.zig | 35 +++++++++++------------------------ examples/hello_server.zig | 18 +++--------------- examples/my_first_server.zig | 22 ++++------------------ src/codegen/codegen.zig | 4 ++-- 4 files changed, 20 insertions(+), 59 deletions(-) diff --git a/examples/hello_client.zig b/examples/hello_client.zig index 2e2dbc4..0b19b54 100644 --- a/examples/hello_client.zig +++ b/examples/hello_client.zig @@ -46,23 +46,11 @@ const usage = \\ ; -var debug_allocator: std.heap.DebugAllocator(.{}) = .init; - -pub fn main() !void { - const gpa, const is_debug = switch (builtin.mode) { - .Debug, .ReleaseSafe => .{ debug_allocator.allocator(), true }, - .ReleaseFast, .ReleaseSmall => .{ std.heap.smp_allocator, false }, - }; - defer if (is_debug) { - _ = debug_allocator.deinit(); - }; - - var threaded: std.Io.Threaded = .init(gpa, .{}); - defer threaded.deinit(); - const io = threaded.ioBasic(); - - const args = try std.process.argsAlloc(gpa); - defer std.process.argsFree(gpa, args); +pub fn main(init: std.process.Init) !void { + const io = init.io; + const gpa = init.gpa; + const arena = init.arena.allocator(); + const args = try init.minimal.args.toSlice(arena); if (args.len < 3) fatalWithUsage("expected at least 2 arguments but got {d}", .{args.len - 1}); @@ -71,13 +59,12 @@ pub fn main() !void { defer gpa.free(input_file); // Spawn the language server as a child process. - var child_process: std.process.Child = .init(args[2..], gpa); - child_process.stdin_behavior = .Pipe; - child_process.stdout_behavior = .Pipe; - child_process.stderr_behavior = if (show_langauge_server_stderr) .Inherit else .Ignore; - - child_process.spawn(io) catch |err| fatal("child process could not be created: {}", .{err}); - child_process.waitForSpawn() catch |err| fatal("child process could not be created: {}", .{err}); + var child_process = std.process.spawn(io, .{ + .argv = args[2..], + .stdin = .pipe, + .stdout = .pipe, + .stderr = .pipe, + }) catch |err| fatal("child process could not be created: {}", .{err}); // Language servers can support multiple communication channels (e.g. stdio, pipes, sockets). // See https://microsoft.github.io/language-server-protocol/specifications/specification-current/#implementationConsiderations diff --git a/examples/hello_server.zig b/examples/hello_server.zig index 0383890..0020c02 100644 --- a/examples/hello_server.zig +++ b/examples/hello_server.zig @@ -30,21 +30,9 @@ pub const std_options: std.Options = .{ .log_level = std.log.default_level, // Customize the log level here }; -var debug_allocator: std.heap.DebugAllocator(.{}) = .init; - -pub fn main() !void { - const gpa, const is_debug = switch (builtin.mode) { - .Debug, .ReleaseSafe => .{ debug_allocator.allocator(), true }, - .ReleaseFast, .ReleaseSmall => .{ std.heap.smp_allocator, false }, - }; - defer if (is_debug) { - _ = debug_allocator.deinit(); - }; - - var threaded: std.Io.Threaded = .init(gpa, .{}); - defer threaded.deinit(); - const io = threaded.ioBasic(); - +pub fn main(init: std.process.Init) !void { + const io = init.io; + const gpa = init.gpa; // Language servers can support multiple communication channels (e.g. stdio, pipes, sockets). // See https://microsoft.github.io/language-server-protocol/specifications/specification-current/#implementationConsiderations // diff --git a/examples/my_first_server.zig b/examples/my_first_server.zig index 093bb9e..b8b0452 100644 --- a/examples/my_first_server.zig +++ b/examples/my_first_server.zig @@ -4,33 +4,19 @@ const std = @import("std"); const builtin = @import("builtin"); const lsp = @import("lsp"); -var debug_allocator: std.heap.DebugAllocator(.{}) = .init; - -pub fn main() !void { - const gpa, const is_debug = switch (builtin.mode) { - .Debug, .ReleaseSafe => .{ debug_allocator.allocator(), true }, - .ReleaseFast, .ReleaseSmall => .{ std.heap.smp_allocator, false }, - }; - defer if (is_debug) { - _ = debug_allocator.deinit(); - }; - - var threaded: std.Io.Threaded = .init(gpa, .{}); - defer threaded.deinit(); - const io = threaded.ioBasic(); - +pub fn main(init: std.process.Init) !void { // LSP implementations typically communicate over stdio (stdin and stdout) var read_buffer: [256]u8 = undefined; - var stdio_transport: lsp.Transport.Stdio = .init(io, &read_buffer, .stdin(), .stdout()); + var stdio_transport: lsp.Transport.Stdio = .init(init.io, &read_buffer, .stdin(), .stdout()); const transport: *lsp.Transport = &stdio_transport.transport; // The handler is a user provided type that stores the state of the // language server and provides callbacks for the desired LSP messages. - var handler: Handler = .init(gpa); + var handler: Handler = .init(init.gpa); defer handler.deinit(); try lsp.basic_server.run( - gpa, + init.gpa, transport, &handler, std.log.err, diff --git a/src/codegen/codegen.zig b/src/codegen/codegen.zig index cb06929..167f383 100644 --- a/src/codegen/codegen.zig +++ b/src/codegen/codegen.zig @@ -3,7 +3,7 @@ const std = @import("std"); const MetaModel = @import("MetaModel.zig"); -pub fn main() !u8 { +pub fn main(init: std.process.Init.Minimal) !u8 { var debug_allocator: std.heap.DebugAllocator(.{}) = .init; defer _ = debug_allocator.deinit(); @@ -12,7 +12,7 @@ pub fn main() !u8 { var threaded: std.Io.Threaded = .init_single_threaded; const io = threaded.ioBasic(); - var arg_it: std.process.ArgIterator = try .initWithAllocator(gpa); + var arg_it = try init.args.iterateAllocator(gpa); defer arg_it.deinit(); _ = arg_it.skip(); // skip self exe From ec2d36f957fb48cdadbc1af8e881169a5b136679 Mon Sep 17 00:00:00 2001 From: Johan Persson Date: Mon, 5 Jan 2026 19:02:46 +0100 Subject: [PATCH 2/5] Inherit or ignore stderr for hello_client example --- examples/hello_client.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/hello_client.zig b/examples/hello_client.zig index 0b19b54..4688072 100644 --- a/examples/hello_client.zig +++ b/examples/hello_client.zig @@ -63,7 +63,7 @@ pub fn main(init: std.process.Init) !void { .argv = args[2..], .stdin = .pipe, .stdout = .pipe, - .stderr = .pipe, + .stderr = if (show_langauge_server_stderr) .inherit else .ignore, }) catch |err| fatal("child process could not be created: {}", .{err}); // Language servers can support multiple communication channels (e.g. stdio, pipes, sockets). From fbe663ca8197701838d4cde24f791f8acfc00185 Mon Sep 17 00:00:00 2001 From: Johan Persson Date: Mon, 5 Jan 2026 19:33:02 +0100 Subject: [PATCH 3/5] Bumped minimal version --- build.zig.zon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.zig.zon b/build.zig.zon index 7b0cde3..c7abc37 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.1859+212968c57", + .minimum_zig_version = "0.16.0-dev.1993+50422d5c3", .dependencies = .{}, .paths = .{ "build.zig", From f82c6ec781c2945a5a18422d92e61d4ac1d53f5a Mon Sep 17 00:00:00 2001 From: Johan Persson Date: Mon, 5 Jan 2026 19:35:06 +0100 Subject: [PATCH 4/5] Updated README.md with correct minimal zig version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cf8227a..874c128 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.1859+212968c57` or later. Checkout the `0.15.x` branch when using Zig 0.15 +> The default branch requires Zig `0.16.0-dev.1993+50422d5c3` or later. Checkout the `0.15.x` branch when using Zig 0.15 ```bash # Initialize a `zig build` project if you haven't already From e4b6e40370a23e51f2284e8f43463d8ca727e8bb Mon Sep 17 00:00:00 2001 From: Techatrix Date: Wed, 7 Jan 2026 07:09:26 +0100 Subject: [PATCH 5/5] set minimum Zig version to `0.16.0-dev.1976+8e091047b` Zig `0.16.0-dev.1993` is not available as a prebuilt binary. --- README.md | 2 +- build.zig.zon | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 874c128..97070bc 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.1993+50422d5c3` or later. Checkout the `0.15.x` branch when using Zig 0.15 +> The default branch requires Zig `0.16.0-dev.1976+8e091047b` 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 c7abc37..e2ffaf9 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.1993+50422d5c3", + .minimum_zig_version = "0.16.0-dev.1976+8e091047b", .dependencies = .{}, .paths = .{ "build.zig",