diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-15 18:27:49 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 00:12:14 -0300 |
| commit | 4a3c5a48224cf542429504e8728e10c802e1fd52 (patch) | |
| tree | 92b9b0922d8e37abd0af68cc014433449be29f05 /test/output.zig | |
| parent | f3a9a1a9005024923f32e1acae5ecd509e9bbfd2 (diff) | |
| download | pardes-4a3c5a48224cf542429504e8728e10c802e1fd52.tar.gz pardes-4a3c5a48224cf542429504e8728e10c802e1fd52.zip | |
Highlight exact source occurrences in LSP references and goto results
Diffstat (limited to 'test/output.zig')
| -rw-r--r-- | test/output.zig | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/test/output.zig b/test/output.zig index 722f2e44..ede8e7dd 100644 --- a/test/output.zig +++ b/test/output.zig @@ -1337,3 +1337,47 @@ test "declaration context ellipses mark only final header lines before omitted s } } } + +test "LSP occurrence tint follows the supplied source span through context" { + const snippet = "\tfoo + 界 + foo;"; + const text = "const Box = struct {\n fn run() void {\n" ++ snippet ++ "\n foo();\n }\n};\n"; + for ([_]pardes.lsp.Kind{ .references, .definition }) |kind| { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 40 }); + defer p.deinit(); + const source = try p.setTestFile(text); + p.gpa.free(source.file.?.path); + source.file.?.path = try p.gpa.dupe(u8, "/occurrence.zig"); + p.locations_config = .{ .context = 1, .tscontext = true }; + p.presentation.enabled = false; + var input: std.Io.Writer.Allocating = .init(p.gpa); + defer input.deinit(); + const start = std.mem.lastIndexOf(u8, snippet, "foo").?; + try pardes.lsp.sourceSpanRow(&input.writer, source.file.?.path, 2, start, 2, start + 3, snippet); + try panes.Output.fillResults(p, 0, "/", .{ .query = kind }, "", try input.toOwnedSlice(), 0); + const id = source.search_pane.?; + const file = &p.panes[id].?.file.?; + var matches: usize = 0; + for (file.location_rows, 0..) |row, index| { + if (row.kind != .match) continue; + const line = modal.lineSlice(file.content, index); + try std.testing.expectEqualStrings(snippet, line[row.code_start..]); + try std.testing.expectEqual(start + 1, row.at.col); + try std.testing.expectEqual(start + 3, row.at.end_col); + matches += 1; + } + try std.testing.expectEqual(@as(usize, 1), matches); + pardes.layout.compute(p); + var frame = std.heap.ArenaAllocator.init(p.gpa); + defer frame.deinit(); + const surface = try p.render(frame.allocator()); + const chrome = pardes.ChromeTheme.fromTheme(p.theme()); + var marked: usize = 0; + for (surface.cells) |cell| { + if (!std.meta.eql(cell.style.bg, pardes.Color{ .rgb = chrome.search_bg })) continue; + try std.testing.expect(cell.text[0] == 'f' or cell.text[0] == 'o'); + marked += 1; + } + try std.testing.expectEqual(@as(usize, 3), marked); + try std.testing.expectEqualStrings(text, source.file.?.content); + } +} |
