Skip to content

Commit 6274eeb

Browse files
author
Jay Rhoden
authored
document code completions in example server (#26)
1 parent fe98e89 commit 6274eeb

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

examples/my_first_server.zig

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ pub const Handler = struct {
109109
},
110110
},
111111
.hoverProvider = .{ .bool = true },
112+
.completionProvider = .{ .triggerCharacters = &.{"."} },
112113
};
113114

114115
// Tries to validate that our server capabilities are actually implemented.
@@ -256,6 +257,33 @@ pub const Handler = struct {
256257
};
257258
}
258259

260+
pub fn @"textDocument/completion"(
261+
_: *Handler,
262+
arena: std.mem.Allocator,
263+
params: lsp.types.CompletionParams,
264+
) error{OutOfMemory}!lsp.ResultType("textDocument/completion") {
265+
std.log.debug("Received 'textDocument/completion' notification", .{});
266+
267+
if (params.context) |context| {
268+
std.log.info("completion triggered by {?s} {t}", .{
269+
context.triggerCharacter,
270+
context.triggerKind,
271+
});
272+
}
273+
274+
const completions = try arena.dupe(lsp.types.CompletionItem, &.{
275+
.{
276+
.label = "get",
277+
.detail = "get the value",
278+
},
279+
.{
280+
.label = "set",
281+
.detail = "set the value",
282+
},
283+
});
284+
return .{ .array_of_CompletionItem = completions };
285+
}
286+
259287
/// We received a response message from the client/editor.
260288
pub fn onResponse(
261289
_: *Handler,

0 commit comments

Comments
 (0)