From 685b4050bb0caaa95c4c6a209e69f7777469e9fc Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sun, 25 Oct 2026 11:40:05 -0300 Subject: 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 Claude-Session: https://claude.ai/code/session_016u3hBPFfja5pK4EBRC1UVD --- docs/next-searchrows.md | 89 ++++++++ docs/search-proto-converge.md | 48 ++++- docs/typ/guide.typ | 9 +- src/Query.zig | 443 ++++++++++++++++++++++++++++++++++----- src/Stream.zig | 272 +++++++++++++++++++++++- src/locations.zig | 34 +++ src/ninep/ctl.zig | 5 +- test/snapshots/fsearch.golden | 12 +- test/snapshots/grep.golden | 2 +- test/snapshots/lookrange.golden | 16 +- test/snapshots/lsp-client.golden | 4 +- test/snapshots/lsprelpath.golden | 22 +- test/snapshots/lsprelpath.snap | 23 +- test/snapshots/stepgrain.golden | 12 +- test/snapshots/tagbottom.golden | 4 +- 15 files changed, 877 insertions(+), 118 deletions(-) create mode 100644 docs/next-searchrows.md diff --git a/docs/next-searchrows.md b/docs/next-searchrows.md new file mode 100644 index 00000000..79ffc444 --- /dev/null +++ b/docs/next-searchrows.md @@ -0,0 +1,89 @@ +# searchrows: query rows that are addresses, coloured as their files + +The author's ask (2026-10-25): the search results "should show Lookable +locations for the matches, and it should highlight the near text on the +preview/result pane", then "using treesitter for the highlight I mean", +then on the row format: "the row can be just path:line:row but the path +should be minimal i.e. it should be the smallest one that doesn't refer to +panes like @p1 but that resolves a Look". Change `tsyvmpux`, on +`zmluwpuv`. Positions, not a verdict. + +## The row + + Places.zig:163:8 pub fn firstFrom(hits: []const Hit, at: usize) usize { + Places.zig:237:19 const i = firstFrom(set.hits.items, at); + ../shade.zig:1:11 pub const Shade = enum { + +- `path:line:col`, then the line's code from its first non-blank: plain + text, so B3 anywhere on the address is a Look as anywhere, a sweep copies + it, and a frozen pane saved is a list of addresses that still work. +- The path is `Query.lookPath(buf, path, dir)`: the shortest text a Look + from the query pane resolves: relative to the pane's directory (`x`, + `sub/x`, `../x`) when strictly shorter, else absolute. A relative name a + Look would read as something else (`@p...`, `://`) stays absolute. One + function, used by every hit row and by the file and declaration headers + of Grep, `/`/All and the language server lists. +- On every row, `/` in the owner included: a bare `:12:5` would be looked + up in the +Search itself (a Look resolves against the pane it is in) and + a saved list would lose its file. +- A group's code starts in one column: the address padded to + `path + ':' + digits(longest line in the group) + ':' + 3`, then two + spaces (a column of four digits or more pushes its own row one cell). +- Declaration headers carry `path:line` in the same column; file headers + stay the bare path (itself a Look). + +## Colours + +- Rows: `Stream.paintRows` paints a whole file on the worker + (`syntax.highlightApart`, the same call as the anim paint-ahead): the text + of the pane that shows it, else read from disk there. It lands in the + locations cache beside Callstack's (`locations.Cache.put`); each row takes + its line's slice when the line still reads as the row does + (`Query.Shades`, one walk down each file a refill). Until then rows are + plain; on arrival `Query.recolor` colours every query pane's plain rows + in place and asks for the next file: one at a time, each (path, revision) + once a Grep (a 256 ring). The match tint (`decorateRow`) sits on top, its + position past the address (`code_start`). Not on the loop, not in a 9P + write (asked again on the next step), not without workers. +- The +Preview: colours are its own pane's (painted as any file pane), and + the query's hits in that file are its places (`Places.search` literal for + a Grep, `Places.feed` from the rows for a list), tinted and ticked, the + current row's one current and selected, centred. A pane that already + shows the file gets the same (`selectPlace`). + +## Numbers + +`zz grep rows timings` (src/Stream.zig, `GREP_TIMES=`): Debug, a +TestShell worker, 160x50, the stress file (src/layout.zig x17, 1.22 MB, +29002 lines), typing `pane` three times with 400 ms of frames after each +key, then Enter on 2000 rows. Load 2.4-3.0 before, 2.7-2.8 after; after is +three runs. + +| frame work | before | after | +|---|---|---| +| keystroke (update + render) p50 / p90 / max | 2.2 / 4.2 / 6.0 ms | 2.0-2.1 / 2.9-6.5 / 4.4-6.7 ms | +| refill frame (rows remade) p50 / p90 / max | 4.4 / 5.2 / 5.2 ms | 4.8-5.1 / 5.4-6.1 / 5.4-6.1 ms | +| other frames p50 / p90 / max | 0.9 / 1.3 / 10.6 ms | 0.9 / 1.2-1.3 / 10.0-10.2 ms | +| Enter (2000 rows written) | 27.0 ms | 28.2-28.7 ms | +| frames after Enter p50 / max | 0.9 / 1.7 ms | 0.9 / 1.3-1.7 ms | + +Rows coloured after Enter: 1718 of 2000; the other 282 are plain in the +file's own colours too (checked against `highlightApart` of the file). A +refill costs ~0.4 ms more (the wider rows and the Shades walk), inside the +noise of the keystroke column; the paint itself never shows on the loop. + +## Pushback and rough edges + +- The current row's address is barely legible: the address's dim location + colour on the current row's mark tint (visible in the screenshot). The + thing B3 aims at should read; a brighter location fg on the marked row is + a one-line theme decision I left to you. +- A text with no file (a +New scratch) has no path any Look resolves, so + its `/` rows keep `@pN`, the only address that works there. +- `lsprelpath` asserted the opposite policy ("must NOT become + `../shade.zig`"); the author's shortest-path rule wins, the script says so. +- Rows of a file over 4 MB, and of markdown/typst (their injections share + parsers, so no worker paints them) stay plain; a disk file changed after + it was painted keeps plain rows for its changed lines until the next Grep. +- One file painted at a time: a Grep over hundreds of files colours file + by file (each lands in a frame); a worker per file if that is slow. diff --git a/docs/search-proto-converge.md b/docs/search-proto-converge.md index 99adbc2c..7a3e361a 100644 --- a/docs/search-proto-converge.md +++ b/docs/search-proto-converge.md @@ -40,13 +40,40 @@ only the prompts that are not search. `Search ` is the builtin under the three argument paths (`config.leader_args`, pick's table). -**Rows look like Callstack's**: a gutter line number, the hit's line with -the match tinted (every match on a line tinted, one row a line), under the -declaration it is in (once a parse exists, see below), under the file -(Grep, the LSP lists), under `@pN name (count)` in serial order (All). -B3 on a row's line number looks at its address; B3 on its code is a word -Look as anywhere; B2 on line 1 runs it again. The pane has no gutter of its -own, and its rows are read-only while live (queryline's clampEdit). +**Rows look like Callstack's**: each row's place first, as text, +`path:line:col`, the path the shortest a Look from the query pane +resolves (relative to its directory, `../` included, when that is shorter, +else absolute; `Query.lookPath`), never an `@pN` but for a text with no +file, padded so a group's code starts in one column, then +the hit's line coloured as its file's language colours it, the match +tinted over that (every match on a line tinted, one row a line); under the +declaration it is in (once a parse exists, see below; the header has its +`path:line` too), under the file (Grep, the LSP lists), under `@pN name +(count)` in serial order (All). B3 on the address is a Look as anywhere, a +sweep copies it, and a frozen pane saved is a list of addresses that still +work; B3 on its code is a word Look; B2 on line 1 runs it again. The pane +has no gutter of its own, and its rows are read-only while live +(queryline's clampEdit). The address is on every row, `/`'s included: +a bare `:12:5` would be looked up in the +Search itself (a Look resolves +against the pane it is in), and a saved list would lose its file. + +The rows' colours are their files' whole (`Stream.paintRows`): a file is +painted once on the worker (`syntax.highlightApart`, the text of the pane +that shows it, else read there from disk), kept in the locations cache +beside Callstack's, and each row takes its line's slice when the line +still reads as the row does (`Query.Shades`, one walk down each file a +refill). Until then the rows are plain; when a file lands, every query +pane's plain rows from it are coloured in place (`Query.recolor`), which +asks for the next file, one at a time. Without workers (tests) the rows +stay plain. + +**The +Preview is the file as its own pane shows it**: its colours are +the file's (`colorAlgo` `.source`, painted ahead as any pane), and the +query's hits in it are its places (a Grep's searched there as in an open +pane, a list's fed from its rows), tinted and ticked, the current row's +one current and selected, centred with its neighbours round it. A pane +that already shows the file gets the same: its places, the row's one +selected. **Keys** on line 1, typing: Ctrl-n / Ctrl-p (and Down / Up, `config.query_next` / `query_prev`) step the current row; Enter lands; Esc cancels. Tab stays the @@ -197,9 +224,10 @@ of 100 (the Debug SafeAllocator's stack capture per allocation was 30% at - LookNext / LookPrev do not step query rows (their addresses are in row metadata, not text). -- Grep rows carry no syntax colours; `/` rows are coloured where the - owner's highlights cover them (zeros elsewhere, so no fragment parse per - refill). +- Rows of a file bigger than 4 MB, of markdown and typst (their + injections share parsers, so no worker paints them) stay plain; a disk + file changed after it was painted keeps plain rows for its changed + lines until the next Grep. - Rail ticks are not carried over the detached wire (a detached frontend shows tints, not ticks). - In a window too short for the group (4 rows), only the query pane's tag diff --git a/docs/typ/guide.typ b/docs/typ/guide.typ index 61ba5455..58e5d907 100644 --- a/docs/typ/guide.typ +++ b/docs/typ/guide.typ @@ -175,7 +175,7 @@ is born #word("SearchRows") rows tall and never resizes itself; nothing found is a count of `0` in its tag, not an exit. #pairs( - [#key("/") `vw`], [every match in the text tinted and ticked on its scroll rail, the first after the cursor selected; the rows under line 1 are the lines holding it, a line number in the gutter, each under the declaration it is in], + [#key("/") `vw`], [every match in the text tinted and ticked on its scroll rail, the first after the cursor selected; the rows under line 1 are the lines holding it, each its place as text first (`file:line:col`, the shortest path a #word("Look") from the pane resolves), then the line coloured as the file is, under the declaration it is in], [#keys("Ctrl-n", "Ctrl-p")], [the next or previous match, typing; the text follows it], [#key("Enter")], [the keyboard on the match, the pattern in `/`, the rows kept as text (#word("Save") keeps them as a file)], [#keys("n", "N")], [the next or previous match in the text, round the end without a word], @@ -202,8 +202,11 @@ typing, #keys("n", "N") and #keys("j", "k") in the pane's normal mode); #btn("B1") on the rows places the caret and selects, as in any pane, and moves nothing else. #key("Enter") lands the current row, making the preview that file's pane where it stands. -#btn("B3") on a row's line number looks at the row; #btn("B2") on line 1 -runs it again. The next search from the same pane reuses its query pane, +The preview colours the file as its own pane does, and the query's hits +in it are its places, tinted and ticked, the current one selected. +#btn("B3") on a row's place goes there, as on any address; the rows kept +as text (#word("Save")) are a list of places that still work. +#btn("B2") on line 1 runs it again. The next search from the same pane reuses its query pane, its kept rows back on #key("Esc") (#word("SearchPane") `new`: a pane each; #word("SearchPlace") `column`: in a finder column at the right). A PDF's and a terminal's #key("/") still ask on the message row and list a diff --git a/src/Query.zig b/src/Query.zig index 11db8579..09b46f3b 100644 --- a/src/Query.zig +++ b/src/Query.zig @@ -10,11 +10,12 @@ //! matched fuzzy (Names.zig), text by regex. Editing the word changes //! the source. //! -//! The rows look like a Callstack's: the hit line with the match tinted -//! under a gutter line number, under the declaration it is in (when the -//! owner's parse exists: never made here on the loop), under its file -//! (Grep) or under `@pN name (count)` (All). They are addresses, all text: -//! B3 on one looks, B2 on line 1 runs it again. Wherever a row points into +//! The rows look like a Callstack's: the hit's place as text, +//! `path:line:col`, then its line coloured as its file is (painted on a +//! worker, Shades) with the match tinted, under the declaration it is in +//! (when the owner's parse exists: never made here on the loop), under its +//! file (Grep) or under `@pN name (count)` (All). They are addresses, all +//! text: B3 on one looks, B2 on line 1 runs it again. Wherever a row points into //! an open pane's text, that pane's places (Places.zig) show the set: //! tints, rail ticks, the current one selected. A row pointing at a file //! no pane shows is shown in the +Preview attached under this pane; Enter @@ -399,6 +400,10 @@ fn save(p: *Pardes, rp: *Pane, q: *Query) !Saved { /// on a tick. Nothing here is synchronous with an edit of the owner: its /// places shift (Places.shift) and the rows follow once it stands a frame. pub fn produceAll(p: *Pardes, tick: bool, keyed: bool) void { + if (p.stream.rows_later) { + p.stream.rows_later = false; + recolor(p); + } for (p.panes, 0..) |slot, id| { const pane = slot orelse continue; if (pane.query == null) continue; @@ -735,7 +740,7 @@ fn setRows(p: *Pardes, rp: *Pane, out: *std.ArrayList(u8), rows: *std.ArrayList( } else { locations.freeRows(p.gpa, f.location_rows); f.location_rows = meta; - f.syntax_dirty = true; + dropHighlights(p, f); } } else { File.setContent(p, f, content); @@ -758,41 +763,127 @@ fn gpa_free_pager(p: *Pardes, f: *File.State) void { f.pager_spans = &.{}; } -/// The gutter a file of `nlines` lines numbers its rows in: two spaces, -/// the number right-aligned, two spaces. -fn gutterWidth(nlines: usize) usize { +/// The room a group of rows gives its addresses, so that their code +/// starts in one column: the path, a colon, its longest line number, a +/// colon, three digits of column (a longer one pushes its code on a cell). +fn addressWidth(rel: []const u8, max_line: usize) usize { var digits: usize = 1; - var n = nlines; + var n = max_line; while (n >= 10) : (n /= 10) digits += 1; - return 2 + @max(3, digits) + 2; + return rel.len + 1 + digits + 1 + 3; } -fn writeHitRow(p: *Pardes, out: *std.ArrayList(u8), rows: *std.ArrayList(locations.Row), width: usize, path: []const u8, line_no: usize, whole: []const u8, col: usize, end: usize, shade: []const u8) !void { +/// One hit row: its place as text first, `rel:line:col` (`rel` the path +/// as Look finds it from the query pane's directory), so that B3 on it is a +/// Look as anywhere, a sweep copies it and a saved list is a list of +/// addresses; padded to `width`, then two spaces and the line's code from +/// its first non-blank. Coloured as its file is: `shade`, the line's +/// colours when its pane has them painted, else the whole file's from the +/// worker (Shades). +fn writeHitRow(p: *Pardes, out: *std.ArrayList(u8), rows: *std.ArrayList(locations.Row), sh: *Shades, width: usize, rel: []const u8, path: []const u8, line_no: usize, whole: []const u8, col: usize, end: usize, shade: []const u8) !void { var lead: usize = 0; while (lead < whole.len and (whole[lead] == ' ' or whole[lead] == '\t')) lead += 1; const code = std.mem.trimEnd(u8, whole[lead..], "\r"); - var buf: [4096 + 32]u8 = undefined; - var num: [24]u8 = undefined; - const number = std.fmt.bufPrint(&num, "{d}", .{line_no}) catch ""; - const pad = width -| 2 -| number.len; - if (pad + number.len + 2 + code.len > buf.len) return; - @memset(buf[0..pad], ' '); - @memcpy(buf[pad..][0..number.len], number); - @memcpy(buf[pad + number.len ..][0..2], " "); - @memcpy(buf[pad + number.len + 2 ..][0..code.len], code); - const text = buf[0 .. pad + number.len + 2 + code.len]; - const gutter = pad + number.len + 2; - try writeRow(p, out, rows, text, .{ + var buf: [8192]u8 = undefined; + const address = std.fmt.bufPrint(&buf, "{s}:{d}:{d}", .{ rel, line_no, col + 1 }) catch return; + const gutter = @max(width, address.len) + 2; + if (gutter + code.len > buf.len) return; + @memset(buf[address.len..gutter], ' '); + @memcpy(buf[gutter..][0..code.len], code); + try writeRow(p, out, rows, buf[0 .. gutter + code.len], .{ .kind = .match, .source_column = lead, .path = @constCast(path), .at = .{ .line = line_no, .col = col + 1, .end_line = line_no, .end_col = @max(col + 1, end) }, - .location_end = gutter, + .location_end = address.len, .code_start = gutter, - .colors = @constCast(if (shade.len >= lead) shade[lead..][0..@min(shade.len - lead, code.len)] else &.{}), + .colors = @constCast(if (shade.len >= lead + code.len) shade[lead..][0..code.len] else sh.of(p, path, line_no, code, lead)), }); } +/// Rows' syntax colours from their file's whole (as Callstack's rows are), +/// kept in the locations cache once a worker has painted it +/// (Stream.paintRows): the line found going down the file a row at a time, +/// so a refill walks each file once. A file not painted, or whose line no +/// longer reads as the row does, is asked for (once a refill) and its rows +/// are plain till it lands (`recolor`). +const Shades = struct { + path: []const u8 = "", + source: []const u8 = "", + colors: []const u8 = &.{}, + /// The line (1-based) that starts at `at` in `source`. + line: usize = 1, + at: usize = 0, + asked: bool = false, + + /// The colours of `code`, which is line `line_no` of `path` from byte + /// `column` on, or none. + fn of(sh: *Shades, p: *Pardes, path: []const u8, line_no: usize, code: []const u8, column: usize) []const u8 { + if (path.len == 0 or line_no == 0 or code.len == 0) return &.{}; + if (!std.mem.eql(u8, path, sh.path)) { + // its own copy: a caller's path is often a buffer it reuses + sh.* = .{ .path = p.scratch.allocator().dupe(u8, path) catch return &.{} }; + if (p.locations_cache.peek(path)) |e| { + sh.source = e.source; + sh.colors = e.colors; + } + } + if (sh.colors.len == 0 or sh.colors.len != sh.source.len) return sh.ask(p); + if (line_no < sh.line) { + sh.line = 1; + sh.at = 0; + } + while (sh.line < line_no) : (sh.line += 1) { + sh.at = (std.mem.indexOfScalarPos(u8, sh.source, sh.at, '\n') orelse return sh.ask(p)) + 1; + } + const line = sh.source[sh.at .. std.mem.indexOfScalarPos(u8, sh.source, sh.at, '\n') orelse sh.source.len]; + if (column + code.len > line.len or !std.mem.eql(u8, line[column..][0..code.len], code)) return sh.ask(p); + return sh.colors[sh.at + column ..][0..code.len]; + } + + fn ask(sh: *Shades, p: *Pardes) []const u8 { + if (!sh.asked) Stream.paintRows(p, sh.path); + sh.asked = true; + return &.{}; + } +}; + +/// A file's colours arrived (Stream.paintRows): every query pane's hit +/// rows still plain, live or frozen, coloured from what is painted now, in +/// place; the first row of a file not painted yet asks for it, so they are +/// painted one after another. +pub fn recolor(p: *Pardes) void { + for (p.panes) |slot| { + const rp = slot orelse continue; + if (rp.query == null) continue; + const f = &rp.file.?; + var sh: Shades = .{}; + var lines = std.mem.splitScalar(u8, f.content, '\n'); + var changed = false; + for (f.location_rows) |row| { + const text = lines.next() orelse break; + if (row.kind != .match or row.location_end == 0 or row.at.line == 0 or row.colors.len == 0) continue; + if (std.mem.indexOfNone(u8, row.colors, &.{0}) != null) continue; + const code = text[@min(row.code_start, text.len)..]; + const got = sh.of(p, row.path, row.at.line, code[0..@min(code.len, row.colors.len)], row.source_column); + if (got.len == 0) continue; + @memcpy(row.colors[0..got.len], got); + changed = true; + } + if (changed) dropHighlights(p, f); + } +} + +/// The pane's painted colours let go, so the next frame paints them from +/// its rows again: with its text the same, a frame would keep the old ones +/// (refreshHighlights keeps a painting that covers the view). +fn dropHighlights(p: *Pardes, f: *File.State) void { + if (f.highlights.len > 0) p.tree_sitter_gpa.free(f.highlights); + f.highlights = &.{}; + f.highlight_start = 0; + f.syntax_dirty = true; +} + /// The path a row of pane `tp`'s text says: its file's, or `@pN` for a /// text that is no file (a list, a scratch). fn addressOf(arena: std.mem.Allocator, tp: *const Pane) []const u8 { @@ -801,17 +892,47 @@ fn addressOf(arena: std.mem.Allocator, tp: *const Pane) []const u8 { return std.fmt.allocPrint(arena, config.pane_addr ++ "{d}", .{tp.serial}) catch ""; } +/// The shortest text that names file `path` to a Look from directory +/// `dir` (a Look joins a relative word to its pane's directory): the path +/// relative to `dir` (`x`, `sub/x`, `../x`) when that is shorter, else the +/// absolute one, never an `@pN`. A relative name a Look would read as +/// something else (a pane address, a URL) stays absolute. `buf` holds a +/// relative one that climbs. +pub fn lookPath(buf: []u8, path: []const u8, dir: []const u8) []const u8 { + // a relative pane's (a test's): its directory's prefix off, as ever + if (path.len == 0 or path[0] != '/' or dir.len == 0 or dir[0] != '/') return Names.relative(path, dir); + const d = std.mem.trimEnd(u8, dir, "/"); + // the last slash both share, ending a whole component of `dir` + var k: usize = 0; + var i: usize = 0; + while (i < path.len and i <= d.len) : (i += 1) { + if (path[i] == '/' and (i == d.len or d[i] == '/')) k = i; + if (i == d.len or d[i] != path[i]) break; + } + const ups = std.mem.count(u8, d[k..], "/"); + const rest = path[k + 1 ..]; + if (ups * 3 + rest.len >= path.len or ups * 3 + rest.len > buf.len) return path; + for (0..ups) |u| @memcpy(buf[u * 3 ..][0..3], "../"); + @memcpy(buf[ups * 3 ..][0..rest.len], rest); + const rel = buf[0 .. ups * 3 + rest.len]; + if (std.mem.startsWith(u8, rel, config.pane_addr) or std.mem.indexOf(u8, rel, "://") != null) return path; + return rel; +} + /// Rows from pane `tp`'s places: one a line with any (two on a line are /// one row: everywhere's bug), the declaration they are in over them when /// its parse exists, from place `from` on, `budget` rows at most. The /// place it stopped before. -fn writePlacesRows(p: *Pardes, q: *Query, out: *std.ArrayList(u8), rows: *std.ArrayList(locations.Row), tp: *Pane, from: usize, budget: *usize) !usize { +fn writePlacesRows(p: *Pardes, q: *Query, out: *std.ArrayList(u8), rows: *std.ArrayList(locations.Row), tp: *Pane, dir: []const u8, from: usize, budget: *usize) !usize { const f = &tp.file.?; const set = &tp.places; const hits = set.hits.items; const index = try File.lineIndex(p.gpa, f); - const width = gutterWidth(index.len); const path = addressOf(p.scratch.allocator(), tp); + var relbuf: [4096]u8 = undefined; + const rel = lookPath(&relbuf, path, dir); + const width = addressWidth(rel, index.len); + var sh: Shades = .{}; const decls = ownerDecls(p, f, false) orelse &.{}; var decl_now: ?usize = null; var i: usize = @min(from, hits.len); @@ -852,15 +973,20 @@ fn writePlacesRows(p: *Pardes, q: *Query, out: *std.ArrayList(u8), rows: *std.Ar const head_ls = index[decls[di].start_line]; const head_le = if (decls[di].start_line + 1 < index.len) index[decls[di].start_line + 1] - 1 else f.content.len; const head = std.mem.trim(u8, f.content[head_ls..head_le], " \t\r"); - var hb: [600]u8 = undefined; - const text = std.fmt.bufPrint(&hb, " {s}", .{head[0..@min(head.len, 560)]}) catch ""; + // Its address too, `rel:line`, in the column the hits' are. + var hb: [8192]u8 = undefined; + const address = std.fmt.bufPrint(&hb, "{s}:{d}", .{ rel, decls[di].start_line + 1 }) catch ""; + const gutter = @max(width, address.len) + 2; + const shown = head[0..@min(head.len, hb.len -| gutter)]; + @memset(hb[address.len..gutter], ' '); + @memcpy(hb[gutter..][0..shown.len], shown); try q.items.append(p.gpa, .{ .kind = .header, .serial = tp.serial }); - try writeRow(p, out, rows, text, .{ .kind = .context, .declaration = true, .path = @constCast(path), .at = .{ .line = decls[di].start_line + 1 }, .location_end = 0, .code_start = 0 }); + try writeRow(p, out, rows, hb[0 .. gutter + shown.len], .{ .kind = .context, .declaration = true, .path = @constCast(path), .at = .{ .line = decls[di].start_line + 1 }, .location_end = address.len, .code_start = gutter }); }; } const shade: []const u8 = if (f.highlights.len > 0 and ls >= f.highlight_start and le <= f.highlight_start + f.highlights.len) f.highlights[ls - f.highlight_start .. le - f.highlight_start] else &.{}; try q.items.append(p.gpa, .{ .kind = .hit, .serial = tp.serial, .hit = i, .n = n }); - try writeHitRow(p, out, rows, width, path, line + 1, f.content[ls..le], hits[i].start - ls, @min(hits[i].end, le) - ls, shade); + try writeHitRow(p, out, rows, &sh, width, rel, path, line + 1, f.content[ls..le], hits[i].start - ls, @min(hits[i].end, le) - ls, shade); i += n; } return i; @@ -891,7 +1017,7 @@ fn makeTextRows(p: *Pardes, id: usize, oid: usize, full: bool) !void { var hb: [64]u8 = undefined; try noteRow(p, q, &out, &rows, std.fmt.bufPrint(&hb, " ... {d} places before these", .{from}) catch " ..."); } - q.window.hi = try writePlacesRows(p, q, &out, &rows, owner, from, &budget); + q.window.hi = try writePlacesRows(p, q, &out, &rows, owner, std.fs.path.dirname(rp.file.?.path) orelse "/", from, &budget); q.window.lo = @min(from, q.window.hi); } if (q.more) try noteRow(p, q, &out, &rows, " ... and more: the count says how many"); @@ -974,7 +1100,7 @@ fn makeAllRows(p: *Pardes, id: usize) !void { const head = std.fmt.bufPrint(&hb, config.pane_addr ++ "{d} {s} ({d})", .{ tp.serial, name[0..@min(name.len, 500)], set.hits.items.len }) catch ""; try q.items.append(p.gpa, .{ .kind = .header, .serial = tp.serial }); try writeRow(p, &out, &rows, head, .{ .kind = .context, .declaration = true, .path = @constCast(addressOf(p.scratch.allocator(), tp)), .at = .{}, .location_end = 0, .code_start = 0 }); - _ = try writePlacesRows(p, q, &out, &rows, tp, 0, &budget); + _ = try writePlacesRows(p, q, &out, &rows, tp, std.fs.path.dirname(rp.file.?.path) orelse "/", 0, &budget); } if (budget == 0) try noteRow(p, q, &out, &rows, " ... and more: the count says how many"); setRows(p, rp, &out, &rows); @@ -1084,6 +1210,8 @@ fn makeGrepRows(p: *Pardes, id: usize, full: bool) !void { const q = rp.query.?; const dir = std.fs.path.dirname(rp.file.?.path) orelse "/"; const at: usize = @min(q.grep_at, q.found.items.len -| 1); + // nothing current before these rows: the first one's shown once it is + const shown = q.current != null; q.items.clearRetainingCapacity(); var out: std.ArrayList(u8) = .empty; defer out.deinit(p.gpa); @@ -1097,18 +1225,29 @@ fn makeGrepRows(p: *Pardes, id: usize, full: bool) !void { try noteRow(p, q, &out, &rows, std.fmt.bufPrint(&hb, " ... {d} lines before these", .{lo}) catch " ..."); } var current: ?usize = null; + var sh: Shades = .{}; + var width: usize = 0; + var relbuf: [4096]u8 = undefined; for (q.found.items[lo..hi], lo..) |fd, i| { - const rel = q.found_bytes.items[fd.path..][0..fd.path_len]; - const path = std.fmt.bufPrint(&pathbuf, "{s}/{s}", .{ std.mem.trimEnd(u8, dir, "/"), rel }) catch continue; - if (!std.mem.eql(u8, rel, last_path)) { - last_path = rel; + const name = q.found_bytes.items[fd.path..][0..fd.path_len]; + const path = std.fmt.bufPrint(&pathbuf, "{s}/{s}", .{ std.mem.trimEnd(u8, dir, "/"), name }) catch continue; + const rel = lookPath(&relbuf, path, dir); + if (!std.mem.eql(u8, name, last_path)) { + last_path = name; try q.items.append(p.gpa, .{ .kind = .header }); try writeRow(p, &out, &rows, rel, .{ .kind = .context, .path = @constCast(path), .at = .{}, .location_end = 0, .code_start = 0 }); + // the file's rows in this window, for the widest line number + var max_line: usize = fd.line; + for (q.found.items[i..hi]) |next| { + if (!std.mem.eql(u8, q.found_bytes.items[next.path..][0..next.path_len], name)) break; + max_line = @max(max_line, next.line); + } + width = addressWidth(rel, max_line); } const code = q.found_bytes.items[fd.code..][0..fd.code_len]; if (i == at) current = q.items.items.len; try q.items.append(p.gpa, .{ .kind = .hit, .hit = i, .n = 1 }); - try writeHitRow(p, &out, &rows, 9, path, fd.line, code, fd.col, fd.end, &.{}); + try writeHitRow(p, &out, &rows, &sh, width, rel, path, fd.line, code, fd.col, fd.end, &.{}); } if (hi < q.found.items.len) { var hb: [64]u8 = undefined; @@ -1122,7 +1261,7 @@ fn makeGrepRows(p: *Pardes, id: usize, full: bool) !void { q.current = current orelse firstHit(q); countGrepCurrent(q); showCurrent(rp); - if (q.current == null) blankPreview(p, id); + if (q.current == null) blankPreview(p, id) else if (!shown) showTarget(p, id); } /// What the disk walk passed over, said under the rows: a search that @@ -1258,16 +1397,28 @@ fn makeListRows(p: *Pardes, id: usize, pat: []const u8) !void { var last_path: []const u8 = ""; var pathbuf: [4096 + 8]u8 = undefined; var n: usize = 0; - for (sorted.items) |ln| { + var sh: Shades = .{}; + var width: usize = 0; + var relbuf: [4096]u8 = undefined; + for (sorted.items, 0..) |ln, li| { if (ln.len == 0) continue; if (pat.len > 0 and std.ascii.findIgnoreCase(ln, pat) == null) continue; const t = look.parsePathLine(ln); if (t.at.line == 0) continue; const path = if (t.path.len > 0 and t.path[0] == '/') t.path else std.fmt.bufPrint(&pathbuf, "{s}/{s}", .{ std.mem.trimEnd(u8, dir, "/"), t.path }) catch continue; + const rel = lookPath(&relbuf, path, dir); if (!std.mem.eql(u8, t.path, last_path)) { last_path = t.path; try q.items.append(p.gpa, .{ .kind = .header }); - try writeRow(p, &out, &rows, Names.relative(t.path, dir), .{ .kind = .context, .path = @constCast(path), .at = .{}, .location_end = 0, .code_start = 0 }); + try writeRow(p, &out, &rows, rel, .{ .kind = .context, .path = @constCast(path), .at = .{}, .location_end = 0, .code_start = 0 }); + // sorted by place: the file's last row has its widest line number + var max_line: usize = t.at.line; + for (sorted.items[li..]) |next| { + const tn = look.parsePathLine(next); + if (!std.mem.eql(u8, tn.path, t.path)) break; + max_line = @max(max_line, tn.at.line); + } + width = addressWidth(rel, max_line); } const rest = std.mem.trimStart(u8, ln[@min(t.end, ln.len)..], " \t:"); const col0 = t.at.col -| 1; @@ -1293,7 +1444,7 @@ fn makeListRows(p: *Pardes, id: usize, pat: []const u8) !void { break; } try q.items.append(p.gpa, .{ .kind = .hit, .n = 1, .serial = shown_in }); - try writeHitRow(p, &out, &rows, 9, path, t.at.line, code, col, end, &.{}); + try writeHitRow(p, &out, &rows, &sh, width, rel, path, t.at.line, code, col, end, &.{}); n += 1; } if (n == 0) try noteRow(p, q, &out, &rows, " nothing"); @@ -1520,11 +1671,26 @@ fn showTarget(p: *Pardes, id: usize) void { const line0 = meta.at.line -| 1; const visible = line0 >= tf.scroll and line0 < tf.scroll + tp.rows; if (meta.at.line > 0) look.focusPaneLine(p, i, meta.at, if (visible) .keep else .center); + _ = selectPlace(p, tp, rp.serial, meta.at); return; } displayPreview(p, id, meta.path, meta.at); } +/// The place a row points at (its line and column) made current in pane +/// `tp`'s places, when query `serial` fed them: selected and in view, as +/// the owner's are. False when there is none there. +fn selectPlace(p: *Pardes, tp: *Pane, serial: u32, at: look.Spot) bool { + const f = if (tp.file) |*file| file else return false; + const set = &tp.places; + if (set.from != serial or !set.started or at.line == 0 or at.line > File.nlines(p.gpa, f)) return false; + const ls = File.lineStart(p.gpa, f, at.line - 1); + const i = Places.firstFrom(set.hits.items, ls + (at.col -| 1)); + if (i >= set.hits.items.len or (at.line < File.nlines(p.gpa, f) and set.hits.items[i].start >= File.lineStart(p.gpa, f, at.line))) return false; + set.goTo(tp, i, false); + return true; +} + // ---- the +Preview ---- /// The +Preview under query pane `qid`, if it has one: by serial. @@ -1597,6 +1763,8 @@ fn displayPreview(p: *Pardes, qid: usize, path: []const u8, at: look.Spot) void f.scroll = 0; f.syntax_dirty = true; pane.hscroll = 0; + // another file: its own places, found below + pane.places.clear(p.gpa); p.sync(); } look.clearNavigationSelection(p, pane); @@ -1609,6 +1777,36 @@ fn displayPreview(p: *Pardes, qid: usize, path: []const u8, at: look.Spot) void return; } look.focusPaneLine(p, id, at, .center); + // The query's hits in this file are the preview's places, tinted and + // ticked as in the file's own pane would be, the row's one current and + // selected; the view centred on it, its neighbours round it. + const qp = p.panes[qid].?; + const q = qp.query.?; + switch (q.source) { + .grep => if (parse(q.asked)) |a| pane.places.search(p, pane, .list, qp.serial, a.pat, true, null, false), + .refs, .defs, .impls, .diagnostics => if (pane.places.from != qp.serial or !pane.places.shows(pane)) { + var hits: std.ArrayList(Places.Hit) = .empty; + defer hits.deinit(p.gpa); + const dir = std.fs.path.dirname(qp.file.?.path) orelse "/"; + const nlines = File.nlines(p.gpa, f); + var pathbuf: [4096 + 8]u8 = undefined; + var lines = std.mem.splitScalar(u8, q.lsp_rows, '\n'); + while (lines.next()) |ln| { + const t = look.parsePathLine(ln); + if (t.at.line == 0 or t.at.line > nlines) continue; + const full = if (t.path.len > 0 and t.path[0] == '/') t.path else std.fmt.bufPrint(&pathbuf, "{s}/{s}", .{ std.mem.trimEnd(u8, dir, "/"), t.path }) catch continue; + if (!std.mem.eql(u8, full, f.path)) continue; + const ls = File.lineStart(p.gpa, f, t.at.line - 1); + const le = std.mem.indexOfScalarPos(u8, f.content, ls, '\n') orelse f.content.len; + const col = @min(t.at.col -| 1, le - ls); + const end = @min(if (t.at.end_col > 0 and t.at.end_line == t.at.line) t.at.end_col else col + 1, le - ls); + hits.append(p.gpa, .{ .start = ls + col, .end = ls + @max(end, col + 1) }) catch break; + } + pane.places.feed(p, pane, qp.serial, hits.items, null); + }, + else => {}, + } + if (selectPlace(p, pane, qp.serial, at)) return; if (at.end_line == 0 or at.end_col <= at.col) pane.body.msel = .{ .active = true, .r0 = @intCast(at.line - 1), .r1 = @intCast(at.line - 1) }; } @@ -1914,8 +2112,9 @@ pub fn clampEdit(p: *Pardes, t: *panes.Text, old: []const u8, new: []u8) ?[]u8 { return out; } -/// B3 on a row's gutter (its line number): the row's address, as a +Diff -/// line's prefix is its place (exec.operandAt). Null off a gutter. +/// B3 on a row's address text: the address whole, as a +Diff line's +/// prefix is its place (exec.operandAt), so a path with a space in it is +/// still one; the text says the same place. Null off the address. pub fn rowAddress(pane: *const Pane, row: usize, col: usize, buf: []u8) ?[]const u8 { if (pane.query == null) return null; const f = pane.file orelse return null; @@ -2122,9 +2321,9 @@ test "a / query: Enter lands and freezes, the register filled, n and N step sile try std.testing.expectEqual(Places.Provenance.search, pane.places.provenance); const frozen = try std.testing.allocator.dupe(u8, qp.file.?.content); defer std.testing.allocator.free(frozen); - // the rows: one a line (gamma alpha has one), a gutter number each - try std.testing.expect(std.mem.indexOf(u8, frozen, " 1 alpha one\n") != null); - // B3 on a row's line number is its address; on its code, no address + // the rows: one a line (gamma alpha has one), each its place as text + try std.testing.expect(std.mem.indexOf(u8, frozen, "\ntest.txt:1:1 alpha one\n") != null); + // B3 on a row's address is its address; on its code, no address var abuf: [256]u8 = undefined; const addr = rowAddress(qp, 1, 2, &abuf).?; try std.testing.expect(std.mem.endsWith(u8, addr, ":1:1")); @@ -2511,3 +2710,151 @@ test "B1 on a query pane's rows places the caret and selects, nothing else, the try std.testing.expectEqual(@as(usize, 0), p.active); try std.testing.expectEqual(@as(i32, 3), pane.body.cur_row); } + +test "a query row's place is its text: the match tinted after it, B3 on it opens the place, the rows saved and read again still Look" { + if (!filesystem.platform_has_fs) return; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 48 }); + defer p.deinit(); + const a = try testFileIn(p, &tmp, "a.txt", "zero\none needle\ntwo\nthree needle here\n"); + leader(p, "fg"); + typeKeys(p, "needle"); + settle(p); + const qid = queryPane(p).?; + const qp = p.panes[qid].?; + const f = &qp.file.?; + // each row `path:line:col`, relative to the pane's directory, the code + // after it in one column + try std.testing.expect(std.mem.indexOf(u8, f.content, "\na.txt:2:5 one needle\n") != null); + try std.testing.expect(std.mem.indexOf(u8, f.content, "\na.txt:4:7 three needle here\n") != null); + // the match's tint where the match is, past the address + var row4: usize = 0; + var lines = std.mem.splitScalar(u8, f.content, '\n'); + var i: usize = 0; + while (lines.next()) |line| : (i += 1) { + if (i >= f.location_rows.len) break; + const meta = f.location_rows[i]; + if (meta.kind != .match or meta.location_end == 0) continue; + const dec = Output.decorateRow(f.output, line, meta); + try std.testing.expectEqualStrings("needle", line[dec.mark_start..dec.mark_end]); + try std.testing.expect(look.parsePathLine(line[0..meta.location_end]).at.line == meta.at.line); + if (meta.at.line == 4) row4 = i; + } + try std.testing.expect(row4 > 0); + // B3 on the address: the place, in the pane that shows it + a.body.cur_row = 0; + p.acknowledgePanelPresentation(&.{}); + const r = p.rects[qid]; + const y = r.y + qp.tag_rows + @as(u16, @intCast(row4)) - @as(u16, @intCast(qp.scroll())); + const x = r.x + config.GUTTER + File.gutterWidth(qp) + 3; + p.update(.{ .mouse = .{ .button = .right, .kind = .press, .col = x, .row = y } }); + p.update(.{ .mouse = .{ .button = .right, .kind = .release, .col = x, .row = y } }); + try std.testing.expectEqual(@as(usize, 0), p.active); + try std.testing.expectEqual(@as(i32, 3), a.body.cur_row); + // the rows as a plain text in that directory (what Save writes): a + // Look at a row's address word still goes there + const saved = try std.testing.allocator.dupe(u8, f.content); + defer std.testing.allocator.free(saved); + p.newScratchBelow(0); + const sid = p.active; + const sp = p.panes[sid].?; + File.setContent(p, &sp.file.?, try p.gpa.dupe(u8, saved)); + try std.testing.expect(sp.query == null and sp.file.?.location_rows.len == 0); + const at = std.mem.indexOf(u8, saved, "a.txt:2:5").?; + const line = saved[at .. std.mem.indexOfScalarPos(u8, saved, at, '\n').?]; + const word = look.expandedWord(line, 3).?; + a.body.cur_row = 0; + look.lookAt(p, sid, line[word.lo..word.hi]); + try std.testing.expectEqual(@as(usize, 0), p.active); + try std.testing.expectEqual(@as(i32, 1), a.body.cur_row); +} + +test "the +Preview: the query's hits in its file are its places, the row's one current and selected, coloured as the file is" { + if (!filesystem.platform_has_fs) return; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const text = "const needle = 1;\nconst hay = 2;\nfn f() void {\n _ = needle;\n}\npub const needle_too = needle;\n"; + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "b.zig", .data = text }); + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 60 }); + defer p.deinit(); + _ = try testFileIn(p, &tmp, "a.txt", "x\n"); + leader(p, "fg"); + typeKeys(p, "needle"); + settle(p); + const qid = queryPane(p).?; + // the first row shown in the preview as the rows land; a step, the next + const pid = previewOf(p, qid).?; + try std.testing.expectEqual(@as(?usize, 0), p.panes[pid].?.places.current); + p.update(.{ .key = .{ .cp = 'n', .ctrl = true } }); + const pv = p.panes[pid].?; + try std.testing.expect(std.mem.endsWith(u8, pv.file.?.path, "/b.zig")); + // its places: every `needle` in the file, as its own pane would find them + var expected: std.ArrayList(Places.Hit) = .empty; + defer expected.deinit(std.testing.allocator); + var from: usize = 0; + while (std.mem.indexOfPos(u8, text, from, "needle")) |at| : (from = at + 1) try expected.append(std.testing.allocator, .{ .start = at, .end = at + 6 }); + try std.testing.expectEqualSlices(Places.Hit, expected.items, pv.places.hits.items); + // the current row's (line 4, column 9) current and selected + try std.testing.expectEqual(@as(?usize, 1), pv.places.current); + var sel = pv.body.primaryRange(pv.file.?.content, 0); + try std.testing.expectEqual(expected.items[1].start, @min(sel.anchor, sel.head)); + // the next row: the next place, the preview's places standing + p.update(.{ .key = .{ .cp = 'n', .ctrl = true } }); + try std.testing.expectEqual(pid, previewOf(p, qid).?); + try std.testing.expectEqual(@as(?usize, 2), pv.places.current); + sel = pv.body.primaryRange(pv.file.?.content, 0); + try std.testing.expectEqual(expected.items[2].start, @min(sel.anchor, sel.head)); + // its colours the file's, as its own pane paints them + if (!syntax.enabled) return; + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + _ = try p.render(frame.allocator()); + const pf = &pv.file.?; + try std.testing.expect(pf.highlights.len > 0 and std.mem.indexOfNone(u8, pf.highlights, &.{0}) != null); + const own = try syntax.highlightFileRange(p.tree_sitter_gpa, pf.path, pf.content, pf.highlight_start, pf.highlight_start + pf.highlights.len); + defer p.tree_sitter_gpa.free(own); + try std.testing.expectEqualSlices(u8, own, pf.highlights); +} + +test "a row's address is the shortest path a Look from the query pane resolves: in its directory, under it, above it, else absolute" { + if (!filesystem.platform_has_fs) return; + if (!pardes.lsp.supports.contains(.references)) return; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.createDirPath(std.testing.io, "q/sub"); + for ([_][]const u8{ "q/sub/deep.txt", "up.txt" }) |name| try tmp.dir.writeFile(std.testing.io, .{ .sub_path = name, .data = "one\ntwo\n" }); + var root_buf: [std.fs.max_path_bytes]u8 = undefined; + const root = root_buf[0..try tmp.dir.realPath(std.testing.io, &root_buf)]; + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 40 }); + defer p.deinit(); + _ = try testFileIn(p, &tmp, "q/here.txt", "one\ntwo\n"); + // another tree, where the climb out would be longer than the path + const far = "/etc/passwd"; + if (std.c.access(far, std.c.F_OK) != 0) return; + const answer = try std.fmt.allocPrint(std.testing.allocator, "{s}/q/here.txt:2:1 two\n{s}/q/sub/deep.txt:2:1 two\n{s}/up.txt:2:1 two\n" ++ far ++ ":1:1 root\n", .{ root, root, root }); + defer std.testing.allocator.free(answer); + fillList(p, 0, .refs, answer); + const qp = p.panes[queryPane(p).?].?; + const f = &qp.file.?; + const dir = std.fs.path.dirname(f.path).?; + var lines = std.mem.splitScalar(u8, f.content, '\n'); + var seen: std.ArrayList([]const u8) = .empty; + defer seen.deinit(std.testing.allocator); + for (f.location_rows) |row| { + const line = lines.next().?; + if (row.kind != .match or row.location_end == 0) continue; + const addr = line[0..row.location_end]; + try seen.append(std.testing.allocator, addr); + // Looked at from the pane: the row's file, at its line + var realbuf: [4096]u8 = undefined; + const t = look.resolve(p, addr, dir, &realbuf); + try std.testing.expectEqualStrings(row.path, t.file.path); + try std.testing.expectEqual(row.at.line, t.file.at.line); + } + for ([_][]const u8{ "here.txt:2:1", "sub/deep.txt:2:1", "../up.txt:2:1", far ++ ":1:1" }) |want| { + for (seen.items) |got| { + if (std.mem.eql(u8, got, want)) break; + } else return error.TestUnexpectedResult; + } +} diff --git a/src/Stream.zig b/src/Stream.zig index e42d4a16..da7d12eb 100644 --- a/src/Stream.zig +++ b/src/Stream.zig @@ -218,6 +218,20 @@ painted_ahead: u32 = 0, painted_on_loop: u32 = 0, /// The view the last paint was asked from, and which way it was going. ahead_seen: struct { serial: u32 = 0, scroll: usize = 0, dir: i2 = 1 } = .{}, +/// A file's colours for query rows being worked out (paintRows), one at a +/// time, its own task beside the scroll's. ponytail: one file at a time, +/// the next asked when it lands (Query.recolor); a worker per file if a +/// Grep of hundreds of files colours too slowly. +rows_paint: ?PaintTask = null, +/// The files (a hash of path and revision) asked since the last Grep +/// began: each asked once, so a file whose colours never fit its rows +/// (changed on disk since) is not painted again and again. ponytail: a +/// ring of 256; the oldest forgotten. +rows_asked: [256]u64 = @splat(0), +rows_asked_at: u8 = 0, +/// Rows asked for their colours while a 9P write was served: asked again +/// on the next step (Query.produceAll). +rows_later: bool = false, pub fn deinit(s: *Stream, gpa: std.mem.Allocator) void { s.cancelTask(); @@ -244,7 +258,7 @@ pub fn cancelParse(s: *Stream) void { /// The paints' workers told to stop and joined (the session's end). pub fn cancelPaint(s: *Stream) void { - for ([_]*?PaintTask{ &s.paint, &s.paint_retired }) |slot| { + for ([_]*?PaintTask{ &s.paint, &s.paint_retired, &s.rows_paint }) |slot| { const t = slot.* orelse continue; slot.* = null; t.job.stop.store(true, .release); @@ -310,11 +324,69 @@ pub fn paintAhead(p: *Pardes, serial: u32, revision: u32, path: []const u8, cont p.emit(.{ .search = .{ .gen = gen } }); } -fn paintWork(job: *PaintJob, ctx: ?*anyopaque, sink: Sink) void { +/// A file's colours for the query rows that show its lines, the whole +/// file painted on a worker (rows coloured as the file's language colours +/// them, as Callstack's are): the text of the pane that shows it, else read +/// from disk there. Kept in the locations cache when it lands, where the +/// rows find them (Query.Shades). Not without workers (the rows stay +/// plain), nor for a file bigger than `max_rows_paint_bytes`, nor twice for +/// one revision of a file. +pub fn paintRows(p: *Pardes, path: []const u8) void { + const s = &p.stream; + if (s.rows_paint != null or p.host.vtable.search == null) return; + // Asked while a 9P write is served (a script's Grep): not now, as no + // paint is (the write would wait for it to settle); the next step asks. + if (p.fs.serving) { + s.rows_later = true; + return; + } + if (!syntax.readyApart(path)) return; + var content: ?[]const u8 = null; + var revision: u32 = 0; + for (p.panes) |slot| if (slot) |pane| if (pane.file) |f| if (f.output == null and std.mem.eql(u8, f.path, path)) { + content = f.content; + revision = f.revision; + break; + }; + if (content) |c| if (c.len > max_rows_paint_bytes) return; + const key = std.hash.Wyhash.hash(revision, path) | 1; + if (std.mem.indexOfScalar(u64, &s.rows_asked, key) != null) return; + const job = p.gpa.create(PaintJob) catch return; + const path_copy = p.gpa.dupe(u8, path) catch { + p.gpa.destroy(job); + return; + }; + const source = p.gpa.dupe(u8, content orelse "") catch { + p.gpa.free(path_copy); + p.gpa.destroy(job); + return; + }; + s.rows_asked[s.rows_asked_at] = key; + s.rows_asked_at +%= 1; + s.paint_count +%= 1; + const gen = paint_bit | (s.paint_count & ~paint_bit); + job.* = .{ .gpa = p.gpa, .out = p.gpa, .gen = gen, .serial = 0, .revision = revision, .start = 0, .path = path_copy, .source = source }; + s.rows_paint = .{ .job = job }; + p.emit(.{ .search = .{ .gen = gen } }); +} + +/// The biggest file whose colours query rows are painted from. +const max_rows_paint_bytes = 4 << 20; + +fn paintWork(io: std.Io, job: *PaintJob, ctx: ?*anyopaque, sink: Sink) void { + // A file's colours for query rows (paintRows, serial 0) with no text + // given: read here, off the loop, and sent back with the colours, the + // text they are of. + const read: []u8 = if (job.serial == 0 and job.source.len == 0) + std.Io.Dir.cwd().readFileAlloc(io, job.path, job.out, .limited(max_rows_paint_bytes)) catch @constCast(&[_]u8{}) + else + @constCast(&[_]u8{}); + const source = if (read.len > 0) read else job.source; // Stopped or failed, it still answers (with nothing), so the loop // knows to join it. - const styles: []u8 = syntax.highlightApart(job.out, job.path, job.source, &job.stop) catch @constCast(&[_]u8{}); - _ = sink(ctx, .{ .gen = job.gen, .styles = styles, .painted = .{ .serial = job.serial, .revision = job.revision, .start = job.start }, .end = .done }); + const styles: []u8 = syntax.highlightApart(job.out, job.path, source, &job.stop) catch @constCast(&[_]u8{}); + const text: []u8 = if (job.serial != 0 or read.len > 0) read else job.out.dupe(u8, job.source) catch @constCast(&[_]u8{}); + _ = sink(ctx, .{ .gen = job.gen, .rows = text, .styles = styles, .painted = .{ .serial = job.serial, .revision = job.revision, .start = job.start }, .end = .done }); } /// A paint's answer: its task joined, its stretch kept for when the view @@ -322,6 +394,22 @@ fn paintWork(job: *PaintJob, ctx: ?*anyopaque, sink: Sink) void { fn receivePaint(p: *Pardes, b: *const Batch) void { const s = &p.stream; const painted = b.painted.?; + // A file's colours for query rows: kept where the rows find them, and + // the rows coloured from them (which asks for the next file). + if (s.rows_paint) |t| if (t.job.gen == b.gen) { + s.rows_paint = null; + if (t.future) |f| { + pardes.turn.yield(); + var future = f; + future.await(t.io.?); + pardes.turn.back(); + } + defer t.job.deinit(); + p.locations_cache.put(p.tree_sitter_gpa, t.job.path, b.rows, b.styles) catch {}; + panes.Query.recolor(p); + p.needs_frame = true; + return; + }; // Its task joined: it has sent its last, so the join is a return away. for ([_]*?PaintTask{ &s.paint, &s.paint_retired }) |slot| if (slot.*) |t| if (t.job.gen == b.gen) { slot.* = null; @@ -436,6 +524,7 @@ pub fn query(p: *Pardes, target: u32, kind: Kind, pattern: []const u8, dir: []co s.first_ns = null; s.state = .waiting; s.due_ns = if (how == .typed) p.now_ns + debounce_ns else p.now_ns; + if (kind == .grep) s.rows_asked = @splat(0); } /// Over: the worker canceled, nothing more of it lands. @@ -502,11 +591,11 @@ pub fn start(io: std.Io, gpa: std.mem.Allocator, p: *Pardes, gen: u32, ctx: ?*an const s = &p.stream; // A paint's generation: its own task, its own worker. if (gen & paint_bit != 0) { - if (s.paint) |*t| if (t.job.gen == gen and t.future == null) { + for ([_]*?PaintTask{ &s.paint, &s.rows_paint }) |slot| if (slot.*) |*t| if (t.job.gen == gen and t.future == null) { t.job.out = gpa; - t.future = io.concurrent(paintWork, .{ t.job, ctx, sink }) catch { + t.future = io.concurrent(paintWork, .{ io, t.job, ctx, sink }) catch { const job = t.job; - s.paint = null; + slot.* = null; job.deinit(); return; }; @@ -555,6 +644,16 @@ fn makeJob(gpa: std.mem.Allocator, s: *const Stream) !*Job { /// the whole search on the loop, the turn out for it, its batches taken in /// as a worker's would be. Its cap is a hard stop. pub fn runHere(p: *Pardes, gen: u32) void { + // A paint with no worker to run it (a shell not threaded yet): let go, + // never left to hold its slot; the rows or the view ask again. + if (gen & paint_bit != 0) { + const s = &p.stream; + for ([_]*?PaintTask{ &s.paint, &s.rows_paint }) |slot| if (slot.*) |t| if (t.job.gen == gen and t.future == null) { + slot.* = null; + t.job.deinit(); + }; + return; + } if (comptime !filesystem.platform_has_fs) { p.stream.state = .failed; return; @@ -1395,3 +1494,162 @@ test "Stream: a Grep stops at its 2000 lines and waits; More in the query pane's try testing.expectEqual(@as(usize, 3000), qp.query.?.found.items.len); try testing.expect(!qp.query.?.capped); } + +test "zz grep rows timings: a Grep of about 2000 rows on the stress file, a worker (GREP_TIMES=)" { + const Key = pardes.Key; + const path_z = std.c.getenv("GREP_TIMES") orelse return error.SkipZigTest; + const path = std.mem.span(path_z); + const bytes = try std.Io.Dir.cwd().readFileAlloc(testing.io, path, testing.allocator, .limited(8 << 20)); + defer testing.allocator.free(bytes); + const p = try Pardes.init(testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 50 }); + defer p.deinit(); + const pane = try p.setTestFile(bytes); + p.gpa.free(pane.file.?.path); + pane.file.?.path = try p.gpa.dupe(u8, path); + p.advance(1); + var shell: TestShell = .init(); + TestShell.attach(p); + defer { + p.stream.cancelTask(); + p.stream.cancelParse(); + p.stream.cancelPaint(); + shell.q.deinit(); + } + var frame = std.heap.ArenaAllocator.init(testing.allocator); + defer frame.deinit(); + _ = try p.render(frame.allocator()); + const Stats = struct { + fn print(name: []const u8, xs: []u64) void { + if (xs.len == 0) return; + std.mem.sort(u64, xs, {}, std.sort.asc(u64)); + std.debug.print("{s}: n {d} p50 {d} us p90 {d} us max {d} us\n", .{ name, xs.len, xs[xs.len / 2] / 1000, xs[xs.len * 9 / 10] / 1000, xs[xs.len - 1] / 1000 }); + } + }; + var keys: std.ArrayList(u64) = .empty; + defer keys.deinit(testing.allocator); + var refills: std.ArrayList(u64) = .empty; + defer refills.deinit(testing.allocator); + var idle: std.ArrayList(u64) = .empty; + defer idle.deinit(testing.allocator); + panes.Query.open(p, 0, .grep, "", true); + const qid = p.active; + const q = p.panes[qid].?.query.?; + for (0..3) |round| { + for ("pane") |c| { + const t0 = now(); + p.advance(t0); + p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + _ = frame.reset(.retain_capacity); + _ = try p.render(frame.allocator()); + try keys.append(testing.allocator, now() - t0); + // the frames till the next key: the debounce, the batches, the paints + const until = now() + 400 * std.time.ns_per_ms; + while (now() < until) { + const made = q.made_gen; + const t1 = now(); + p.advance(t1); + shell.pump(p); + p.update(.tick); + _ = frame.reset(.retain_capacity); + _ = try p.render(frame.allocator()); + try (if (q.made_gen != made) &refills else &idle).append(testing.allocator, now() - t1); + testing.io.sleep(.fromMilliseconds(2), .awake) catch {}; + } + } + // back to an empty pattern for the next round + if (round < 2) for (0..4) |_| p.update(.{ .key = .{ .cp = Key.backspace } }); + } + // Enter: the whole list frozen, 2000 rows, and the frames after it. + var after: std.ArrayList(u64) = .empty; + defer after.deinit(testing.allocator); + const t3 = now(); + p.advance(t3); + p.update(.{ .key = .{ .cp = Key.enter } }); + _ = frame.reset(.retain_capacity); + _ = try p.render(frame.allocator()); + const t_enter = now() - t3; + const until = now() + 1000 * std.time.ns_per_ms; + while (now() < until) { + const t1 = now(); + p.advance(t1); + shell.pump(p); + p.update(.tick); + _ = frame.reset(.retain_capacity); + _ = try p.render(frame.allocator()); + try after.append(testing.allocator, now() - t1); + testing.io.sleep(.fromMilliseconds(2), .awake) catch {}; + } + var coloured: usize = 0; + for (p.panes[qid].?.file.?.location_rows) |row| coloured += @intFromBool(row.kind == .match and std.mem.indexOfNone(u8, row.colors, &.{0}) != null); + std.debug.print("grep rows: {d} found ({s}), {d} rows frozen, {d} coloured; Enter (2000 rows written) {d} us\n", .{ q.found.items.len, @tagName(p.stream.used), p.panes[qid].?.file.?.location_rows.len, coloured, t_enter / 1000 }); + Stats.print("frames after Enter", after.items); + Stats.print("keystroke (update + render)", keys.items); + Stats.print("refill frame (pump + tick + render, rows remade)", refills.items); + Stats.print("other frames", idle.items); +} + +test "Stream: a Grep's rows are coloured as their file's language colours them, the file painted on a worker, the match tint on top" { + if (comptime !filesystem.platform_has_fs) return; + if (!syntax.enabled or !syntax.readyApart("c.zig")) return; + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + const text = "const std = @import(\"std\");\npub fn value() u32 {\n return 42; // value\n}\n"; + try tmp.dir.writeFile(testing.io, .{ .sub_path = "c.zig", .data = text }); + var root_buf: [4096]u8 = undefined; + const root = root_buf[0..try tmp.dir.realPath(testing.io, &root_buf)]; + const p = try Pardes.init(testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 }); + defer p.deinit(); + // the file open in the pane that asks: its text painted, not the disk's + const pane = try p.setTestFile(text); + p.gpa.free(pane.file.?.path); + pane.file.?.path = try std.fs.path.join(p.gpa, &.{ root, "c.zig" }); + var shell: TestShell = .init(); + TestShell.attach(p); + defer { + p.stream.cancelTask(); + p.stream.cancelPaint(); + shell.q.deinit(); + } + panes.Query.open(p, 0, .grep, "value", false); + const qid = for (p.panes, 0..) |slot, i| { + if (slot) |qp| if (qp.query != null) break i; + } else return error.NoQueryPane; + const f = &p.panes[qid].?.file.?; + var halt: std.atomic.Value(bool) = .init(false); + const own = try syntax.highlightApart(testing.allocator, "c.zig", text, &halt); + defer testing.allocator.free(own); + var arena = std.heap.ArenaAllocator.init(testing.allocator); + defer arena.deinit(); + const until = now() + 10 * std.time.ns_per_s; + var coloured: usize = 0; + while (now() < until) { + p.advance(now()); + shell.pump(p); + p.update(.tick); + // a frame each, as a shell draws: the rows painted before their colours land + _ = arena.reset(.retain_capacity); + _ = try p.render(arena.allocator()); + coloured = 0; + for (f.location_rows) |row| if (row.kind == .match and row.location_end > 0 and std.mem.indexOfNone(u8, row.colors, &.{0}) != null) { + coloured += 1; + }; + if (coloured == 2 and p.stream.rows_paint == null) break; + testing.io.sleep(.fromMilliseconds(2), .awake) catch {}; + } + try testing.expectEqual(@as(usize, 2), coloured); + // and painted: the frame's colours are the rows' + _ = arena.reset(.retain_capacity); + _ = try p.render(arena.allocator()); + // each row's colours its line's, byte for byte; the match tinted over them + var lines = std.mem.splitScalar(u8, f.content, '\n'); + for (f.location_rows) |row| { + const line = lines.next().?; + if (row.kind != .match or row.location_end == 0) continue; + const ls = @import("modal.zig").lineStartOffset(text, row.at.line - 1); + try testing.expectEqualSlices(u8, own[ls + row.source_column ..][0..row.colors.len], row.colors); + const at = @intFromPtr(line.ptr) - @intFromPtr(f.content.ptr) + row.code_start - f.highlight_start; + try testing.expectEqualSlices(u8, row.colors, f.highlights[at..][0..row.colors.len]); + const dec = panes.Output.decorateRow(f.output, line, row); + try testing.expectEqualStrings("value", line[dec.mark_start..dec.mark_end]); + } +} 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); diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index d9bd4372..9cb96667 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -3059,8 +3059,9 @@ test "a script's Grep and Find fill the pane's one query pane, a row a line unde const rows = grepped.file.?.content; try testing.expect(std.mem.startsWith(u8, rows, "Grep bravo\n")); try testing.expect(std.mem.indexOf(u8, rows, "\nother.txt\n") != null); - try testing.expect(std.mem.indexOf(u8, rows, "2 bravo here\n") != null); - try testing.expect(std.mem.indexOf(u8, rows, "3 three bravo\n") != null); + // each row its place as text, `path:line:col`, the code in one column + try testing.expect(std.mem.indexOf(u8, rows, "\nother.txt:2:1 bravo here\n") != null); + try testing.expect(std.mem.indexOf(u8, rows, "\nother.txt:3:7 three bravo\n") != null); try testing.expectEqual(@as(usize, 2), grepped.query.?.total); try testing.expectEqual(Status.ok, wr(p, Node.of(serialOf(p), .exec), "Find other\n").reply.status); const found = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, root_exec, 0, 64).bytes, "\n"), 10)).?].?; diff --git a/test/snapshots/fsearch.golden b/test/snapshots/fsearch.golden index f7e5bba6..b195e7a5 100644 --- a/test/snapshots/fsearch.golden +++ b/test/snapshots/fsearch.golden @@ -31,9 +31,9 @@ == snap typing grid=180x31 cursor=7,10 |9: ^ +Search 1/3 Del |10: /MARK -|11: 2 MARK a -|12: 6 MARK b -|13: 10 MARK c +|11: g.txt:2:1 MARK a +|12: g.txt:6:1 MARK b +|13: g.txt:10:1 MARK c == style typing grid=180x31 |0: 0-1 d,#1d2824, 2-179 #b2c3b8,#1d2824, |1: 0-1 d,#887455, 2-89 #becfc4,#314738, 90-91 #becfc4,#887455, 92-179 #b2c3b8,#1d2824, @@ -46,9 +46,9 @@ |8: 0-0 d,#5e4923, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f5f7ee,#3c614a, 11-11 #f5f7ee,#0d1410, 12-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, |9: 0-1 #000000,#add38a, 2-89 #becfc4,#314738, 90-90 #becfc4,#608269, 91-179 #becfc4,#0d1410, |10: 0-0 d,#608269, 1-1 d,#0d1410, 2-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, -|11: 0-0 d,#608269, 1-1 d,#0d1410, 2-5 d,#243a2d, 6-8 #59675c,#243a2d, 9-12 #f7e4a5,#5e4923, 13-13 #f7e4a5,#243a2d, 14-89 #e5eee5,#243a2d, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, -|12: 0-0 d,#608269, 1-5 d,#0d1410, 6-8 #59675c,#0d1410, 9-12 #f7e4a5,#352e19, 13-13 #f7e4a5,#0d1410, 14-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, -|13: 0-0 d,#608269, 1-4 d,#0d1410, 5-8 #59675c,#0d1410, 9-12 #f7e4a5,#352e19, 13-13 #f7e4a5,#0d1410, 14-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, +|11: 0-0 d,#608269, 1-1 d,#0d1410, 2-15 #59675c,#243a2d, 16-19 #f7e4a5,#5e4923, 20-20 #f7e4a5,#243a2d, 21-89 #e5eee5,#243a2d, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, +|12: 0-0 d,#608269, 1-1 d,#0d1410, 2-15 #59675c,#0d1410, 16-19 #f7e4a5,#352e19, 20-20 #f7e4a5,#0d1410, 21-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, +|13: 0-0 d,#608269, 1-1 d,#0d1410, 2-15 #59675c,#0d1410, 16-19 #f7e4a5,#352e19, 20-20 #f7e4a5,#0d1410, 21-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, |14: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, |15: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, |16: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, diff --git a/test/snapshots/grep.golden b/test/snapshots/grep.golden index 6dbe19fa..165839f7 100644 --- a/test/snapshots/grep.golden +++ b/test/snapshots/grep.golden @@ -23,7 +23,7 @@ |9: ^ +Search 1/3 Del |10: Grep TARGET |11: a.txt -|12: 1 hello TARGET one +|12: a.txt:1:7 hello TARGET one |13: /tmp/pardes-snap/grep/cwd/+Preview Del |14: 1 == snap second grid=180x31 cursor=13,10 diff --git a/test/snapshots/lookrange.golden b/test/snapshots/lookrange.golden index 2c0aa63d..8f5908bb 100644 --- a/test/snapshots/lookrange.golden +++ b/test/snapshots/lookrange.golden @@ -71,8 +71,8 @@ == snap hit1 grid=150x31 cursor=17,15 |21: +Search 2/2 Save Unattach Del |22: /NEEDLE -|23: 7 gg NEEDLE gg -|24: 8 hhhh NEEDLE +|23: r.txt:7:4 gg NEEDLE gg +|24: r.txt:8:6 hhhh NEEDLE == style hit1 grid=150x31 |14: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-9 #e5eee5,#0d1410, 10-15 #e5eee5,#352e19, 16-149 #e5eee5,#0d1410, |15: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-11 #e5eee5,#0d1410, 12-17 #f5f7ee,#3c614a, 18-149 #f5f7ee,#0d1410, @@ -80,21 +80,21 @@ |18: 0-0 d,#e5eee5, 1-149 d,#0d1410, |21: 0-1 d,#496656, 2-149 #b2c3b8,#1d2824, |22: 0-0 d,#608269, 1-1 d,#0d1410, 2-149 #e5eee5,#0d1410, -|23: 0-0 d,#608269, 1-5 d,#0d1410, 6-8 #59675c,#0d1410, 9-11 #e5eee5,#0d1410, 12-17 #f7e4a5,#352e19, 18-18 #f7e4a5,#0d1410, 19-149 #e5eee5,#0d1410, -|24: 0-0 d,#608269, 1-1 d,#0d1410, 2-5 d,#243a2d, 6-8 #59675c,#243a2d, 9-13 #e5eee5,#243a2d, 14-19 #f7e4a5,#5e4923, 20-149 #f7e4a5,#243a2d, +|23: 0-0 d,#608269, 1-1 d,#0d1410, 2-14 #59675c,#0d1410, 15-17 #e5eee5,#0d1410, 18-23 #f7e4a5,#352e19, 24-24 #f7e4a5,#0d1410, 25-149 #e5eee5,#0d1410, +|24: 0-0 d,#608269, 1-1 d,#0d1410, 2-14 #59675c,#243a2d, 15-19 #e5eee5,#243a2d, 20-25 #f7e4a5,#5e4923, 26-149 #f7e4a5,#243a2d, == snap hit2 grid=150x31 cursor=15,14 == style hit2 grid=150x31 |14: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-9 #e5eee5,#0d1410, 10-15 #f5f7ee,#3c614a, 16-16 #f5f7ee,#0d1410, 17-149 #e5eee5,#0d1410, |15: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-11 #e5eee5,#0d1410, 12-17 #e5eee5,#352e19, 18-149 #e5eee5,#0d1410, |16: 0-0 d,#e5eee5, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, |18: 0-0 d,#5e4923, 1-149 d,#0d1410, -|23: 0-0 d,#608269, 1-5 d,#0d1410, 6-8 #59675c,#0d1410, 9-11 #e5eee5,#0d1410, 12-17 #f7e4a5,#5e4923, 18-18 #f7e4a5,#0d1410, 19-149 #e5eee5,#0d1410, -|24: 0-0 d,#608269, 1-1 d,#0d1410, 2-5 d,#243a2d, 6-8 #59675c,#243a2d, 9-13 #e5eee5,#243a2d, 14-19 #f7e4a5,#352e19, 20-149 #f7e4a5,#243a2d, +|23: 0-0 d,#608269, 1-1 d,#0d1410, 2-14 #59675c,#0d1410, 15-17 #e5eee5,#0d1410, 18-23 #f7e4a5,#5e4923, 24-24 #f7e4a5,#0d1410, 25-149 #e5eee5,#0d1410, +|24: 0-0 d,#608269, 1-1 d,#0d1410, 2-14 #59675c,#243a2d, 15-19 #e5eee5,#243a2d, 20-25 #f7e4a5,#352e19, 26-149 #f7e4a5,#243a2d, == snap back grid=150x31 cursor=17,15 == style back grid=150x31 |14: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-9 #e5eee5,#0d1410, 10-15 #e5eee5,#352e19, 16-149 #e5eee5,#0d1410, |15: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-11 #e5eee5,#0d1410, 12-17 #f5f7ee,#3c614a, 18-149 #f5f7ee,#0d1410, |16: 0-0 d,#5e4923, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, |18: 0-0 d,#e5eee5, 1-149 d,#0d1410, -|23: 0-0 d,#608269, 1-5 d,#0d1410, 6-8 #59675c,#0d1410, 9-11 #e5eee5,#0d1410, 12-17 #f7e4a5,#352e19, 18-18 #f7e4a5,#0d1410, 19-149 #e5eee5,#0d1410, -|24: 0-0 d,#608269, 1-1 d,#0d1410, 2-5 d,#243a2d, 6-8 #59675c,#243a2d, 9-13 #e5eee5,#243a2d, 14-19 #f7e4a5,#5e4923, 20-149 #f7e4a5,#243a2d, +|23: 0-0 d,#608269, 1-1 d,#0d1410, 2-14 #59675c,#0d1410, 15-17 #e5eee5,#0d1410, 18-23 #f7e4a5,#352e19, 24-24 #f7e4a5,#0d1410, 25-149 #e5eee5,#0d1410, +|24: 0-0 d,#608269, 1-1 d,#0d1410, 2-14 #59675c,#243a2d, 15-19 #e5eee5,#243a2d, 20-25 #f7e4a5,#5e4923, 26-149 #f7e4a5,#243a2d, diff --git a/test/snapshots/lsp-client.golden b/test/snapshots/lsp-client.golden index f3d7006e..670d6a86 100644 --- a/test/snapshots/lsp-client.golden +++ b/test/snapshots/lsp-client.golden @@ -20,9 +20,9 @@ |13: +Search 1/3 Del |14: Refs |15: lib.rs -|16: 2 pub fn add(a: i32, b: i32) -> i32 { +|16: lib.rs:2:8 pub fn add(a: i32, b: i32) -> i32 { |17: main.rs -|18: 4 let x = add(1, 2); +|18: main.rs:4:13 let x = add(1, 2); |19: /tmp/pardes-snap/lsp-client/cwd/+Preview Del |20: 1 == snap gr-opened grid=100x25 cursor=21,6 diff --git a/test/snapshots/lsprelpath.golden b/test/snapshots/lsprelpath.golden index dacb6b89..3af53a5c 100644 --- a/test/snapshots/lsprelpath.golden +++ b/test/snapshots/lsprelpath.golden @@ -17,10 +17,10 @@ | | +Search 2/2 Del | Refs -| /tmp/pardes-snap/lsprelpath/cwd/shade.zig -| 1 pub const Shade = enum { +| ../shade.zig +| ../shade.zig:1:11 pub const Shade = enum { | parent.zig -| 3 pub fn pick(s: shade.Shade) u8 { +| parent.zig:3:22 pub fn pick(s: shade.Shade) u8 { | | | @@ -56,15 +56,15 @@ |16: 0-1 d,#496656, 2-99 #b2c3b8,#1d2824, |17: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, |18: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, -|19: 0-0 d,#608269, 1-1 d,#0d1410, 2-7 d,#243a2d, 8-10 #59675c,#243a2d, 11-20 #e5eee5,#243a2d, 21-25 #f7e4a5,#5e4923, 26-26 #f7e4a5,#243a2d, 27-99 #e5eee5,#243a2d, +|19: 0-0 d,#608269, 1-1 d,#0d1410, 2-21 #59675c,#243a2d, 22-31 #e5eee5,#243a2d, 32-36 #f7e4a5,#5e4923, 37-37 #f7e4a5,#243a2d, 38-39 #e5eee5,#243a2d, 40-44 #c9a7ed,#243a2d, 45-99 #e5eee5,#243a2d, |20: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, -|21: 0-0 d,#608269, 1-7 d,#0d1410, 8-10 #59675c,#0d1410, 11-31 #e5eee5,#0d1410, 32-36 #f7e4a5,#5e4923, 37-99 #e5eee5,#0d1410, +|21: 0-0 d,#608269, 1-1 d,#0d1410, 2-19 #59675c,#0d1410, 20-23 #e5eee5,#0d1410, 24-26 #c9a7ed,#0d1410, 27-40 #e5eee5,#0d1410, 41-45 #f7e4a5,#5e4923, 46-99 #e5eee5,#0d1410, |22: 0-0 d,#608269, 1-99 d,#0d1410, |23: 0-0 d,#608269, 1-99 d,#0d1410, |24: 0-0 d,#608269, 1-99 d,#0d1410, |25: 0-0 d,#608269, 1-99 d,#0d1410, |26: 0-1 d,#add38a, 2-33 #becfc4,#314738, 34-43 #dfbce5,#314738, 44-99 #becfc4,#314738, -|27: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-16 #e5eee5,#0d1410, 17-21 #f5f7ee,#3c614a, 22-22 #f5f7ee,#0d1410, 23-24 #e5eee5,#0d1410, 25-29 #c9a7ed,#0d1410, 30-99 #e5eee5,#0d1410, +|27: 0-0 d,#e5eee5, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-16 #e5eee5,#0d1410, 17-21 #f5f7ee,#3c614a, 22-22 #f5f7ee,#0d1410, 23-24 #e5eee5,#0d1410, 25-29 #c9a7ed,#0d1410, 30-99 #e5eee5,#0d1410, |28: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-99 #e5eee5,#0d1410, |29: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-99 #e5eee5,#0d1410, |30: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-99 #e5eee5,#0d1410, @@ -92,9 +92,9 @@ | +Search 2/2 Del | Refs | inner/tint.zig -| 1 pub const Tint = enum { +| inner/tint.zig:1:11 pub const Tint = enum { | subdir.zig -| 3 pub fn hue(t: tint.Tint) u8 { +| subdir.zig:3:20 pub fn hue(t: tint.Tint) u8 { | | | @@ -130,15 +130,15 @@ |16: 0-1 d,#496656, 2-99 #b2c3b8,#1d2824, |17: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, |18: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, -|19: 0-0 d,#608269, 1-1 d,#0d1410, 2-7 d,#243a2d, 8-10 #59675c,#243a2d, 11-20 #e5eee5,#243a2d, 21-24 #f7e4a5,#5e4923, 25-25 #f7e4a5,#243a2d, 26-99 #e5eee5,#243a2d, +|19: 0-0 d,#608269, 1-1 d,#0d1410, 2-23 #59675c,#243a2d, 24-33 #e5eee5,#243a2d, 34-37 #f7e4a5,#5e4923, 38-38 #f7e4a5,#243a2d, 39-40 #e5eee5,#243a2d, 41-45 #c9a7ed,#243a2d, 46-99 #e5eee5,#243a2d, |20: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, -|21: 0-0 d,#608269, 1-7 d,#0d1410, 8-10 #59675c,#0d1410, 11-29 #e5eee5,#0d1410, 30-33 #f7e4a5,#5e4923, 34-99 #e5eee5,#0d1410, +|21: 0-0 d,#608269, 1-1 d,#0d1410, 2-19 #59675c,#0d1410, 20-23 #e5eee5,#0d1410, 24-26 #c9a7ed,#0d1410, 27-38 #e5eee5,#0d1410, 39-42 #f7e4a5,#5e4923, 43-99 #e5eee5,#0d1410, |22: 0-0 d,#608269, 1-99 d,#0d1410, |23: 0-0 d,#608269, 1-99 d,#0d1410, |24: 0-0 d,#608269, 1-99 d,#0d1410, |25: 0-0 d,#608269, 1-99 d,#0d1410, |26: 0-1 d,#add38a, 2-43 #becfc4,#314738, 44-52 #dfbce5,#314738, 53-99 #becfc4,#314738, -|27: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-16 #e5eee5,#0d1410, 17-20 #f5f7ee,#3c614a, 21-21 #f5f7ee,#0d1410, 22-23 #e5eee5,#0d1410, 24-28 #c9a7ed,#0d1410, 29-99 #e5eee5,#0d1410, +|27: 0-0 d,#e5eee5, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-16 #e5eee5,#0d1410, 17-20 #f5f7ee,#3c614a, 21-21 #f5f7ee,#0d1410, 22-23 #e5eee5,#0d1410, 24-28 #c9a7ed,#0d1410, 29-99 #e5eee5,#0d1410, |28: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-99 #e5eee5,#0d1410, |29: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-99 #e5eee5,#0d1410, |30: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-99 #e5eee5,#0d1410, diff --git a/test/snapshots/lsprelpath.snap b/test/snapshots/lsprelpath.snap index 70ca3fdc..152a13a3 100644 --- a/test/snapshots/lsprelpath.snap +++ b/test/snapshots/lsprelpath.snap @@ -1,19 +1,18 @@ # What a language row SPELLS its path as, and that both spellings still LOOK. # -# A row is written relative to the directory of the file the query was asked -# about (lsp.rel, fed from Req.root) when the answer lives UNDER that directory, -# and keeps its full absolute path when it does not — a `gr` list was otherwise +# A row spells its path the shortest way a Look from the query pane resolves +# (Query.lookPath): relative to the pane's directory, `../` included, when that +# is shorter than the absolute path, else absolute — a `gr` list was otherwise # the same forty-character prefix repeated down the pane with the part you came -# to read pushed off the right edge, and a path outside the tree has nothing -# short to be called. +# to read pushed off the right edge. # # A row in the SAME directory shortens to a bare basename; the two that a -# prefix strip can actually get wrong are here, one app each, as `gr` rows +# careless shortening can get wrong are here, one app each, as `gr` rows # (the file headers of the asking text's query pane, line 1 `Refs`): # -# PARENT the enum is one level UP from the asking file, so nothing is -# stripped and the row carries `/tmp/.../cwd/shade.zig`. This is -# the case that must NOT become `../shade.zig`. +# PARENT the enum is one level UP from the asking file, so the row +# climbs: `../shade.zig`, shorter than `/tmp/.../cwd/shade.zig`, +# and a Look from the pane still lands on it. # SUBDIRECTORY the enum is one level DOWN, so the strip leaves a path with a # separator still in it — `inner/tint.zig`, not `tint.zig`. A # strip that took the basename instead would produce a row that @@ -29,7 +28,7 @@ file shade.zig pub const Shade = enum {\n verdigris,\n cinnabar,\n};\n file sub/inner/tint.zig pub const Tint = enum {\n ochre,\n indigo,\n};\n file sub/parent.zig const shade = @import("../shade.zig");\n\npub fn pick(s: shade.Shade) u8 {\n return switch (s) {\n \n };\n}\n file sub/subdir.zig const tint = @import("inner/tint.zig");\n\npub fn hue(t: tint.Tint) u8 {\n return switch (t) {\n \n };\n}\n -# ---- PARENT: outside the asking file's tree, so the row stays absolute ---- +# ---- PARENT: outside the asking file's tree, so the row climbs ---- start 35 100 sub/parent.zig wait 8000 fn pick stable 700 20000 @@ -39,8 +38,8 @@ stable 400 5000 key g key r # the query pane under parent.zig, line 1 `Refs`, the rows under each file: -# shade.zig's spelled whole, its directory being above -wait 15000 cwd/shade.zig +# shade.zig's spelled from above, `../shade.zig` +wait 15000 ../shade.zig:1 stable 700 15000 snap absrow # the current row is parent.zig's own; the one before it is shade.zig's, diff --git a/test/snapshots/stepgrain.golden b/test/snapshots/stepgrain.golden index a406597c..33eea330 100644 --- a/test/snapshots/stepgrain.golden +++ b/test/snapshots/stepgrain.golden @@ -14,10 +14,10 @@ |^ +Search 1/3 Del | Grep ZQMARK | a.txt -| 1 hello ZQMARK one -| 2 see also sub/b.txt for ZQMARK two +| a.txt:1:7 hello ZQMARK one +| a.txt:2:24 see also sub/b.txt for ZQMARK two | sub/b.txt -| 1 ZQMARK inside sub +| sub/b.txt:1:1 ZQMARK inside sub | | | @@ -41,10 +41,10 @@ |12: 0-1 #000000,#add38a, 2-149 #becfc4,#314738, |13: 0-0 d,#608269, 1-1 d,#0d1410, 2-149 #e5eee5,#0d1410, |14: 0-0 d,#608269, 1-1 d,#0d1410, 2-149 #e5eee5,#0d1410, -|15: 0-0 d,#608269, 1-7 d,#0d1410, 8-10 #59675c,#0d1410, 11-16 #e5eee5,#0d1410, 17-22 #f7e4a5,#5e4923, 23-23 #f7e4a5,#0d1410, 24-149 #e5eee5,#0d1410, -|16: 0-0 d,#608269, 1-1 d,#0d1410, 2-7 d,#243a2d, 8-10 #59675c,#243a2d, 11-33 #e5eee5,#243a2d, 34-39 #f7e4a5,#5e4923, 40-40 #f7e4a5,#243a2d, 41-149 #e5eee5,#243a2d, +|15: 0-0 d,#608269, 1-1 d,#0d1410, 2-14 #59675c,#0d1410, 15-20 #e5eee5,#0d1410, 21-26 #f7e4a5,#5e4923, 27-27 #f7e4a5,#0d1410, 28-149 #e5eee5,#0d1410, +|16: 0-0 d,#608269, 1-1 d,#0d1410, 2-14 #59675c,#243a2d, 15-37 #e5eee5,#243a2d, 38-43 #f7e4a5,#5e4923, 44-44 #f7e4a5,#243a2d, 45-149 #e5eee5,#243a2d, |17: 0-0 d,#608269, 1-1 d,#0d1410, 2-149 #e5eee5,#0d1410, -|18: 0-0 d,#608269, 1-7 d,#0d1410, 8-10 #59675c,#0d1410, 11-16 #f7e4a5,#5e4923, 17-17 #f7e4a5,#0d1410, 18-149 #e5eee5,#0d1410, +|18: 0-0 d,#608269, 1-1 d,#0d1410, 2-18 #59675c,#0d1410, 19-24 #f7e4a5,#5e4923, 25-25 #f7e4a5,#0d1410, 26-149 #e5eee5,#0d1410, |19: 0-0 d,#608269, 1-149 d,#0d1410, |20: 0-0 d,#608269, 1-149 d,#0d1410, |21: 0-0 d,#608269, 1-149 d,#0d1410, diff --git a/test/snapshots/tagbottom.golden b/test/snapshots/tagbottom.golden index cf690a40..06798df3 100644 --- a/test/snapshots/tagbottom.golden +++ b/test/snapshots/tagbottom.golden @@ -153,8 +153,8 @@ == snap search-prompt grid=100x31 cursor=5,21 |20: /tmp/pardes-snap/tagbottom/cwd/bottom.txt Save Tty Collapse Del |21: /ZZ -|22: 1 ZZONE -|23: 2 ZZTWO +|22: bottom.txt:1:1 ZZONE +|23: bottom.txt:2:1 ZZTWO |30: ^ +Search 1/2 Del == snap leader grid=100x31 cursor=9,13 |12: 1 ZZONE SPC -- cgit v1.3