summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/output.zig44
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);
+ }
+}