summaryrefslogtreecommitdiff
path: root/src/lsp/lsp.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-15 18:27:49 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:14 -0300
commit4a3c5a48224cf542429504e8728e10c802e1fd52 (patch)
tree92b9b0922d8e37abd0af68cc014433449be29f05 /src/lsp/lsp.zig
parentf3a9a1a9005024923f32e1acae5ecd509e9bbfd2 (diff)
downloadpardes-4a3c5a48224cf542429504e8728e10c802e1fd52.tar.gz
pardes-4a3c5a48224cf542429504e8728e10c802e1fd52.zip
Highlight exact source occurrences in LSP references and goto results
Diffstat (limited to 'src/lsp/lsp.zig')
-rw-r--r--src/lsp/lsp.zig17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/lsp/lsp.zig b/src/lsp/lsp.zig
index ca19009a..9dd1da5a 100644
--- a/src/lsp/lsp.zig
+++ b/src/lsp/lsp.zig
@@ -85,10 +85,15 @@ pub fn row(out: *std.Io.Writer, path: []const u8, line: usize, col: usize, text:
// Input positions are zero-based and end-exclusive; displayed spans are one-based and inclusive.
pub fn spanRow(out: *std.Io.Writer, path: []const u8, line: usize, col: usize, end_line: usize, end_col: usize, text: []const u8) std.Io.Writer.Error!void {
- if (end_line != line or end_col <= col) return row(out, path, line, col, text);
- try out.print("{s}:{d}:{d}-{d} {s}\n", .{
- path, line + 1, col + 1, end_col, std.mem.trim(u8, text, " \t\r\n"),
- });
+ return sourceSpanRow(out, path, line, col, end_line, end_col, std.mem.trim(u8, text, " \t\r\n"));
+}
+
+/// Source bytes keep their indentation and trailing spaces so byte columns
+/// still identify the same token in the displayed snippet.
+pub fn sourceSpanRow(out: *std.Io.Writer, path: []const u8, line: usize, col: usize, end_line: usize, end_col: usize, text: []const u8) std.Io.Writer.Error!void {
+ try out.print("{s}:{d}:{d}", .{ path, line + 1, col + 1 });
+ if (end_line == line and end_col > col) try out.print("-{d}", .{end_col});
+ try out.print(" {s}\n", .{std.mem.trimEnd(u8, text, "\r\n")});
}
pub fn edit(out: *std.Io.Writer, start: usize, end: usize) std.Io.Writer.Error!void {
@@ -114,9 +119,10 @@ pub fn lineCol(source: []const u8, offset: usize) struct { line: usize, col: usi
}
test "LSP encoders report every insufficient output capacity" {
- const cases = [_]struct { kind: enum { row, span, edit, put }, expected: []const u8 }{
+ const cases = [_]struct { kind: enum { row, span, source_span, edit, put }, expected: []const u8 }{
.{ .kind = .row, .expected = "file:1:3 hi\n" },
.{ .kind = .span, .expected = "file:1:3-5 hi\n" },
+ .{ .kind = .source_span, .expected = "file:1:3-5 \t hi \t\n" },
.{ .kind = .edit, .expected = "@edit 1 3\n" },
.{ .kind = .put, .expected = "@put 1 3 hé%20%25%0A\n" },
};
@@ -127,6 +133,7 @@ test "LSP encoders report every insufficient output capacity" {
const result = switch (case.kind) {
.row => row(&out, "file", 0, 2, " hi \n"),
.span => spanRow(&out, "file", 0, 2, 0, 5, " hi \n"),
+ .source_span => sourceSpanRow(&out, "file", 0, 2, 0, 5, "\t hi \t\r\n"),
.edit => edit(&out, 1, 3),
.put => put(&out, 1, 3, "hé %\n"),
};