This commit is contained in:
agra
2026-02-20 18:22:42 +02:00
parent 6f927361aa
commit 2f95810f9d
10 changed files with 510 additions and 77 deletions

View File

@@ -255,6 +255,23 @@ pub fn locationJson(allocator: std.mem.Allocator, uri: []const u8, range: Range)
);
}
/// Build a LocationLink JSON response (for go-to-definition with origin range).
pub fn locationLinkJson(allocator: std.mem.Allocator, target_uri: []const u8, target_range: Range, origin_range: Range) ![]const u8 {
const uri_escaped = try jsonString(allocator, target_uri);
return std.fmt.allocPrint(allocator,
"[{{\"originSelectionRange\":{{\"start\":{{\"line\":{d},\"character\":{d}}},\"end\":{{\"line\":{d},\"character\":{d}}}}}," ++
"\"targetUri\":{s}," ++
"\"targetRange\":{{\"start\":{{\"line\":{d},\"character\":{d}}},\"end\":{{\"line\":{d},\"character\":{d}}}}}," ++
"\"targetSelectionRange\":{{\"start\":{{\"line\":{d},\"character\":{d}}},\"end\":{{\"line\":{d},\"character\":{d}}}}}}}]",
.{
origin_range.start.line, origin_range.start.character, origin_range.end.line, origin_range.end.character,
uri_escaped,
target_range.start.line, target_range.start.character, target_range.end.line, target_range.end.character,
target_range.start.line, target_range.start.character, target_range.end.line, target_range.end.character,
},
);
}
/// Build a Hover JSON response.
pub fn hoverJson(allocator: std.mem.Allocator, contents: []const u8) ![]const u8 {
const escaped = try jsonString(allocator, contents);