Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2333a48
move code generation to src/codegen/
Techatrix Sep 12, 2025
e2bad27
build: add zig build codegen
Techatrix Sep 12, 2025
6c990e2
improve how empty lines are added when rendering properties
Techatrix Sep 12, 2025
f1938dd
refactor type introspection in code generation
Techatrix Sep 16, 2025
984a832
store message metadata in a `std.StaticStringMap`
Techatrix Sep 16, 2025
ecf38b7
improve generated field names of unions
Techatrix Sep 20, 2025
1e3b543
utilize symbol namespacing
Techatrix Sep 27, 2025
b593018
update codegen config
Techatrix Oct 1, 2025
3b28666
convert more anonymous container types into named declarations
Techatrix Oct 1, 2025
e0da129
update to LSP Specification 3.18 (proposal)
Techatrix Oct 1, 2025
56e1d6b
refactor
Techatrix Oct 1, 2025
c1a8b9f
fix lsp.types.LanguageKind workaround about duplicate `pascal` field
Techatrix Oct 3, 2025
518ccb2
use const pointer for recursive nested ranges
Techatrix Oct 3, 2025
1824ceb
merge `remove_symbols` and `rename_symbols` in config.zon
Techatrix Oct 3, 2025
9e24b2d
control where generated symbols will be placed in source code
Techatrix Oct 3, 2025
40bf6ab
make hash functions for meta model match equality function
Techatrix Oct 3, 2025
b3a9f13
update symbol config
Techatrix Oct 3, 2025
402a09b
update rest of the code to the new generated LSP types
Techatrix Oct 3, 2025
12d5ca9
rewrite codegen symbolize
Techatrix Oct 4, 2025
e91de66
rename fields of MetaModel.Params
Techatrix Oct 4, 2025
ceeb338
remove codegen config options for debugging
Techatrix Oct 8, 2025
67b0ba6
move `lsp.JsonRPCMessage.ID` to `lsp.types.ID` and dedupe when possible
Techatrix Oct 15, 2025
849a877
document the allowed values of a numeric ID
Techatrix Oct 28, 2025
665b351
update symbol config
Techatrix Oct 28, 2025
cfa9d13
add `lsp.flat` namespace that contains symbols with their original name
Techatrix Oct 28, 2025
9d969e9
remove messageDirectionName from codegen.zig
Techatrix Oct 28, 2025
fcd6e90
Add doc comment mentioning the symbol's original name from the Spec
Techatrix Nov 18, 2025
92ec5be
improve code formatting when generated file contains syntax errors
Techatrix Nov 19, 2025
9eab64c
assert that `MetaModel.Property.optional` is null
Techatrix Nov 19, 2025
a611d69
fix broken link to documentation icon in readme
Techatrix Nov 19, 2025
9b10e5e
improve some (mostly internal) documentation
Techatrix Nov 19, 2025
20dc88a
update `codegen.SymbolTree.dump` to better handle nested nodes
Techatrix Nov 19, 2025
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
@@ -1,6 +1,6 @@
[![CI](https://github.com/zigtools/lsp-kit/actions/workflows/main.yml/badge.svg)](https://github.com/zigtools/lsp-kit/actions)
[![codecov](https://codecov.io/gh/zigtools/lsp-kit/graph/badge.svg?token=C3HCN59E4C)](https://codecov.io/gh/zigtools/lsp-kit)
[![Documentation](https://badgen.net/badge/icon/Docs?icon=wiki&label)](https://zigtools.github.io/lsp-kit)
[![Documentation](https://img.shields.io/badge/Docs-grey?logo=zig)](https://zigtools.github.io/lsp-kit)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

# Zig LSP Kit
Expand Down
5 changes: 4 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn build(b: *std.Build) void {
const exe = b.addExecutable(.{
.name = "lsp-codegen",
.root_module = b.addModule("lsp-codegen", .{
.root_source_file = b.path("src/main.zig"),
.root_source_file = b.path("src/codegen/codegen.zig"),
.target = b.graph.host,
}),
});
Expand Down Expand Up @@ -62,6 +62,9 @@ pub fn build(b: *std.Build) void {
},
});

const codegen_step = b.step("codegen", "Install LSP types generated from the meta model");
codegen_step.dependOn(&b.addInstallFile(lsp_types_output_file, "lsp_types.zig").step);

// -------------------------------- Autodoc --------------------------------

const autodoc_exe = b.addObject(.{
Expand Down
8 changes: 4 additions & 4 deletions examples/hello_client.zig
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub fn main() !void {
const documentFormattingProvider = initialize_result.capabilities.documentFormattingProvider orelse break :blk false;
switch (documentFormattingProvider) {
.bool => |supported| break :blk supported,
.DocumentFormattingOptions => break :blk true,
.document_formatting_options => break :blk true,
}
};

Expand All @@ -150,11 +150,11 @@ pub fn main() !void {
try transport.writeNotification(
gpa,
"textDocument/didOpen", // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_didOpen
lsp.types.DidOpenTextDocumentParams,
lsp.types.TextDocument.DidOpenParams,
.{
.textDocument = .{
.uri = "untitled:Document", // Usually a file system uri will be provided like 'file:///path/to/main.zig'
.languageId = "",
.languageId = .{ .custom_value = "" },
.text = input_file,
.version = 0,
},
Expand All @@ -168,7 +168,7 @@ pub fn main() !void {
gpa,
.{ .number = 1 },
"textDocument/formatting", // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_formatting
lsp.types.DocumentFormattingParams,
lsp.types.document_formatting.Params,
.{
.textDocument = .{ .uri = "untitled:Document" },
.options = .{ .tabSize = 4, .insertSpaces = true },
Expand Down
8 changes: 4 additions & 4 deletions examples/hello_server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ const RequestMethods = union(enum) {
/// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#shutdown
shutdown,
/// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_formatting
@"textDocument/formatting": lsp.types.DocumentFormattingParams,
@"textDocument/formatting": lsp.types.document_formatting.Params,
other: lsp.MethodWithParams,
};

Expand All @@ -201,10 +201,10 @@ const NotificationMethods = union(enum) {
/// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#exit
exit,
/// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_didOpen
@"textDocument/didOpen": lsp.types.DidOpenTextDocumentParams,
@"textDocument/didOpen": lsp.types.TextDocument.DidOpenParams,
/// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_didChange
@"textDocument/didChange": lsp.types.DidChangeTextDocumentParams,
@"textDocument/didChange": lsp.types.TextDocument.DidChangeParams,
/// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_didClose
@"textDocument/didClose": lsp.types.DidCloseTextDocumentParams,
@"textDocument/didClose": lsp.types.TextDocument.DidCloseParams,
other: lsp.MethodWithParams,
};
24 changes: 12 additions & 12 deletions examples/my_first_server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub const Handler = struct {
.@"utf-32" => .@"utf-32",
},
.textDocumentSync = .{
.TextDocumentSyncOptions = .{
.text_document_sync_options = .{
.openClose = true,
.change = .Full,
},
Expand Down Expand Up @@ -163,7 +163,7 @@ pub const Handler = struct {
pub fn @"textDocument/didOpen"(
self: *Handler,
_: std.mem.Allocator,
notification: lsp.types.DidOpenTextDocumentParams,
notification: lsp.types.TextDocument.DidOpenParams,
) !void {
std.log.debug("Received 'textDocument/didOpen' notification", .{});

Expand All @@ -187,7 +187,7 @@ pub const Handler = struct {
pub fn @"textDocument/didChange"(
self: *Handler,
_: std.mem.Allocator,
notification: lsp.types.DidChangeTextDocumentParams,
notification: lsp.types.TextDocument.DidChangeParams,
) !void {
std.log.debug("Received 'textDocument/didChange' notification", .{});

Expand All @@ -203,11 +203,11 @@ pub const Handler = struct {

for (notification.contentChanges) |content_change| {
switch (content_change) {
.literal_1 => |change| {
.text_document_content_change_whole_document => |change| {
buffer.clearRetainingCapacity();
try buffer.appendSlice(self.allocator, change.text);
},
.literal_0 => |change| {
.text_document_content_change_partial => |change| {
const loc = lsp.offsets.rangeToLoc(buffer.items, change.range, self.offset_encoding);
try buffer.replaceRange(self.allocator, loc.start, loc.end - loc.start, change.text);
},
Expand All @@ -223,7 +223,7 @@ pub const Handler = struct {
pub fn @"textDocument/didClose"(
self: *Handler,
_: std.mem.Allocator,
notification: lsp.types.DidCloseTextDocumentParams,
notification: lsp.types.TextDocument.DidCloseParams,
) !void {
std.log.debug("Received 'textDocument/didClose' notification", .{});

Expand All @@ -241,7 +241,7 @@ pub const Handler = struct {
pub fn @"textDocument/hover"(
handler: *Handler,
_: std.mem.Allocator,
params: lsp.types.HoverParams,
params: lsp.types.Hover.Params,
) ?lsp.types.Hover {
std.log.debug("Received 'textDocument/hover' request", .{});

Expand All @@ -253,7 +253,7 @@ pub const Handler = struct {

return .{
.contents = .{
.MarkupContent = .{
.markup_content = .{
.kind = .plaintext,
.value = "I don't know what you are hovering over but I'd like to point out that you have a nice editor theme",
},
Expand All @@ -264,8 +264,8 @@ pub const Handler = struct {
pub fn @"textDocument/completion"(
_: *Handler,
arena: std.mem.Allocator,
params: lsp.types.CompletionParams,
) error{OutOfMemory}!lsp.ResultType("textDocument/completion") {
params: lsp.types.completion.Params,
) error{OutOfMemory}!?lsp.types.completion.Result {
std.log.debug("Received 'textDocument/completion' notification", .{});

if (params.context) |context| {
Expand All @@ -275,7 +275,7 @@ pub const Handler = struct {
});
}

const completions = try arena.dupe(lsp.types.CompletionItem, &.{
const completions = try arena.dupe(lsp.types.completion.Item, &.{
.{
.label = "get",
.detail = "get the value",
Expand All @@ -285,7 +285,7 @@ pub const Handler = struct {
.detail = "set the value",
},
});
return .{ .array_of_CompletionItem = completions };
return .{ .completion_items = completions };
}

/// We received a response message from the client/editor.
Expand Down
Loading