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.1859+212968c57` 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
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.1859+212968c57",
.minimum_zig_version = "0.16.0-dev.1976+8e091047b",
.dependencies = .{},
.paths = .{
"build.zig",
Expand Down
35 changes: 11 additions & 24 deletions examples/hello_client.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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});

Expand All @@ -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 = 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).
// See https://microsoft.github.io/language-server-protocol/specifications/specification-current/#implementationConsiderations
Expand Down
18 changes: 3 additions & 15 deletions examples/hello_server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
22 changes: 4 additions & 18 deletions examples/my_first_server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/codegen/codegen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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
Expand Down