This commit is contained in:
agra
2026-02-11 02:22:00 +02:00
parent 89fc6427c4
commit 7bb4fe0c5f
7 changed files with 251 additions and 14 deletions

View File

@@ -204,7 +204,18 @@ pub const DocumentSymbol = struct {
/// Build completion items JSON array.
pub fn completionItemsJson(allocator: std.mem.Allocator, items: []const CompletionItem) ![]const u8 {
return completionItemsJsonInner(allocator, items, false);
}
/// Build a CompletionList object with isIncomplete: false, preventing the client
/// from supplementing results with its own word-based suggestions.
pub fn completionListJson(allocator: std.mem.Allocator, items: []const CompletionItem) ![]const u8 {
return completionItemsJsonInner(allocator, items, true);
}
fn completionItemsJsonInner(allocator: std.mem.Allocator, items: []const CompletionItem, as_list: bool) ![]const u8 {
var buf = std.ArrayList(u8).empty;
if (as_list) try buf.appendSlice(allocator, "{\"isIncomplete\":false,\"items\":");
try buf.append(allocator, '[');
for (items, 0..) |item, idx| {
if (idx > 0) try buf.append(allocator, ',');
@@ -225,6 +236,7 @@ pub fn completionItemsJson(allocator: std.mem.Allocator, items: []const Completi
}
}
try buf.append(allocator, ']');
if (as_list) try buf.append(allocator, '}');
return buf.items;
}