optionals
This commit is contained in:
@@ -108,7 +108,8 @@ pub fn initializeResultJson(allocator: std.mem.Allocator) ![]const u8 {
|
||||
"\"semanticTokensProvider\":{{\"legend\":{{" ++
|
||||
"\"tokenTypes\":[\"namespace\",\"type\",\"enum\",\"struct\",\"parameter\",\"variable\",\"enumMember\",\"function\",\"keyword\",\"number\",\"string\",\"operator\"]," ++
|
||||
"\"tokenModifiers\":[\"declaration\",\"readonly\"]" ++
|
||||
"}},\"full\":true}}}}}}",
|
||||
"}},\"full\":true}}," ++
|
||||
"\"inlayHintProvider\":true}}}}",
|
||||
.{},
|
||||
);
|
||||
}
|
||||
@@ -358,3 +359,29 @@ pub fn publishDiagnosticsJson(allocator: std.mem.Allocator, uri: []const u8, dia
|
||||
try buf.appendSlice(allocator, "]}");
|
||||
return buf.items;
|
||||
}
|
||||
|
||||
pub const InlayHint = struct {
|
||||
line: u32,
|
||||
character: u32,
|
||||
label: []const u8,
|
||||
kind: u32 = 1, // 1 = Type
|
||||
padding_left: bool = true,
|
||||
padding_right: bool = false,
|
||||
};
|
||||
|
||||
/// Build inlay hints JSON array response.
|
||||
pub fn inlayHintsJson(allocator: std.mem.Allocator, hints: []const InlayHint) ![]const u8 {
|
||||
var buf = std.ArrayList(u8).empty;
|
||||
try buf.append(allocator, '[');
|
||||
for (hints, 0..) |hint, idx| {
|
||||
if (idx > 0) try buf.append(allocator, ',');
|
||||
const label_escaped = try jsonString(allocator, hint.label);
|
||||
const json = try std.fmt.allocPrint(allocator,
|
||||
"{{\"position\":{{\"line\":{d},\"character\":{d}}},\"label\":{s},\"kind\":{d},\"paddingLeft\":{s},\"paddingRight\":{s}}}",
|
||||
.{ hint.line, hint.character, label_escaped, hint.kind, if (hint.padding_left) "true" else "false", if (hint.padding_right) "true" else "false" },
|
||||
);
|
||||
try buf.appendSlice(allocator, json);
|
||||
}
|
||||
try buf.append(allocator, ']');
|
||||
return buf.items;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user