summaryrefslogtreecommitdiff
path: root/src/locations.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-25 11:40:05 -0300
committerGabriel Schneider <[email protected]>2026-10-25 12:24:05 -0300
commit685b4050bb0caaa95c4c6a209e69f7777469e9fc (patch)
treeb1c34301f9f1febd5e70dfdfee52425cdca0ef4a /src/locations.zig
parent29d753b420385d7ca214250909e3a33c85cfab8d (diff)
downloadpardes-685b4050bb0caaa95c4c6a209e69f7777469e9fc.tar.gz
pardes-685b4050bb0caaa95c4c6a209e69f7777469e9fc.zip
query: a row is its place as text, `path:line:col` then its code, the path the shortest a Look from the query pane resolves (Query.lookPath: relative, `../` included, when shorter, else absolute, never `@pN` but for a text with no file), aligned per group, the declaration headers `path:line`; its code coloured as its file's language colours it, the file painted whole on the worker (Stream.paintRows, highlightApart, kept in the locations cache, Query.Shades a walk a refill, Query.recolor in place as each lands) with the match tinted over it; the +Preview's places are the query's hits in its file (a Grep searched, a list fed), tinted and ticked, the row's one current and selected, as in a pane that already shows it; tests for B3 on an address, a saved list's Looks, the shortest path, the preview's places and colours, the worker's colours; fsearch, grep, lookrange, lsp-client, lsprelpath (now `../shade.zig`), stepgrain, tagbottom goldens: the address rows; docs/next-searchrows.md: the design and the numbers
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016u3hBPFfja5pK4EBRC1UVD
Diffstat (limited to 'src/locations.zig')
-rw-r--r--src/locations.zig34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/locations.zig b/src/locations.zig
index 6f086214..cdb228a6 100644
--- a/src/locations.zig
+++ b/src/locations.zig
@@ -814,6 +814,40 @@ pub const Cache = struct {
return .{ .analysis = next.analysis };
}
+ /// The analysis kept for `path` with its colours, if any, of whatever
+ /// source it was made from (a caller compares the lines it uses):
+ /// never parses. Borrowed, as `get`'s.
+ pub fn peek(cache: *const Cache, path: []const u8) ?struct { source: []const u8, colors: []const u8 } {
+ for (cache.entries[0..cache.len]) |entry| if (entry.colors_ready and std.mem.eql(u8, entry.path, path))
+ return .{ .source = entry.source, .colors = entry.analysis.colors };
+ return null;
+ }
+
+ /// `source`'s colours, worked out elsewhere (a worker's, Stream.paintRows),
+ /// kept for `path` in place of what was: copies of both.
+ pub fn put(cache: *Cache, gpa: std.mem.Allocator, path: []const u8, source: []const u8, colors: []const u8) !void {
+ if (path.len + source.len + colors.len > max_bytes) return error.SourceTooLarge;
+ const owned_path = try gpa.dupe(u8, path);
+ errdefer gpa.free(owned_path);
+ const owned_source = try gpa.dupe(u8, source);
+ errdefer gpa.free(owned_source);
+ const next: Entry = .{
+ .path = owned_path,
+ .source = owned_source,
+ .analysis = .{ .colors = try gpa.dupe(u8, colors) },
+ .declarations_ready = false,
+ .colors_ready = true,
+ };
+ for (cache.entries[0..cache.len], 0..) |entry, index| if (std.mem.eql(u8, entry.path, path)) {
+ cache.remove(gpa, index);
+ break;
+ };
+ while (cache.len == max_entries or cache.bytes > max_bytes - next.size()) cache.remove(gpa, 0);
+ cache.entries[cache.len] = next;
+ cache.len += 1;
+ cache.bytes += next.size();
+ }
+
fn remove(cache: *Cache, gpa: std.mem.Allocator, index: usize) void {
cache.bytes -= cache.entries[index].size();
cache.entries[index].deinit(gpa);