Skip to content

Commit 7c4578f

Browse files
authored
Merge pull request #28 from zigtools/dev
2 parents c46ac86 + 20dc88a commit 7c4578f

File tree

14 files changed

+5459
-2798
lines changed

14 files changed

+5459
-2798
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![CI](https://github.com/zigtools/lsp-kit/actions/workflows/main.yml/badge.svg)](https://github.com/zigtools/lsp-kit/actions)
22
[![codecov](https://codecov.io/gh/zigtools/lsp-kit/graph/badge.svg?token=C3HCN59E4C)](https://codecov.io/gh/zigtools/lsp-kit)
3-
[![Documentation](https://badgen.net/badge/icon/Docs?icon=wiki&label)](https://zigtools.github.io/lsp-kit)
3+
[![Documentation](https://img.shields.io/badge/Docs-grey?logo=zig)](https://zigtools.github.io/lsp-kit)
44
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
55

66
# Zig LSP Kit

build.zig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn build(b: *std.Build) void {
2727
const exe = b.addExecutable(.{
2828
.name = "lsp-codegen",
2929
.root_module = b.addModule("lsp-codegen", .{
30-
.root_source_file = b.path("src/main.zig"),
30+
.root_source_file = b.path("src/codegen/codegen.zig"),
3131
.target = b.graph.host,
3232
}),
3333
});
@@ -62,6 +62,9 @@ pub fn build(b: *std.Build) void {
6262
},
6363
});
6464

65+
const codegen_step = b.step("codegen", "Install LSP types generated from the meta model");
66+
codegen_step.dependOn(&b.addInstallFile(lsp_types_output_file, "lsp_types.zig").step);
67+
6568
// -------------------------------- Autodoc --------------------------------
6669

6770
const autodoc_exe = b.addObject(.{

examples/hello_client.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ pub fn main() !void {
125125
const documentFormattingProvider = initialize_result.capabilities.documentFormattingProvider orelse break :blk false;
126126
switch (documentFormattingProvider) {
127127
.bool => |supported| break :blk supported,
128-
.DocumentFormattingOptions => break :blk true,
128+
.document_formatting_options => break :blk true,
129129
}
130130
};
131131

@@ -150,11 +150,11 @@ pub fn main() !void {
150150
try transport.writeNotification(
151151
gpa,
152152
"textDocument/didOpen", // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_didOpen
153-
lsp.types.DidOpenTextDocumentParams,
153+
lsp.types.TextDocument.DidOpenParams,
154154
.{
155155
.textDocument = .{
156156
.uri = "untitled:Document", // Usually a file system uri will be provided like 'file:///path/to/main.zig'
157-
.languageId = "",
157+
.languageId = .{ .custom_value = "" },
158158
.text = input_file,
159159
.version = 0,
160160
},
@@ -168,7 +168,7 @@ pub fn main() !void {
168168
gpa,
169169
.{ .number = 1 },
170170
"textDocument/formatting", // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_formatting
171-
lsp.types.DocumentFormattingParams,
171+
lsp.types.document_formatting.Params,
172172
.{
173173
.textDocument = .{ .uri = "untitled:Document" },
174174
.options = .{ .tabSize = 4, .insertSpaces = true },

examples/hello_server.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ const RequestMethods = union(enum) {
191191
/// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#shutdown
192192
shutdown,
193193
/// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_formatting
194-
@"textDocument/formatting": lsp.types.DocumentFormattingParams,
194+
@"textDocument/formatting": lsp.types.document_formatting.Params,
195195
other: lsp.MethodWithParams,
196196
};
197197

@@ -201,10 +201,10 @@ const NotificationMethods = union(enum) {
201201
/// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#exit
202202
exit,
203203
/// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_didOpen
204-
@"textDocument/didOpen": lsp.types.DidOpenTextDocumentParams,
204+
@"textDocument/didOpen": lsp.types.TextDocument.DidOpenParams,
205205
/// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_didChange
206-
@"textDocument/didChange": lsp.types.DidChangeTextDocumentParams,
206+
@"textDocument/didChange": lsp.types.TextDocument.DidChangeParams,
207207
/// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_didClose
208-
@"textDocument/didClose": lsp.types.DidCloseTextDocumentParams,
208+
@"textDocument/didClose": lsp.types.TextDocument.DidCloseParams,
209209
other: lsp.MethodWithParams,
210210
};

examples/my_first_server.zig

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub const Handler = struct {
107107
.@"utf-32" => .@"utf-32",
108108
},
109109
.textDocumentSync = .{
110-
.TextDocumentSyncOptions = .{
110+
.text_document_sync_options = .{
111111
.openClose = true,
112112
.change = .Full,
113113
},
@@ -163,7 +163,7 @@ pub const Handler = struct {
163163
pub fn @"textDocument/didOpen"(
164164
self: *Handler,
165165
_: std.mem.Allocator,
166-
notification: lsp.types.DidOpenTextDocumentParams,
166+
notification: lsp.types.TextDocument.DidOpenParams,
167167
) !void {
168168
std.log.debug("Received 'textDocument/didOpen' notification", .{});
169169

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

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

204204
for (notification.contentChanges) |content_change| {
205205
switch (content_change) {
206-
.literal_1 => |change| {
206+
.text_document_content_change_whole_document => |change| {
207207
buffer.clearRetainingCapacity();
208208
try buffer.appendSlice(self.allocator, change.text);
209209
},
210-
.literal_0 => |change| {
210+
.text_document_content_change_partial => |change| {
211211
const loc = lsp.offsets.rangeToLoc(buffer.items, change.range, self.offset_encoding);
212212
try buffer.replaceRange(self.allocator, loc.start, loc.end - loc.start, change.text);
213213
},
@@ -223,7 +223,7 @@ pub const Handler = struct {
223223
pub fn @"textDocument/didClose"(
224224
self: *Handler,
225225
_: std.mem.Allocator,
226-
notification: lsp.types.DidCloseTextDocumentParams,
226+
notification: lsp.types.TextDocument.DidCloseParams,
227227
) !void {
228228
std.log.debug("Received 'textDocument/didClose' notification", .{});
229229

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

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

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

271271
if (params.context) |context| {
@@ -275,7 +275,7 @@ pub const Handler = struct {
275275
});
276276
}
277277

278-
const completions = try arena.dupe(lsp.types.CompletionItem, &.{
278+
const completions = try arena.dupe(lsp.types.completion.Item, &.{
279279
.{
280280
.label = "get",
281281
.detail = "get the value",
@@ -285,7 +285,7 @@ pub const Handler = struct {
285285
.detail = "set the value",
286286
},
287287
});
288-
return .{ .array_of_CompletionItem = completions };
288+
return .{ .completion_items = completions };
289289
}
290290

291291
/// We received a response message from the client/editor.

0 commit comments

Comments
 (0)