From df964ae2f14d21a4799d52a07abfe3b2bef3c65e Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 01:40:25 -0300 Subject: ansi, Term, term/terminal, abi/term: a terminal's colours from the chrome (the themes programme's L2d; DESIGN.md R1, R14, R15, B6): the paint and the filter take the page, its text, its dim ink and the sixteen the theme resolved once a theme change (`Chrome.page`, `Chrome.ansi`), never the theme's own fields: a theme with no sixteen of its own draws a program's in the ones worked out for it (R14: its own hues within 30 degrees, else canonical ones, held 4.5:1 on its page), where the cells named an index and each frontend drew its own palette (the tty the host's, the window ghostty's, the Mac Tango: three for one index); a theme that leaves its page to the host (`dark`) leaves page, text and sixteen to a tty as before (`Ink.host`), and in a window draws the null page, its text and its sixteen (R1, R14: "the window uses its ansi"); the filter's base is that sixteen and its 256 targets ghostty's generator over it, made once a theme (FilterPalette, keyed by the theme's values: no reimplemented generator, no per-frame make), where the base for a theme without a palette was made of its roles (ANSI 1 the keyword, 5 the selection, 13 its ink: C1's surfaces.md §3.10) and the page of `dark` was its tag (`ink.bg orelse ink.tag_bg`, #2c2a3e under a #121212 window: §3.1); SGR faint on the page's text is the page's dim ink (R15: the text toward the page to 3.5:1, so as faint on a light page as on a dark one), where a tty halved its brightness toward black and a window took 60 % of it (faint on a coloured ink stays the frontend's, L2e's); Ink is {fg, bg, dim, ansi, host} (abi/term.zig: `tag_fg`, `tag_bg`, `palette` and `base` deleted), ansi.inkOf takes the core (its chrome and its view's frontend); RUN (TEST FIRST): test/terminal.zig "a theme that leaves its page to the host (`dark`) draws a terminal's page, text, faint and sixteen as the null page and its own in a window, and leaves them to a tty; its filter keys to that page, never its tag": in a window a plain cell on #121212 in dark's text, SGR 31 in `ansi[1]`, SGR 2 in `page.dim` and not faint; in a tty `.default`, index 1, faint; the filter's page the null page and its ink the text: on the base the window's cells are `.default`, index 1 and faint and the filter's page dark's tag (the old Ink had no page to give: `ink.bg orelse ink.tag_bg`); the Filter tests re-pinned to the chrome: helix's SGR 31 raw is its resolved `ansi[1]` (was index 1), the `F` cell's faint on the page's text its dim ink (was the text, faint), a reversed explicit cell's ink the chrome's page, the in-place custom theme now a ThemeFile's way (its sixteen changed and its chrome worked out: finishThemeInitialization) where it poked the keyword the old base mapped to ANSI 1, the theme loops by setThemeIndex (they set `settings.theme` under a chrome worked out for another) and with `dark` among them; test/panes.zig's TerminalTests that assert a program's raw indices (an edit buffer sliding rows and their colours, a combining mark, an emoji prompt, a swallowed row, an emptied buffer, the overlay in tty mode, colours never taken from rows below the viewport: seven failed on helix's indices now its resolved sixteen, and the last would have kept passing while proving nothing) take `dark` in a tty, which leaves the sixteen to the host as helix's missing palette did; the wide glyph's last column keeps helix (a page of its own, so the body draws every cell) and asks its resolved red; goldens re-recorded: load.golden row 7 and headersweep-restored.golden rows 6, 14, 15 and 21: the `── restored history ──` banner (SGR 2, terminal.zig's restored_banner) in orchard's page dim ink #666f68 where the tty drew #e5eee5 faint, and the blank cells after it on its row the same fg (vaxis erases the rest of a row in its last SGR; nothing drawn there); pagercolor.golden, theme.golden and themesel.golden unchanged (every native and ported theme in them has its sixteen); GATES: core-test 1123/1296 (173 skipped), term-test 17/17, pane-test 184/185 (1 skipped: base 183/184, +1 the dark test), process-test 145 of 147 and the two re-recorded (3 skipped); load 3.4 to 7.8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/File.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/File.zig') diff --git a/core/File.zig b/core/File.zig index 0f9178ac..332499b4 100644 --- a/core/File.zig +++ b/core/File.zig @@ -2942,7 +2942,7 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes. // A row whose first byte names a hue (syntax.ground_add, _del): its // grounds, the theme's, worked out once a frame and only for one. var grounds: ?Colors.Grounds = null; - const ink = ansi.inkOf(p.theme()); + const ink = ansi.inkOf(p); var filtered_storage: pardes.Term.Filter = undefined; const filtered: ?*pardes.Term.Filter = if (pane.tty_filter and spans.len > 0) blk: { filtered_storage = pardes.Term.filter(&ink, &p.tty_filter_palette); -- cgit v1.3 From 148e48dd9b8cd7e66aa1521daa49a64852b1650e Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 02:28:09 -0300 Subject: syntax, Query, Pick, Names, Band, Stream, File, colors: the Symbols picker grouped by kind, a kind mark on each row (UX DESIGN N, binding; the user: "The lsp symbols should be more organized: types first then functions then fields and the rest (and some indicator to tell the kind)", "For the symbols picker"): the rows are the file's own parse's, as before, now from a symbol walk of their own (syntax.zig `SymbolWalk`, in the same walk of the tree as the sticky headers' declarations, which keep theirs: contextFromTree), by one kind table a grammar (`symbol_rules`: Zig, C, C++, Rust, Go, Python, JavaScript, Java, C#, Kotlin, Scala, Ruby, PHP, bash, Haskell, OCaml, Erlang, Elixir, Clojure, Fortran, Ada, Pascal, PowerShell; JSON, CSS, HTML, Markdown and Typst have no declarations to list), each node's kind as given or found where its grammar cannot say it (Zig's `const S = struct`, `error{...}`, `@This()`, `@Type(...)` a type and `@import(...)` a module, JavaScript's `const f = () => ...` a function, C's declaration a function where a declarator is one's and a const where `const` says so, a Python class's or Kotlin's binding a field in a type); fields and consts are listed now (the sticky headers' declarations had neither), a function's consts and vars never (its locals), each named in the types, functions and modules it is in (`Counts.lines`, `torque.Parser.Parse`; an anonymous struct's members in its owner's, a Rust `impl S`'s in `S`, no row of its own); a row is `t Counts = struct`: its kind's mark (t type, f function, m field, c const, v var, n module, · other), its qualified name, two blanks and what its name's line says after the name (its body's `{`, a trailing `,` or `;` dropped), its line the dim meta at the right end (Band's); the mark in the keyword's ink (colors.Roles.kind, the theme's keyword pushed to 4.5:1 on every tag ground and the selection, as the key ink is), the qualifier and the words after the name dim; with the field empty the rows are types, functions, fields, then the rest (consts, vars, modules, other as one group), each in the text's order; typed, they stay grouped and are scored within each group (Names: `Cand.group`, `before` orders by it, then by `better`), the cursor starts on the best match wherever its group puts it (Names.bestRow, Pick.toBest: after a key, when the parse lands, and following the best while the rest are scored), and the count says where it is; the name alone is matched (`u8` in a signature matches nothing); no header rows: every row is a symbol, ordinary text, and C-q keeps them in a +Search with the mark a word; the query pane's `Symbols` rows the same (Query.gather), its current the best; the parse's answer carries the symbols beside the declarations (Stream.Batch.symbols, an input every replica takes), ContextCache keeps both for the revision (derived, made again at a load), and every producer makes both (the worker, a sticky header's refresh, a load), so a text at a revision has the same symbols everywhere; syntax.zig's tests ran in no test program (core-test's filter `syntax context nested` matched nothing on the base): core/root.zig imports it now, and its 34 pass; RUN (TEST FIRST): syntax.zig "syntax symbols: a Zig file's types, functions, fields and the rest ...", "... C, C++, Rust, Go, Python and JavaScript by their kind tables ...", "... every kind table names nodes of its grammar ..." (23 tables), Pick.zig "Symbols (UX DESIGN N): a Zig file's rows types, functions, fields, then the rest ... the mark in the keyword's ink, the qualifier and the rest dim", "Symbols (UX DESIGN N3): typed, the rows stay grouped ... the cursor starts on the best match ...; the name alone is matched, never the signature", "Symbols (UX DESIGN N): a C++ file's rows ...", "Symbols: every row is ordinary text ..."; on the base the rows were ` 2 pub const Counts = struct {` in the text's order, no mark, no field, the cursor on the first row; core-test -Dtest-filter=ymbols 18/18, core-test 1135/1308 (173 skipped); the stack's suites, the dump fuzz, the soak and the pictures are on the change after this one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/Band.zig | 9 +- core/File.zig | 36 +-- core/Names.zig | 31 ++- core/Pick.zig | 255 +++++++++++++++++++- core/Query.zig | 49 +++- core/Stream.zig | 25 +- core/colors.zig | 6 + core/draw.zig | 1 + core/dump.zig | 13 +- core/root.zig | 1 + core/syntax.zig | 707 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 11 files changed, 1066 insertions(+), 67 deletions(-) (limited to 'core/File.zig') diff --git a/core/Band.zig b/core/Band.zig index 8ee5c9f0..0424315a 100644 --- a/core/Band.zig +++ b/core/Band.zig @@ -40,6 +40,9 @@ pub const Row = struct { on: bool = false, /// Its first `key` bytes are a key: the key ink, bold. key: u8 = 0, + /// Its first `kind` bytes are a symbol's kind mark (`t`, `f`, `m`): + /// the keyword's ink (UX DESIGN N4). + kind: u8 = 0, /// Its first `chord` bytes are a chord (Help's `SPC h t`): the key ink /// at the text's weight. chord: u8 = 0, @@ -53,8 +56,9 @@ pub const Row = struct { index: u16 = 0, /// Marked in a picker's list: `•` before it. mark: bool = false, - /// Its first `pre` bytes are a place (`file:line`, `@p3`): the name's - /// tint; the `faint` bytes after them dimmed (a path's directory). + /// Its first `pre` bytes are a place (`file:line`, `@p3`) or a kind + /// mark: the name's tint; the `faint` bytes after them dimmed (a path's + /// directory, a symbol's qualifier). pre: u16 = 0, faint: u16 = 0, /// Said at the row's right end in the dim ink, two cells off its text @@ -644,6 +648,7 @@ fn cutRow(arena: std.mem.Allocator, tab: u16, row: Row, room: u16) !Row { fit.text = try std.mem.concat(arena, u8, &.{ row.text[0..cut], if (room > 0) "…" else "" }); for (row.marks) |m| if (m < cut) try marks.append(arena, m); fit.key = @intCast(@min(row.key, cut)); + fit.kind = @intCast(@min(row.kind, cut)); fit.pre = @intCast(@min(row.pre, cut)); fit.faint = @intCast(@min(row.faint, cut -| fit.pre)); } diff --git a/core/File.zig b/core/File.zig index 0f9178ac..49d22fdc 100644 --- a/core/File.zig +++ b/core/File.zig @@ -60,35 +60,39 @@ pub const History = struct { } }; -/// Owned syntax results: a text's declarations at a revision. +/// Owned syntax results: a text's declarations and symbols at a revision. pub const ContextCache = struct { /// Its revision is dumped and digested: a worker's parse is an input, /// which a client joined since never saw, and a step reads what it - /// left (Query.ownerDecls). The declarations are made again from the - /// text at a load (`reload`), with the allocator that made them. - pub const replica = .{ .local = .{"allocator"}, .derived = .{"declarations"} }; + /// left (Query.ownerDecls, the Symbols source). The declarations and + /// symbols are made again from the text at a load (`reload`), with the + /// allocator that made them. + pub const replica = .{ .local = .{"allocator"}, .derived = .{ "declarations", "symbols" } }; allocator: ?std.mem.Allocator = null, declarations: []syntax.ContextDeclaration = &.{}, + symbols: []syntax.Symbol = &.{}, revision: ?u32 = null, pub fn deinit(self: *ContextCache) void { - if (self.allocator) |gpa| gpa.free(self.declarations); + if (self.allocator) |gpa| { + gpa.free(self.declarations); + gpa.free(self.symbols); + } self.* = .{}; } - /// A loaded text's (its revision the dump's): its declarations parsed - /// again where they are of the text it has. + /// A loaded text's (its revision the dump's): its context parsed + /// again where it is of the text it has. pub fn reload(self: *ContextCache, gpa: std.mem.Allocator, path: []const u8, content: []const u8, revision: u32) void { const at = self.revision orelse return; if (at != revision) return; - const declarations = syntax.contextDeclarations(gpa, path, content) catch return; - self.replace(gpa, declarations, at); + self.replace(gpa, syntax.context(gpa, path, content) catch return, at); } - /// Takes ownership of declarations allocated by gpa. - pub fn replace(self: *ContextCache, gpa: std.mem.Allocator, declarations: []syntax.ContextDeclaration, revision: u32) void { + /// Takes ownership of a context allocated by gpa. + pub fn replace(self: *ContextCache, gpa: std.mem.Allocator, made: syntax.Context, revision: u32) void { self.deinit(); - self.* = .{ .allocator = gpa, .declarations = declarations, .revision = revision }; + self.* = .{ .allocator = gpa, .declarations = made.declarations, .symbols = made.symbols, .revision = revision }; } }; @@ -2490,8 +2494,7 @@ pub fn changed(p: *Pardes, id: u8, bytes: []const u8) void { pub fn refreshContext(p: *Pardes, pane: *Pane, f: *State) void { if (!f.tree_context or !supportsContext(pane) or f.context.revision == f.revision) return; // The file's declarations, in its lines (the layer's are none of it). - const declarations = syntax.contextDeclarations(p.tree_sitter_gpa, f.path, fileText(f, p.scratch.allocator()) catch return) catch return; - f.context.replace(p.tree_sitter_gpa, declarations, f.revision); + f.context.replace(p.tree_sitter_gpa, syntax.context(p.tree_sitter_gpa, f.path, fileText(f, p.scratch.allocator()) catch return) catch return, f.revision); } pub fn refreshHighlights(p: *Pardes) void { @@ -3615,12 +3618,13 @@ test "context cache frees each allocation with its original allocator" { defer std.testing.expect(second.deinit() == .ok) catch @panic("second allocator leaked"); var cache: ContextCache = .{}; defer cache.deinit(); - cache.replace(first.allocator(), try first.allocator().alloc(syntax.ContextDeclaration, 1), 1); - cache.replace(second.allocator(), try second.allocator().alloc(syntax.ContextDeclaration, 2), 2); + cache.replace(first.allocator(), .{ .declarations = try first.allocator().alloc(syntax.ContextDeclaration, 1), .symbols = try first.allocator().alloc(syntax.Symbol, 1) }, 1); + cache.replace(second.allocator(), .{ .declarations = try second.allocator().alloc(syntax.ContextDeclaration, 2), .symbols = try second.allocator().alloc(syntax.Symbol, 2) }, 2); try std.testing.expectEqual(@as(?u32, 2), cache.revision); cache.deinit(); try std.testing.expect(cache.allocator == null); try std.testing.expectEqual(@as(usize, 0), cache.declarations.len); + try std.testing.expectEqual(@as(usize, 0), cache.symbols.len); } /// The inks of row `row`'s first `n` text cells of pane `id` as `s` draws them. diff --git a/core/Names.zig b/core/Names.zig index d063bd17..415064ad 100644 --- a/core/Names.zig +++ b/core/Names.zig @@ -50,6 +50,9 @@ pub const Cand = struct { /// What the row is of: a line of the owner (Symbols, 1-based), a /// pane's serial (Panes); 0 for a path. ref: u32 = 0, + /// Its group: the hits stay in their groups' order, scored within + /// each (a Symbols row's kind, UX DESIGN N3); 0 for every other source. + group: u8 = 0, }; pub const Hit = struct { cand: u32, score: i32 }; @@ -187,9 +190,17 @@ pub fn reachTo(n: *Names, rows: usize) void { n.gen +%= 1; } -/// Hit `a` goes before `b`: the higher score, then the shorter key, then -/// the candidate added first. +/// Hit `a` goes before `b`: the lower group, then `better`. fn before(cands: []const Cand, a: Hit, b: Hit) bool { + const ga = cands[a.cand].group; + const gb = cands[b.cand].group; + if (ga != gb) return ga < gb; + return better(cands, a, b); +} + +/// Hit `a` matched better than `b`: the higher score, then the shorter +/// key, then the candidate added first. +fn better(cands: []const Cand, a: Hit, b: Hit) bool { if (a.score != b.score) return a.score > b.score; const la = cands[a.cand].key_len; const lb = cands[b.cand].key_len; @@ -230,6 +241,22 @@ fn sink(heap: []Hit, cands: []const Cand, from: usize) void { } } +/// The row of the hit the query matched best, wherever its group puts it: +/// where a list's cursor starts (UX DESIGN N3); 0 for an empty query, +/// whose rows are the source's order. Its rows up to it are sorted once +/// `reachTo` has gone past it. +pub fn bestRow(n: *const Names) usize { + const hits = n.hits.items; + if (hits.len == 0 or std.mem.trim(u8, n.queryText(), " ").len == 0) return 0; + var top = hits[0]; + for (hits[1..]) |h| if (better(n.cands.items, h, top)) { + top = h; + }; + var at: usize = 0; + for (hits) |h| at += @intFromBool(before(n.cands.items, h, top)); + return at; +} + /// The row of hit `i` and, in `marks`, the bytes of it the query matched. pub fn row(n: *const Names, i: usize, marks: []u16, nmarks: *usize) []const u8 { const c = n.cands.items[n.hits.items[i].cand]; diff --git a/core/Pick.zig b/core/Pick.zig index 1d332f25..2b5714cb 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -452,7 +452,10 @@ pub fn filter(p: *Pardes, pk: *Pick) void { const q = std.mem.trim(u8, p.view().tag_state.field.text(), " "); p.view().tag_state.rows.at = 0; pk.shown = no_row; - if (fuzzy(pk)) return pk.names.typed(p.gpa, q); + if (fuzzy(pk)) { + pk.names.typed(p.gpa, q); + return toBest(p, pk); + } if (pk.source == .grep) { pk.found.clearRetainingCapacity(); pk.found_bytes.clearRetainingCapacity(); @@ -514,15 +517,31 @@ pub fn declsArrived(p: *Pardes, serial: u32) void { Query.gather(p, &pk.names, .symbols, pk.dir.slice(), null, p.paneBySerial(serial)); pk.names.typed(p.gpa, pk.names.queryText()); pk.names.rescore(p.gpa); + if (live(p) == pk) toBest(p, pk); }; } +/// The live picker's cursor on its best match, wherever its group puts it +/// (UX DESIGN N3: a Symbols list stays grouped while typed), its rows +/// sorted as far as the band shows past it. +fn toBest(p: *Pardes, pk: *Pick) void { + const at = pk.names.bestRow(); + pk.names.reachTo(at + Band.Cursor.shown); + p.view().tag_state.rows.at = @intCast(@min(at, std.math.maxInt(u16))); +} + /// After every step: each live picker's names scored on (a frame's count), /// and on a frame of its own after the cursor stood, the preview of the /// current row. pub fn produceAll(p: *Pardes, tick: bool) void { for (p.picks) |slot| if (slot) |pk| if (pk.unrolled) { - if (pk.names.busy()) pk.names.rescore(p.gpa); + if (pk.names.busy()) { + // A cursor on the best match follows it while the rest are + // scored. + const on_best = live(p) == pk and p.view().tag_state.rows.at == pk.names.bestRow(); + pk.names.rescore(p.gpa); + if (on_best) toBest(p, pk); + } // A theme's preview in the step of the key that moved to it. if (pk.source == .themes) pardes.colors.previewTheme(p, refAt(p, pk)); if (tick) preview(p, pk); @@ -584,7 +603,7 @@ const Target = union(enum) { none, place: struct { path: []const u8, at: look.Sp /// Row `i` as the band shows it and what it points at, its text in /// `arena`. -const Row = struct { text: []const u8, key: u8 = 0, pre: u16 = 0, faint: u16 = 0, dim: bool = false, marks: []const u16 = &.{}, target: Target = .none, meta: []const u8 = "" }; +const Row = struct { text: []const u8, key: u8 = 0, kind: u8 = 0, pre: u16 = 0, faint: u16 = 0, quiet: [2]u16 = .{ 0, 0 }, dim: bool = false, marks: []const u16 = &.{}, target: Target = .none, meta: []const u8 = "" }; fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) std.mem.Allocator.Error!Row { const dir = pk.dir.slice(); @@ -646,8 +665,23 @@ fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) std.me row.dim = p.paneBySerial(cand.ref) == null; row.target = .{ .pane = cand.ref }; }, + // ` 12 m Counts.lines : usize = 0` (Query.gather): the line its + // meta, the mark in the keyword's ink, the qualifier and what + // follows the name dim (UX DESIGN N4). .symbols => { - row.pre = 6; + const line = 8; + if (text.len <= line or cand.key < line) return row; + row.text = text[line..]; + row.meta = std.mem.trimStart(u8, text[0..6], " "); + const marks_in = try arena.alloc(u16, row.marks.len); + for (marks_in, row.marks) |*m, at| m.* = at -| line; + row.marks = marks_in; + const name_at = cand.key - line; + const dot = std.mem.lastIndexOfScalar(u8, row.text[name_at .. name_at + cand.key_len], '.'); + row.kind = @intCast(name_at - 1); + row.pre = @intCast(name_at); + row.faint = @intCast(if (dot) |at| at + 1 else 0); + if (name_at + cand.key_len < row.text.len) row.quiet = .{ @intCast(name_at + cand.key_len), @intCast(row.text.len) }; const owner = p.panes[p.paneBySerial(pk.owner) orelse return row] orelse return row; const f = owner.file orelse return row; row.target = .{ .place = .{ .path = f.path, .at = .{ .line = cand.ref } } }; @@ -837,7 +871,7 @@ pub fn steps(p: *Pardes, arena: std.mem.Allocator) ![]Band.Step { const rows = try arena.alloc(Band.Row, w.hi - w.lo); for (rows, w.lo..) |*row, i| { const r = try rowAt(p, pk, arena, i); - row.* = .{ .text = r.text, .key = r.key, .on = i == s.rows.at, .mark = marked(pk, idOf(pk, i)) != null, .dim = r.dim, .pre = r.pre, .faint = r.faint, .marks = r.marks, .index = @intCast(i), .meta = r.meta }; + row.* = .{ .text = r.text, .key = r.key, .kind = r.kind, .on = i == s.rows.at, .mark = marked(pk, idOf(pk, i)) != null, .dim = r.dim, .pre = r.pre, .faint = r.faint, .quiet = r.quiet, .marks = r.marks, .index = @intCast(i), .meta = r.meta }; } // A place's text (a Grep's line, a list's): its `path:line` in the dim // ink and the text after it in one column, the widest place shown @@ -1415,6 +1449,7 @@ fn refine(p: *Pardes, pk: *Pick, drop: bool) void { if (drop and (if (pk.marks.items.len > 0) marked(pk, h.cand) != null else h.cand == current)) continue; const c = pk.names.cands.items[h.cand]; next.add(p.gpa, pk.names.bytes.items[c.start..][0..c.len], c.key, c.key_len, c.base, c.ref) catch break; + next.cands.items[next.cands.items.len - 1].group = c.group; } } else { var arena = std.heap.ArenaAllocator.init(p.gpa); @@ -1514,7 +1549,7 @@ fn keep(p: *Pardes, pk: *Pick) void { const row = rowAt(p, pk, arena.allocator(), i) catch break; switch (row.target) { .place => |t| if (pk.source == .symbols) - out.writer.print("{s}:{d} {s}\n", .{ std.Io.Dir.path.basename(t.path), t.at.line, std.mem.trimStart(u8, row.text, " 0123456789") }) catch break + out.writer.print("{s}:{d} {s}\n", .{ std.Io.Dir.path.basename(t.path), t.at.line, row.text }) catch break else out.writer.print("{s}\n", .{row.text}) catch break, else => out.writer.print("{s}\n", .{row.text}) catch break, @@ -3283,3 +3318,211 @@ test "Ctrl-r in a picker unrolls its source's earlier queries (UX L2's last line p.update(.{ .key = .{ .cp = Key.escape } }); p.update(.{ .key = .{ .cp = Key.escape } }); } + +/// A Symbols picker opened from a file pane whose path is `name` and text +/// `text`, its symbols parsed (small: here and now), and the pane. +fn openSymbols(p: *Pardes, name: []const u8, text: []const u8) !*Pane { + const pane = try p.setTestFile(text); + p.gpa.free(pane.file.?.path); + pane.file.?.path = try p.gpa.dupe(u8, name); + open(p, p.view().active, .symbols, "", "", ""); + settle(p); + return pane; +} + +/// The live picker's rows, `meta text` a line each. +fn rowLines(p: *Pardes, a: std.mem.Allocator) ![]const u8 { + const pk = live(p).?; + var out: std.ArrayList(u8) = .empty; + for (0..count(p, pk)) |i| { + const r = try rowAt(p, pk, a, i); + try out.print(a, "{s: >2} {s}\n", .{ r.meta, r.text }); + } + return out.items; +} + +const counts_zig = + \\const std = @import("std"); + \\pub const Counts = struct { + \\ lines: usize = 0, + \\ words: usize = 0, + \\ pub const zero: Counts = .{}; + \\ pub fn add(c: *Counts, text: []const u8) void { + \\ const local = text.len; + \\ c.lines += local; + \\ } + \\}; + \\const Mode = enum { fast, slow }; + \\var hits: u32 = 0; + \\pub fn count(text: []const u8) Counts { + \\ return .{ .lines = text.len }; + \\} + \\test "count" {} + \\ +; + +test "Symbols (UX DESIGN N): a Zig file's rows types, functions, fields, then the rest, each in the text's order with the field empty; a row its kind's mark, its name qualified, what its first line says after it, its line the meta; the mark in the keyword's ink, the qualifier and the rest dim" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 }); + defer p.deinit(); + p.settings.jumps = .walk; + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const a = frame.allocator(); + _ = try openSymbols(p, "/w6/counts.zig", counts_zig); + try std.testing.expectEqualStrings( + \\ 2 t Counts = struct + \\11 t Mode = enum { fast, slow } + \\ 6 f Counts.add (c: *Counts, text: []const u8) void + \\13 f count (text: []const u8) Counts + \\ 3 m Counts.lines : usize = 0 + \\ 4 m Counts.words : usize = 0 + \\11 m Mode.fast + \\11 m Mode.slow + \\ 1 n std = @import("std") + \\ 5 c Counts.zero : Counts = .{} + \\12 v hits : u32 = 0 + \\16 · "count" + \\ + , try rowLines(p, a)); + // Drawn: `m Counts.lines : usize = 0` (not the cursor's row). + const pane = p.panes[p.paneBySerial(live(p).?.landing).?].?; + _ = try p.render(a); + const layer = &p.surface.tag_layers[pardes.BAND_LAYER]; + const roles = &p.chromeTheme().roles; + const inks = roles.on(if (Trail.reading(p, pane)) .reading_focused else .focused); + var found = false; + for (0..layer.rows) |y| { + const cells = layer.cells[y * layer.cols ..][0..layer.cols]; + var text: std.ArrayList(u8) = .empty; + var at: std.ArrayList(usize) = .empty; + for (cells, 0..) |c, x| { + try at.append(a, text.items.len); + try text.appendSlice(a, c.grapheme()); + _ = x; + } + const from = std.mem.indexOf(u8, text.items, "m Counts.lines") orelse continue; + var x: usize = 0; + while (at.items[x] < from) x += 1; + try std.testing.expectEqual(pardes.Color{ .rgb = roles.kind }, cells[x].style.fg); + try std.testing.expectEqual(pardes.Color{ .rgb = inks.dim }, cells[x + 2].style.fg); + try std.testing.expectEqual(pardes.Color{ .rgb = inks.text }, cells[x + 9].style.fg); + try std.testing.expectEqual(pardes.Color{ .rgb = inks.dim }, cells[x + 16].style.fg); + // Its line at the row's right end, dim. + const three = std.mem.lastIndexOfScalar(u8, text.items, '3').?; + var m: usize = 0; + while (at.items[m] < three) m += 1; + try std.testing.expect(m > x + 30); + try std.testing.expectEqual(pardes.Color{ .rgb = inks.dim }, cells[m].style.fg); + found = true; + } + try std.testing.expect(found); +} + +test "Symbols (UX DESIGN N3): typed, the rows stay grouped, scored within each group, and the cursor starts on the best match wherever its group puts it; the name alone is matched, never the signature" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 }); + defer p.deinit(); + p.settings.jumps = .walk; + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const a = frame.allocator(); + const pane = try openSymbols(p, "/w6/counts.zig", counts_zig); + for ("count") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + settle(p); + const rows = try rowLines(p, a); + try std.testing.expect(std.mem.startsWith(u8, rows, + \\ 2 t Counts = struct + \\13 f count (text: []const u8) Counts + \\ 6 f Counts.add (c: *Counts, text: []const u8) void + \\ 3 m Counts.lines : usize = 0 + \\ 4 m Counts.words : usize = 0 + \\ + )); + // `count` matched best: the cursor on it, not on the first row, and + // the count says where it is. + const s = &p.view().tag_state; + try std.testing.expectEqual(@as(u16, 1), s.rows.at); + const h = (try head(p, a, p.panes[p.paneBySerial(live(p).?.landing).?].?)).?; + try std.testing.expect(std.mem.indexOf(u8, h.text, "2/7") != null); + // Enter lands on its line. + _ = pane; + // `u8` is in signatures only: nothing matches. + for (0..5) |_| p.update(.{ .key = .{ .cp = pardes.Key.backspace } }); + for ("u8") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + settle(p); + try std.testing.expectEqual(@as(usize, 0), count(p, live(p).?)); +} + +test "Symbols (UX DESIGN N): a C++ file's rows by its kind table, members named in their class and namespace, a function's locals none" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 }); + defer p.deinit(); + p.settings.jumps = .walk; + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + _ = try openSymbols(p, "/w6/parser.cc", + \\#define LIMIT 4 + \\namespace torque { + \\class Parser : public Base { + \\ public: + \\ Parser(); + \\ int Parse(int depth) const { return depth; } + \\ int depth_; + \\}; + \\enum class Kind { kA, kB }; + \\int Parser::Run(int n) { int local = n; return local; } + \\static int counter = 0; + \\const int limit = 4; + \\using Alias = int; + \\} + \\ + ); + try std.testing.expectEqualStrings( + \\ 3 t torque.Parser : public Base + \\ 9 t torque.Kind + \\13 t torque.Alias = int + \\ 5 f torque.Parser.Parser () + \\ 6 f torque.Parser.Parse (int depth) const + \\10 f torque.Parser::Run (int n) + \\ 7 m torque.Parser.depth_ + \\ 9 m torque.Kind.kA + \\ 9 m torque.Kind.kB + \\ 1 · LIMIT 4 + \\ 2 n torque + \\11 v torque.counter = 0 + \\12 c torque.limit = 4 + \\ + , try rowLines(p, frame.allocator())); +} + +test "Symbols: every row is ordinary text: no header rows, the cursor steps onto each in turn, the band shows each row's text, and C-q keeps them in a +Search with the mark a word" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 }); + defer p.deinit(); + p.settings.jumps = .walk; + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const a = frame.allocator(); + _ = try openSymbols(p, "/w6/counts.zig", counts_zig); + const pk = live(p).?; + const n = count(p, pk); + try std.testing.expectEqual(@as(usize, 12), n); + const s = &p.view().tag_state; + for (0..n) |i| { + try std.testing.expectEqual(@as(u16, @intCast(i)), s.rows.at); + const r = try rowAt(p, pk, a, i); + const host = p.paneBySerial(pk.landing).?; + const band = (try Band.of(p, a, p.panes[host].?, host)).?; + var shown = false; + for (0..band.height) |y| { + const ln = try band.line(a, p.settings.tab, @intCast(y)); + shown = shown or std.mem.indexOf(u8, ln.text, r.text) != null; + } + try std.testing.expect(shown); + p.update(.{ .key = .{ .cp = pardes.Key.down } }); + } + p.update(.{ .key = .{ .cp = 'q', .ctrl = true } }); + var kept: ?[]const u8 = null; + for (p.panes) |slot| if (slot) |tp| if (tp.file) |f| if (std.mem.startsWith(u8, f.content, "Symbols ")) { + kept = f.content; + }; + try std.testing.expect(std.mem.indexOf(u8, kept.?, "\ncounts.zig:3 m Counts.lines : usize = 0\n") != null); + try std.testing.expect(std.mem.indexOf(u8, kept.?, "\ncounts.zig:2 t Counts = struct\n") != null); +} diff --git a/core/Query.zig b/core/Query.zig index 2b2abebb..743e9540 100644 --- a/core/Query.zig +++ b/core/Query.zig @@ -530,8 +530,9 @@ fn makeNameRows(p: *Pardes, id: usize) !void { f.pager_spans = spans.toOwnedSlice(p.gpa) catch &.{}; q.total = q.names.hits.items.len; q.more = q.names.busy() or p.stream.busyFor(rp.serial); - // The best is current until a step or a click moves it. - q.current = if (shown > 0) 0 else null; + // The best is current until a step or a click moves it: in a grouped + // list (Symbols) wherever its group puts it. + q.current = if (shown > 0) @min(q.names.bestRow(), shown - 1) else null; countCurrent(q); showCurrent(p.settings.tab, rp); if (q.current == null) blankPreview(p, id) else showTarget(p, id); @@ -771,23 +772,51 @@ pub fn gather(p: *Pardes, names: *Names, source: Source, dir: []const u8, self: const oid = owner_id orelse return; const owner = p.panes[oid].?; const f = if (owner.file) |*file| file else return; - const decls = ownerDecls(f) orelse { + if (f.context.revision != f.revision) { // Parsed on the worker; listed when it is done (declsArrived). Stream.parseFor(p, oid); return; - }; - for (decls) |d| { - const header = f.content[d.start_byte..@min(d.header_end_byte, f.content.len)]; - const first = std.mem.trim(u8, header[0 .. std.mem.indexOfScalar(u8, header, '\n') orelse header.len], " \t\r"); - var buf: [256 + 16]u8 = undefined; - const row = std.fmt.bufPrint(&buf, "{d: >6} {s}", .{ d.start_line + 1, first[0..@min(first.len, 240)] }) catch continue; - names.add(gpa, row, 8, row.len - 8, 0, @intCast(d.start_line + 1)) catch break; } + // The file's text, which was parsed (the `Changes` layer's lines + // are none of it). + const text = File.fileText(f, p.scratch.allocator()) catch return; + const symbols = f.context.symbols; + // A row a symbol, ` 12 m Counts.lines : usize = 0`: its + // line, its mark, its name qualified by the ones it is in, then + // what its first line says after the name; types, functions, + // fields, then the rest, each in the text's order (UX DESIGN N). + // The name alone is matched. + for (0..4) |group| for (symbols) |sym| { + if (sym.kind.group() != group or sym.kind == .scope or sym.end > text.len) continue; + var buf: [512]u8 = undefined; + var row: std.Io.Writer = .fixed(&buf); + row.print("{d: >6} {s} ", .{ sym.line + 1, sym.kind.mark() }) catch continue; + const key_at = row.end; + qualify(&row, symbols, text, sym.parent, 4) catch continue; + row.writeAll(text[sym.name_start..sym.name_end]) catch continue; + const key_len = row.end - key_at; + const rest = text[sym.name_end..@max(sym.name_end, sym.end)]; + var detail = std.mem.trim(u8, rest[0 .. std.mem.indexOfScalar(u8, rest, '\n') orelse rest.len], " \t\r"); + detail = std.mem.trimEnd(u8, std.mem.trimEnd(u8, detail, "{,;"), " \t"); + if (detail.len > 0) row.print(" {s}", .{detail[0..@min(detail.len, buf.len - row.end -| 2)]}) catch {}; + names.add(gpa, row.buffered(), key_at, key_len, 0, sym.line + 1) catch break; + names.cands.items[names.cands.items.len - 1].group = @intCast(group); + }; }, else => {}, } } +/// The names of the symbols `parent` (an index + 1) is in, outermost +/// first, each with its `.`: `Outer.Inner.` (the `depth` innermost). +fn qualify(w: *std.Io.Writer, symbols: []const syntax.Symbol, text: []const u8, parent: u32, depth: u8) std.Io.Writer.Error!void { + if (parent == 0 or parent > symbols.len or depth == 0) return; + const up = symbols[parent - 1]; + if (up.name_end > text.len) return; + try qualify(w, symbols, text, up.parent, depth - 1); + try w.print("{s}.", .{text[up.name_start..up.name_end]}); +} + /// What a Panes row of a closed pane ends with. const closed_word = " (closed)"; diff --git a/core/Stream.zig b/core/Stream.zig index e9e7793b..50c43ae4 100644 --- a/core/Stream.zig +++ b/core/Stream.zig @@ -67,10 +67,11 @@ pub const Batch = struct { end: ?End = null, /// A parse's own time on the worker (`parse_ns`). took_ns: u64 = 0, - /// A parse's answer (`parseFor`): the declarations of pane `serial`'s - /// text at `revision`. + /// A parse's answer (`parseFor`): the declarations and symbols of pane + /// `serial`'s text at `revision`. parsed: ?struct { serial: u32, revision: u32 } = null, decls: []syntax.ContextDeclaration = &.{}, + symbols: []syntax.Symbol = &.{}, /// A paint's answer (`paintAhead`): the colours of pane `serial`'s text /// at `revision` from byte `start`, one syntax.Syn a byte. painted: ?struct { serial: u32, revision: u32, start: usize } = null, @@ -83,6 +84,7 @@ pub const Batch = struct { pub fn deinit(b: *const Batch, gpa: std.mem.Allocator) void { gpa.free(b.rows); gpa.free(b.decls); + gpa.free(b.symbols); gpa.free(b.styles); } }; @@ -480,9 +482,9 @@ pub fn parseFor(p: *Pardes, id: usize) void { fn parseWork(io: std.Io, job: *TextJob, ctx: ?*anyopaque, sink: Sink) void { const began = std.Io.Clock.awake.now(io); - const decls: []syntax.ContextDeclaration = syntax.declarationsApart(job.out, job.path, job.source, &job.stop) catch @constCast(&[_]syntax.ContextDeclaration{}); + const made: syntax.Context = syntax.contextApart(job.out, job.path, job.source, &job.stop) catch .{}; const took: u64 = @intCast(@max(0, began.durationTo(std.Io.Clock.awake.now(io)).nanoseconds)); - _ = sink(ctx, .{ .gen = job.gen, .decls = decls, .parsed = .{ .serial = job.serial, .revision = job.revision }, .end = .done, .took_ns = took }); + _ = sink(ctx, .{ .gen = job.gen, .decls = made.declarations, .symbols = made.symbols, .parsed = .{ .serial = job.serial, .revision = job.revision }, .end = .done, .took_ns = took }); } fn now() u64 { @@ -732,12 +734,15 @@ fn receiveParse(p: *Pardes, b: *const Batch, serial: u32, revision: u32) void { t.job.deinit(); }; s.parse_ns = b.took_ns; - if (p.paneBySerial(serial)) |id| if (p.panes[id].?.file) |*f| if (f.revision == revision and b.decls.len > 0) { - if (p.tree_sitter_gpa.dupe(syntax.ContextDeclaration, b.decls)) |copy| { - f.context.replace(p.tree_sitter_gpa, copy, revision); - panes.Query.declsArrived(p, serial); - panes.Pick.declsArrived(p, serial); - } else |_| {} + if (p.paneBySerial(serial)) |id| if (p.panes[id].?.file) |*f| if (f.revision == revision and (b.decls.len > 0 or b.symbols.len > 0)) kept: { + const decls = p.tree_sitter_gpa.dupe(syntax.ContextDeclaration, b.decls) catch break :kept; + const symbols = p.tree_sitter_gpa.dupe(syntax.Symbol, b.symbols) catch { + p.tree_sitter_gpa.free(decls); + break :kept; + }; + f.context.replace(p.tree_sitter_gpa, .{ .declarations = decls, .symbols = symbols }, revision); + panes.Query.declsArrived(p, serial); + panes.Pick.declsArrived(p, serial); }; p.needs_frame = true; // A `Churn` waiting on these declarations (jj.zig). diff --git a/core/colors.zig b/core/colors.zig index eefb2b67..f9de60c9 100644 --- a/core/colors.zig +++ b/core/colors.zig @@ -1381,6 +1381,10 @@ pub const Roles = struct { /// The letters a query matched: an ink, never a ground, 4.5:1 on every /// tag ground and on the selection. match: [3]u8, + /// A symbol's kind mark in a list (`t`, `f`, UX DESIGN N4): the + /// keyword's ink, which spells a kind in the text (`struct`, `fn`), + /// 4.5:1 on every tag ground and on the selection. + kind: [3]u8, /// The body's places and a preview's landing line, and the current /// one (its matched span): grounds off the page, its ink on them 4.5:1. hit: [3]u8, @@ -1429,6 +1433,7 @@ pub const Roles = struct { const tag_grounds = [_][3]u8{ plain, focused, reading, r.selected[0].ground, r.selected[1].ground, r.selected[2].ground, r.selected[3].ground }; r.key = pushAway(th.box, &tag_grounds, ink_floor); r.match = pushAway(matchHue(th), &tag_grounds, ink_floor); + r.kind = pushAway(th.kw, &tag_grounds, ink_floor); const page = th.bg orelse null_page; const body_ink = th.fg orelse th.tag_fg; const dark = relativeLuminance(page) < 0.18; @@ -2379,6 +2384,7 @@ test "every theme's walk UI roles meet their floors on every ground they are dra } try checks.append(a, .{ .what = "key", .got = leastContrast(r.key, &tags), .floor = @min(Roles.ink_floor, Reach.of(&tags)) }); try checks.append(a, .{ .what = "match", .got = leastContrast(r.match, &tags), .floor = @min(Roles.ink_floor, Reach.of(&tags)) }); + try checks.append(a, .{ .what = "kind", .got = leastContrast(r.kind, &tags), .floor = @min(Roles.ink_floor, Reach.of(&tags)) }); for (r.tag) |inks| { try checks.append(a, .{ .what = "rule", .got = contrast(inks.rule, inks.ground), .floor = Roles.rule_floor }); try checks.append(a, .{ .what = "rule ceiling", .got = Roles.rule_ceiling - contrast(inks.rule, inks.ground), .floor = 0 }); diff --git a/core/draw.zig b/core/draw.zig index b666fc15..447256a9 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -965,6 +965,7 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R if (b < part.row.chord) style.fg = .{ .rgb = chrome.roles.key }; if (b < part.row.pre) style.fg = .{ .rgb = if (active) chrome.tag_active_name_fg else chrome.tag_name_fg }; if (part.row.dim or (b >= part.row.pre and b < part.row.pre + part.row.faint) or (b >= part.row.quiet[0] and b < part.row.quiet[1])) style.fg = .{ .rgb = on.dim }; + if (b < part.row.kind) style.fg = .{ .rgb = chrome.roles.kind }; for (part.row.keys) |k| if (k == b) { style.fg = .{ .rgb = chrome.roles.key }; style.bold = true; diff --git a/core/dump.zig b/core/dump.zig index 2dde9c8c..663ee083 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -1379,7 +1379,7 @@ test "restored syntax context caches are rebuilt from the text rather than loade const f = &pane.file.?; const declarations = try p.tree_sitter_gpa.alloc(pardes.syntax.ContextDeclaration, 1); @memset(std.mem.sliceAsBytes(declarations), 0); - f.context.replace(p.tree_sitter_gpa, declarations, f.revision); + f.context.replace(p.tree_sitter_gpa, .{ .declarations = declarations }, f.revision); // Older builds persisted these two fields; the schema reader must skip them too. const OldFile = struct { path: []const u8, @@ -1405,13 +1405,14 @@ test "restored syntax context caches are rebuilt from the text rather than loade defer gpa.free(bytes); const q = try load(gpa, opts, bytes, null); defer q.deinit(); - // This build's: the revision kept, the declarations parsed again from - // the text, with the syntax allocator. - const want = try pardes.syntax.contextDeclarations(syntax_gpa.allocator(), f.path, f.content); - defer syntax_gpa.allocator().free(want); + // This build's: the revision kept, the declarations and the symbols + // parsed again from the text, with the syntax allocator. + var want = try pardes.syntax.context(syntax_gpa.allocator(), f.path, f.content); + defer want.deinit(syntax_gpa.allocator()); for (q.panes) |slot| if (slot) |restored| if (restored.file) |file| { try std.testing.expectEqual(f.context.revision, file.context.revision); - try std.testing.expectEqualSlices(pardes.syntax.ContextDeclaration, want, file.context.declarations); + try std.testing.expectEqualSlices(pardes.syntax.ContextDeclaration, want.declarations, file.context.declarations); + try std.testing.expectEqualSlices(pardes.syntax.Symbol, want.symbols, file.context.symbols); }; } diff --git a/core/root.zig b/core/root.zig index 11cb5058..86ca62e0 100644 --- a/core/root.zig +++ b/core/root.zig @@ -461,6 +461,7 @@ test { _ = @import("FrameStats.zig"); _ = @import("Query.zig"); _ = @import("Names.zig"); + _ = @import("syntax.zig"); // its tests ran nowhere before _ = @import("Stream.zig"); _ = @import("Tables.zig"); _ = @import("Handover.zig"); diff --git a/core/syntax.zig b/core/syntax.zig index 5c05300e..5cdc2ff3 100644 --- a/core/syntax.zig +++ b/core/syntax.zig @@ -621,7 +621,7 @@ pub fn analyzeSource(gpa: std.mem.Allocator, path: []const u8, content: []const defer tree.destroy(); var result: SourceAnalysis = .{}; errdefer result.deinit(gpa); - if (want_declarations) result.declarations = try declarationsFromTree(gpa, content, tree, null); + if (want_declarations) result.declarations = (try contextFromTree(gpa, content, tree, null, &.{})).declarations; if (want_colors) { result.colors = try gpa.alloc(u8, content.len); @memset(result.colors, 0); @@ -635,23 +635,52 @@ pub fn contextDeclarations(gpa: std.mem.Allocator, path: []const u8, content: [] return analysis.declarations; } -/// The declarations of `content` (its path's language), on a worker -/// (`parseApart`). `halt` ends the parse and the walk early -/// (error.Canceled): a 1.2 MB file is seconds in a Debug build. -pub fn declarationsApart(gpa: std.mem.Allocator, path: []const u8, content: []const u8, halt: *const std.atomic.Value(bool)) ![]ContextDeclaration { - if (content.len == 0) return &.{}; +/// A text's context, from one parse: its declarations (the sticky +/// headers', Locations') and its symbols (the Symbols picker's, UX DESIGN +/// N), both of the same allocator. +pub const Context = struct { + declarations: []ContextDeclaration = &.{}, + symbols: []Symbol = &.{}, + + pub fn deinit(c: *Context, gpa: std.mem.Allocator) void { + gpa.free(c.declarations); + gpa.free(c.symbols); + c.* = .{}; + } +}; + +/// `content`'s context (its path's language), parsed here: a sticky +/// header's (File.refreshContext), a loaded text's. +pub fn context(gpa: std.mem.Allocator, path: []const u8, content: []const u8) !Context { + if (content.len == 0) return .{}; + const spec = byExt(std.Io.Dir.path.extension(path)) orelse return .{}; + const selected = try ensure(spec); + const tree = selected.parser.parseString(content, null) orelse return .{}; + defer tree.destroy(); + return contextFromTree(gpa, content, tree, null, rulesOf(spec.name)); +} + +/// `content`'s context, on a worker (`parseApart`). `halt` ends the parse +/// and the walk early (error.Canceled): a 1.2 MB file is seconds in a +/// Debug build. +pub fn contextApart(gpa: std.mem.Allocator, path: []const u8, content: []const u8, halt: *const std.atomic.Value(bool)) !Context { + if (content.len == 0) return .{}; const ext = std.Io.Dir.path.extension(path); const spec = specs: for (&specs) |*spec| { for (spec.exts) |choice| if (std.ascii.eqlIgnoreCase(ext, choice)) break :specs spec; - } else return &.{}; + } else return .{}; const tree = try parseApart(langOf(spec), content, halt); defer tree.destroy(); - return declarationsFromTree(gpa, content, tree, halt); + return contextFromTree(gpa, content, tree, halt, rulesOf(spec.name)); } -fn declarationsFromTree(gpa: std.mem.Allocator, content: []const u8, tree: *ts.Tree, halt: ?*const std.atomic.Value(bool)) ![]ContextDeclaration { +/// The declarations and, by `rules` (none: no symbols), the symbols of a +/// parse, in one walk of its nodes. +fn contextFromTree(gpa: std.mem.Allocator, content: []const u8, tree: *ts.Tree, halt: ?*const std.atomic.Value(bool), rules: []const Rule) !Context { var result: std.ArrayList(ContextDeclaration) = .empty; errdefer result.deinit(gpa); + var symbols: SymbolWalk = .{ .gpa = gpa, .rules = rules, .source = content }; + errdefer symbols.out.deinit(gpa); // The cursor retains its ancestor stack: sibling visits do not repeatedly // reconstruct parents in broad syntax trees. Preorder preserves source order. var cursor = tree.rootNode().walk(); @@ -661,14 +690,21 @@ fn declarationsFromTree(gpa: std.mem.Allocator, content: []const u8, tree: *ts.T visited += 1; if (halt) |flag| if (visited % 4096 == 0 and flag.load(.monotonic)) return error.Canceled; const node = cursor.node(); - if (node.isNamed()) if (contextSpan(node, content)) |span| { - if (result.items.len == 0 or result.items[result.items.len - 1].start_line != span.start_line or - result.items[result.items.len - 1].end_line != span.end_line) - try result.append(gpa, span); - }; + if (node.isNamed()) { + if (contextSpan(node, content)) |span| { + if (result.items.len == 0 or result.items[result.items.len - 1].start_line != span.start_line or + result.items[result.items.len - 1].end_line != span.end_line) + try result.append(gpa, span); + } + if (rules.len > 0) try symbols.visit(node); + } if (cursor.gotoFirstChild()) continue; while (!cursor.gotoNextSibling()) { - if (!cursor.gotoParent()) return result.toOwnedSlice(gpa); + if (!cursor.gotoParent()) { + const declarations = try result.toOwnedSlice(gpa); + errdefer gpa.free(declarations); + return .{ .declarations = declarations, .symbols = try symbols.out.toOwnedSlice(gpa) }; + } } } } @@ -761,6 +797,527 @@ fn contextSpan(node: ts.Node, source: []const u8) ?ContextDeclaration { }; } +// ---- symbols: the Symbols picker's (UX DESIGN N) ---- + +/// What a symbol is, in the Symbols picker's order (UX DESIGN N2): types, +/// functions, fields, then the rest (consts, vars, modules, other) as one +/// group. A `scope` is listed nowhere: it names its members (Rust's +/// `impl S`: `S.new`). +pub const SymbolKind = enum(u8) { + type, + function, + field, + constant, + variable, + module, + other, + scope, + + /// Its mark in a row (UX DESIGN N4): one letter, `·` for the other. + pub fn mark(k: SymbolKind) []const u8 { + return switch (k) { + .type => "t", + .function => "f", + .field => "m", + .constant => "c", + .variable => "v", + .module => "n", + .other, .scope => "·", + }; + } + + /// Its group in the picker: 0 types, 1 functions, 2 fields, 3 the rest. + pub fn group(k: SymbolKind) u8 { + return @min(@intFromEnum(k), 3); + } +}; + +/// A declaration the Symbols picker lists: its kind, the line and bytes of +/// its name, and the symbol it is declared in. +pub const Symbol = struct { + kind: SymbolKind, + /// The line its name is on, from 0. + line: u32, + name_start: u32, + name_end: u32, + /// Where what its row says after its name ends (a function's + /// signature): its body's start, else its own end. Its row cuts it at + /// its name's line's end. + end: u32, + /// The symbol it is declared in, by its index + 1 (0: none): its name + /// qualifies this one's (`Counts.lines`). + parent: u32 = 0, +}; + +/// How a node of a grammar is a symbol (UX DESIGN N2: one table a language). +const Rule = struct { + node: []const u8, + kind: SymbolKind, + how: How = .plain, + /// The field naming it; without it, its declarator's name (C's) or the + /// first name under it (`nameOf`). "": none (an anonymous scope). + name: []const u8 = "name", + /// A form's first words and the kinds they declare (`.head`). + heads: []const struct { []const u8, SymbolKind } = &.{}, + /// Not one under a node of this kind (Pascal's declProc heading the + /// defProc that is the symbol). + unless_in: []const u8 = "", +}; + +const How = enum { + /// Its kind as given. + plain, + /// Only with a body (C's `struct s { ... }`; `struct s x;` names the + /// type, declares none); unnamed, a scope (an anonymous struct's fields + /// are its owner's). + body, + /// C's declaration: a function where a declarator on the way to its + /// name is one's; else a const where `const` says so (its kind a var). + declarator, + /// A binding whose value tells: a type, a function, a module (Zig's + /// `const S = struct`, `@import`, JavaScript's arrow function); else a + /// const or a var by its keyword. + value, + /// A binding that is a field in a type (a Python class's attribute, + /// Kotlin's property); else a const or a var by its keyword. Named + /// by a name, never a pattern (`self.x = ...`). + binding, + /// A form whose first word says what it declares (Elixir's `def f`, + /// Clojure's `(defn f ...)`), named by its second. + head, + /// No row: a scope its members are named in, by its own name (Rust's + /// `impl S`) or its owner's (an anonymous struct). + scope, +}; + +const c_rules = [_]Rule{ + .{ .node = "function_definition", .kind = .function }, + .{ .node = "declaration", .kind = .variable, .how = .declarator }, + .{ .node = "field_declaration", .kind = .field, .how = .declarator }, + .{ .node = "struct_specifier", .kind = .type, .how = .body }, + .{ .node = "union_specifier", .kind = .type, .how = .body }, + .{ .node = "enum_specifier", .kind = .type, .how = .body }, + .{ .node = "enumerator", .kind = .field }, + .{ .node = "type_definition", .kind = .type }, + .{ .node = "preproc_def", .kind = .other }, + .{ .node = "preproc_function_def", .kind = .other }, +}; + +/// The kind tables, by grammar (grammar_manifest.zig): a grammar with none +/// (JSON, CSS, HTML, Markdown, Typst) lists no symbols. +const symbol_rules = [_]struct { []const u8, []const Rule }{ + .{ "zig", &.{ + // Named by its FnProto's `function` (symbolOf). + .{ .node = "Decl", .kind = .function, .name = "" }, + .{ .node = "VarDecl", .kind = .variable, .how = .value, .name = "variable_type_function" }, + .{ .node = "ContainerField", .kind = .field }, + .{ .node = "TestDecl", .kind = .other, .name = "" }, + .{ .node = "ContainerDecl", .kind = .type, .how = .scope, .name = "" }, + } }, + .{ "c", &c_rules }, + .{ "cpp", &(c_rules ++ [_]Rule{ + .{ .node = "class_specifier", .kind = .type, .how = .body }, + .{ .node = "namespace_definition", .kind = .module }, + .{ .node = "alias_declaration", .kind = .type }, + }) }, + .{ "rust", &.{ + .{ .node = "function_item", .kind = .function }, + .{ .node = "function_signature_item", .kind = .function }, + .{ .node = "struct_item", .kind = .type }, + .{ .node = "enum_item", .kind = .type }, + .{ .node = "union_item", .kind = .type }, + .{ .node = "trait_item", .kind = .type }, + .{ .node = "type_item", .kind = .type }, + .{ .node = "impl_item", .kind = .type, .how = .scope, .name = "type" }, + .{ .node = "field_declaration", .kind = .field }, + .{ .node = "enum_variant", .kind = .field }, + .{ .node = "const_item", .kind = .constant }, + .{ .node = "static_item", .kind = .variable }, + .{ .node = "mod_item", .kind = .module }, + .{ .node = "macro_definition", .kind = .other }, + } }, + .{ "go", &.{ + .{ .node = "function_declaration", .kind = .function }, + .{ .node = "method_declaration", .kind = .function }, + .{ .node = "method_elem", .kind = .function }, + .{ .node = "type_spec", .kind = .type }, + .{ .node = "type_alias", .kind = .type }, + .{ .node = "field_declaration", .kind = .field }, + .{ .node = "const_spec", .kind = .constant }, + .{ .node = "var_spec", .kind = .variable }, + } }, + .{ "python", &.{ + .{ .node = "class_definition", .kind = .type }, + .{ .node = "function_definition", .kind = .function }, + .{ .node = "assignment", .kind = .variable, .how = .binding, .name = "left" }, + } }, + .{ "javascript", &.{ + .{ .node = "function_declaration", .kind = .function }, + .{ .node = "generator_function_declaration", .kind = .function }, + .{ .node = "class_declaration", .kind = .type }, + .{ .node = "method_definition", .kind = .function }, + .{ .node = "field_definition", .kind = .field, .name = "property" }, + .{ .node = "variable_declarator", .kind = .variable, .how = .value }, + } }, + .{ "java", &.{ + .{ .node = "class_declaration", .kind = .type }, + .{ .node = "interface_declaration", .kind = .type }, + .{ .node = "enum_declaration", .kind = .type }, + .{ .node = "record_declaration", .kind = .type }, + .{ .node = "annotation_type_declaration", .kind = .type }, + .{ .node = "method_declaration", .kind = .function }, + .{ .node = "constructor_declaration", .kind = .function }, + .{ .node = "field_declaration", .kind = .field }, + .{ .node = "enum_constant", .kind = .field }, + .{ .node = "constant_declaration", .kind = .constant }, + } }, + .{ "c_sharp", &.{ + .{ .node = "class_declaration", .kind = .type }, + .{ .node = "struct_declaration", .kind = .type }, + .{ .node = "interface_declaration", .kind = .type }, + .{ .node = "enum_declaration", .kind = .type }, + .{ .node = "record_declaration", .kind = .type }, + .{ .node = "delegate_declaration", .kind = .type }, + .{ .node = "namespace_declaration", .kind = .module }, + .{ .node = "file_scoped_namespace_declaration", .kind = .module }, + .{ .node = "method_declaration", .kind = .function }, + .{ .node = "constructor_declaration", .kind = .function }, + .{ .node = "destructor_declaration", .kind = .function }, + .{ .node = "field_declaration", .kind = .field }, + .{ .node = "property_declaration", .kind = .field }, + .{ .node = "event_field_declaration", .kind = .field }, + .{ .node = "enum_member_declaration", .kind = .field }, + } }, + .{ "kotlin", &.{ + .{ .node = "class_declaration", .kind = .type }, + .{ .node = "object_declaration", .kind = .type }, + .{ .node = "companion_object", .kind = .type, .how = .scope, .name = "" }, + .{ .node = "function_declaration", .kind = .function }, + .{ .node = "property_declaration", .kind = .variable, .how = .binding }, + .{ .node = "type_alias", .kind = .type }, + .{ .node = "enum_entry", .kind = .field }, + } }, + .{ "scala", &.{ + .{ .node = "class_definition", .kind = .type }, + .{ .node = "object_definition", .kind = .type }, + .{ .node = "trait_definition", .kind = .type }, + .{ .node = "enum_definition", .kind = .type }, + .{ .node = "type_definition", .kind = .type }, + .{ .node = "function_definition", .kind = .function }, + .{ .node = "function_declaration", .kind = .function }, + .{ .node = "val_definition", .kind = .constant, .how = .binding, .name = "pattern" }, + .{ .node = "var_definition", .kind = .variable, .how = .binding, .name = "pattern" }, + .{ .node = "simple_enum_case", .kind = .field }, + .{ .node = "full_enum_case", .kind = .field }, + } }, + .{ "ruby", &.{ + .{ .node = "class", .kind = .type }, + .{ .node = "singleton_class", .kind = .type, .how = .scope, .name = "" }, + .{ .node = "module", .kind = .module }, + .{ .node = "method", .kind = .function }, + .{ .node = "singleton_method", .kind = .function }, + } }, + .{ "php", &.{ + .{ .node = "class_declaration", .kind = .type }, + .{ .node = "interface_declaration", .kind = .type }, + .{ .node = "trait_declaration", .kind = .type }, + .{ .node = "enum_declaration", .kind = .type }, + .{ .node = "function_definition", .kind = .function }, + .{ .node = "method_declaration", .kind = .function }, + .{ .node = "property_declaration", .kind = .field }, + .{ .node = "enum_case", .kind = .field }, + .{ .node = "const_declaration", .kind = .constant }, + .{ .node = "namespace_definition", .kind = .module }, + } }, + .{ "bash", &.{ + .{ .node = "function_definition", .kind = .function }, + .{ .node = "variable_assignment", .kind = .variable, .how = .binding }, + } }, + .{ "haskell", &.{ + .{ .node = "data_type", .kind = .type }, + .{ .node = "newtype", .kind = .type }, + .{ .node = "type_synomym", .kind = .type }, + .{ .node = "class", .kind = .type }, + .{ .node = "instance", .kind = .type, .how = .scope }, + .{ .node = "function", .kind = .function }, + .{ .node = "bind", .kind = .constant }, + .{ .node = "data_constructor", .kind = .field }, + } }, + .{ "ocaml", &.{ + .{ .node = "type_binding", .kind = .type }, + .{ .node = "module_binding", .kind = .module }, + .{ .node = "module_type_definition", .kind = .type }, + .{ .node = "class_binding", .kind = .type }, + .{ .node = "method_definition", .kind = .function }, + .{ .node = "let_binding", .kind = .constant, .how = .value, .name = "pattern" }, + .{ .node = "field_declaration", .kind = .field }, + .{ .node = "constructor_declaration", .kind = .field }, + } }, + .{ "erlang", &.{ + .{ .node = "fun_decl", .kind = .function }, + .{ .node = "record_decl", .kind = .type }, + .{ .node = "record_field", .kind = .field }, + .{ .node = "type_alias", .kind = .type }, + .{ .node = "pp_define", .kind = .other }, + .{ .node = "module_attribute", .kind = .module }, + } }, + .{ "elixir", &.{ + .{ .node = "call", .kind = .other, .how = .head, .heads = &.{ + .{ "defmodule", .module }, .{ "defprotocol", .type }, .{ "def", .function }, + .{ "defp", .function }, .{ "defdelegate", .function }, .{ "defguard", .function }, + .{ "defguardp", .function }, .{ "defmacro", .other }, .{ "defmacrop", .other }, + } }, + } }, + .{ "clojure", &.{ + .{ .node = "list_lit", .kind = .other, .how = .head, .heads = &.{ + .{ "ns", .module }, .{ "def", .constant }, .{ "defonce", .constant }, .{ "defn", .function }, + .{ "defn-", .function }, .{ "defmulti", .function }, .{ "defmethod", .function }, .{ "defmacro", .other }, + .{ "defrecord", .type }, .{ "deftype", .type }, .{ "defprotocol", .type }, .{ "definterface", .type }, + .{ "defstruct", .type }, + } }, + } }, + .{ "fortran", &.{ + .{ .node = "module", .kind = .module }, + .{ .node = "program", .kind = .module }, + .{ .node = "subroutine", .kind = .function }, + .{ .node = "function", .kind = .function }, + .{ .node = "derived_type_definition", .kind = .type }, + .{ .node = "variable_declaration", .kind = .variable, .how = .binding }, + } }, + .{ "ada", &.{ + .{ .node = "package_declaration", .kind = .module }, + .{ .node = "package_body", .kind = .module }, + .{ .node = "full_type_declaration", .kind = .type }, + .{ .node = "subprogram_declaration", .kind = .function }, + .{ .node = "subprogram_body", .kind = .function }, + .{ .node = "object_declaration", .kind = .variable, .how = .binding }, + .{ .node = "component_declaration", .kind = .field }, + } }, + .{ "pascal", &.{ + .{ .node = "declType", .kind = .type }, + .{ .node = "declProc", .kind = .function, .unless_in = "defProc" }, + .{ .node = "defProc", .kind = .function }, + .{ .node = "declConst", .kind = .constant }, + .{ .node = "declVar", .kind = .variable, .how = .binding }, + .{ .node = "declField", .kind = .field }, + } }, + .{ "powershell", &.{ + .{ .node = "function_statement", .kind = .function }, + .{ .node = "class_statement", .kind = .type }, + .{ .node = "class_method_definition", .kind = .function }, + .{ .node = "class_property_definition", .kind = .field }, + .{ .node = "enum_statement", .kind = .type }, + .{ .node = "enum_member", .kind = .field }, + } }, +}; + +fn rulesOf(grammar: []const u8) []const Rule { + for (symbol_rules) |entry| if (std.mem.eql(u8, entry[0], grammar)) return entry[1]; + return &.{}; +} + +/// A walk's symbols, node by node in preorder (`contextFromTree`). +const SymbolWalk = struct { + gpa: std.mem.Allocator, + rules: []const Rule, + source: []const u8, + out: std.ArrayList(Symbol) = .empty, + /// The scopes the node is in, the innermost last. + scopes: [max_scopes]Scope = undefined, + depth: u8 = 0, + + /// Where a scope ends, its kind, and the symbol its members are named + /// in (an index + 1, 0 none). + const Scope = struct { end: u32, kind: SymbolKind, symbol: u32 }; + /// Deeper scopes are their parent's. + const max_scopes = 32; + + fn visit(w: *SymbolWalk, node: ts.Node) !void { + while (w.depth > 0 and w.scopes[w.depth - 1].end <= node.startByte()) w.depth -= 1; + const in: Scope = if (w.depth > 0) w.scopes[w.depth - 1] else .{ .end = 0, .kind = .module, .symbol = 0 }; + const kind_name = node.kind(); + const rule = for (w.rules) |r| { + if (std.mem.eql(u8, r.node, kind_name)) break r; + } else return; + const found = symbolOf(rule, node, w.source, in.kind) orelse return; + // A body's consts and vars are its locals, none of them listed. + const local = in.kind != .type and in.kind != .module and in.kind != .scope; + if (local and (found.kind == .constant or found.kind == .variable)) return; + var named = in.symbol; + if (found.name) |name| { + try w.out.append(w.gpa, .{ + .kind = found.kind, + .line = name.startPoint().row, + .name_start = name.startByte(), + .name_end = name.endByte(), + .end = found.end, + .parent = in.symbol, + }); + // A const's or a field's members are not named in it. + if (found.kind == .type or found.kind == .function or found.kind == .module or found.kind == .scope) named = @intCast(w.out.items.len); + } + if (w.depth == max_scopes) return; + w.scopes[w.depth] = .{ .end = node.endByte(), .kind = if (found.kind == .scope) rule.kind else found.kind, .symbol = named }; + w.depth += 1; + } +}; + +/// What node `node` declares by `rule`, in a scope of kind `in`: its kind, +/// its name (null: an anonymous scope) and where its row's words end. +fn symbolOf(rule: Rule, node: ts.Node, source: []const u8, in: SymbolKind) ?struct { kind: SymbolKind, name: ?ts.Node, end: u32 } { + if (rule.unless_in.len > 0) if (node.parent()) |up| if (std.mem.eql(u8, up.kind(), rule.unless_in)) return null; + var kind = rule.kind; + var name: ?ts.Node = null; + var end = if (node.childByFieldName("body")) |body| body.startByte() else node.endByte(); + switch (rule.how) { + .plain => name = nameOf(node, rule.name), + .scope => { + name = nameOf(node, rule.name); + kind = .scope; + }, + .body => { + if (node.childByFieldName("body") == null) return null; + name = nameOf(node, rule.name); + if (name == null) kind = .scope; + }, + .declarator => { + var d = node; + while (d.childByFieldName("declarator")) |next| { + if (std.mem.eql(u8, next.kind(), "function_declarator")) kind = .function; + d = next; + } + name = nameOf(node, rule.name); + if (kind == .variable and constant(source, node.startByte(), name orelse return null)) kind = .constant; + }, + .value => { + name = nameOf(node, rule.name); + kind = valueKind(node, source) orelse kind; + // JavaScript's keyword is its declaration's (`const a = 1, b`). + const from = if (std.mem.eql(u8, rule.node, "variable_declarator")) (node.parent() orelse node).startByte() else node.startByte(); + if (kind == .variable and constant(source, from, name orelse return null)) kind = .constant; + }, + .binding => { + const n = node.childByFieldName(rule.name) orelse nameOf(node, rule.name) orelse return null; + if (!nameLike(n.kind())) return null; + name = n; + if (in == .type) kind = .field else if (kind == .variable and constant(source, node.startByte(), n)) kind = .constant; + }, + .head => { + const elixir = std.mem.eql(u8, rule.node, "call"); + const first = (if (elixir) node.childByFieldName("target") else node.namedChild(0)) orelse return null; + const word = source[first.startByte()..first.endByte()]; + kind = for (rule.heads) |h| { + if (std.mem.eql(u8, h[0], word)) break h[1]; + } else return null; + var second = (if (elixir) childOfKind(node, "arguments") else node.namedChild(1)) orelse return null; + if (elixir) second = second.namedChild(0) orelse return null; + if (second.childByFieldName("target")) |target| second = target; + name = if (nameLike(second.kind())) second else nameOf(second, "name"); + }, + } + // Zig's: a function's name is its prototype's, its body a Block; a + // test's its string. + if (std.mem.eql(u8, rule.node, "Decl")) { + const proto = childOfKind(node, "FnProto") orelse return null; + name = proto.childByFieldName("function"); + if (childOfKind(node, "Block")) |block| end = block.startByte(); + } else if (std.mem.eql(u8, rule.node, "TestDecl")) { + const first = node.namedChild(0) orelse return null; + if (std.mem.eql(u8, first.kind(), "Block")) return null; + name = first; + if (childOfKind(node, "Block")) |block| end = block.startByte(); + } + if (name == null and kind != .scope) return null; + if (name) |n| if (n.endByte() <= n.startByte() or n.endByte() - n.startByte() > max_name) return null; + return .{ .kind = kind, .name = name, .end = end }; +} + +/// The longest name a symbol has: a longer one is no name. +const max_name = 200; + +/// The node naming `node`: its field `field`; without one, its declarator's +/// (C's `int *f(void)`: `f`); else the first name under it, past its +/// type, value, body and parameters (Kotlin's, Fortran's). +fn nameOf(node: ts.Node, field: []const u8) ?ts.Node { + if (field.len == 0) return null; + var n = node; + if (node.childByFieldName(field)) |f| n = f else while (n.childByFieldName("declarator")) |d| n = d; + if (nameLike(n.kind())) return n; + if (n.childByFieldName("name")) |f| if (nameLike(f.kind())) return f; + return firstName(n, 3); +} + +fn firstName(node: ts.Node, depth: u8) ?ts.Node { + if (depth == 0) return null; + const skipped = [_][]const u8{ "type", "value", "body", "parameters", "return_type", "returns", "result", "superclass", "arguments", "default", "trait" }; + var i: u32 = 0; + while (i < node.childCount()) : (i += 1) { + const child = node.child(i) orelse continue; + if (!child.isNamed()) continue; + const field = node.fieldNameForChild(i) orelse ""; + if (for (skipped) |s| { + if (std.mem.eql(u8, s, field)) break true; + } else false) continue; + const kind = child.kind(); + if (std.mem.indexOf(u8, kind, "modifier") != null or std.mem.indexOf(u8, kind, "annotation") != null or + std.mem.indexOf(u8, kind, "parameter") != null or std.mem.indexOf(u8, kind, "attribute") != null or + std.mem.indexOf(u8, kind, "decorator") != null or std.mem.indexOf(u8, kind, "comment") != null or + std.mem.indexOf(u8, kind, "literal") != null) continue; + if (nameLike(kind)) return child; + if (firstName(child, depth - 1)) |found| return found; + } + return null; +} + +/// A node kind that is a name: an identifier, a `*_name`, a word. +fn nameLike(kind: []const u8) bool { + if (std.ascii.endsWithIgnoreCase(kind, "identifier") or std.mem.endsWith(u8, kind, "name")) return true; + for ([_][]const u8{ "word", "constant", "atom", "variable", "constructor", "type_constructor", "alias" }) |k| { + if (std.mem.eql(u8, kind, k)) return true; + } + return false; +} + +/// What a binding's value makes it, where it says (else null): Zig's +/// `struct {...}`, `error{...}`, `@This()`, `@Type(...)` a type and +/// `@import(...)` a module; JavaScript's function a function and class a +/// type; OCaml's `let f x = ...` (a parameter) a function. +fn valueKind(node: ts.Node, source: []const u8) ?SymbolKind { + if (node.childByFieldName("value")) |value| { + const kind = value.kind(); + for ([_][]const u8{ "arrow_function", "function_expression", "generator_function" }) |k| if (std.mem.eql(u8, kind, k)) return .function; + if (std.mem.eql(u8, kind, "class")) return .type; + return null; + } + if (childOfKind(node, "parameter") != null) return .function; + // Zig's value: the last of the VarDecl, under its ErrorUnionExpr. + var v = node.namedChild(node.namedChildCount() -| 1) orelse return null; + while (std.mem.eql(u8, v.kind(), "ErrorUnionExpr")) v = v.namedChild(0) orelse return null; + if (!std.mem.eql(u8, v.kind(), "SuffixExpr")) return null; + const first = v.namedChild(0) orelse return null; + const kind = first.kind(); + if (std.mem.eql(u8, kind, "ContainerDecl") or std.mem.eql(u8, kind, "ErrorSetDecl")) return .type; + if (!std.mem.eql(u8, kind, "BUILTINIDENTIFIER")) return null; + const builtin = source[first.startByte()..first.endByte()]; + if (std.mem.eql(u8, builtin, "@This") or std.mem.eql(u8, builtin, "@Type")) return .type; + if ((std.mem.eql(u8, builtin, "@import") or std.mem.eql(u8, builtin, "@cImport")) and v.namedChildCount() == 2) return .module; + return null; +} + +/// Whether a binding is a const: a keyword says so between `from` and its +/// name, or after the name before its value (Ada's `K : constant`). +fn constant(source: []const u8, from: usize, name: ts.Node) bool { + const after = source[name.endByte()..]; + const before_value = std.mem.indexOfAny(u8, after, "=\n") orelse after.len; + for ([_][]const u8{ source[@min(from, name.startByte())..name.startByte()], after[0..before_value] }) |text| { + var words = std.mem.tokenizeAny(u8, text, " \t\r\n,:()*&"); + while (words.next()) |word| for ([_][]const u8{ "const", "constexpr", "val", "final", "readonly", "parameter", "constant" }) |k| { + if (std.mem.eql(u8, word, k)) return true; + }; + } + return false; +} + fn paint(styles: []u8, source: []const u8, selected: Selected) void { const tree = selected.parser.parseString(source, null) orelse return; defer tree.destroy(); @@ -2180,3 +2737,123 @@ test "syntax: a grammar handed in at run time colours and walks as the one compi forgetLanguages(); try std.testing.expect(!supportsPath("x.mine")); } + +/// Each of `source`'s symbols as `mark qualified name`, in the walk's order. +fn symbolLines(gpa: std.mem.Allocator, path: []const u8, source: []const u8) ![]const u8 { + var made = try context(gpa, path, source); + defer made.deinit(gpa); + var out: std.Io.Writer.Allocating = .init(gpa); + defer out.deinit(); + for (made.symbols) |sym| { + if (sym.kind == .scope) continue; + try out.writer.print("{s} ", .{sym.kind.mark()}); + var chain: [8]u32 = undefined; + var n: usize = 0; + var up = sym.parent; + while (up != 0 and n < chain.len) : (up = made.symbols[up - 1].parent) { + chain[n] = up; + n += 1; + } + while (n > 0) { + n -= 1; + const s = made.symbols[chain[n] - 1]; + try out.writer.print("{s}.", .{source[s.name_start..s.name_end]}); + } + try out.writer.print("{s}\n", .{source[sym.name_start..sym.name_end]}); + } + return out.toOwnedSlice(); +} + +test "syntax symbols: a Zig file's types, functions, fields and the rest by their declarations and values, each named in the containers it is in; a function's locals and an unnamed test none of them (UX DESIGN N2)" { + if (comptime !minimal_grammars) return error.SkipZigTest; + const gpa = std.testing.allocator; + start(gpa); + defer stop(); + const source = + \\const std = @import("std"); + \\pub const Counts = struct { + \\ lines: usize = 0, + \\ pub const zero: Counts = .{}; + \\ pub fn add(c: *Counts) void { + \\ const local = 1; + \\ c.lines += local; + \\ } + \\}; + \\const Mode = enum { fast, slow }; + \\const Failure = error{ Late, Lost }; + \\const Self = @This(); + \\var hits: u32 = 0; + \\fn List(comptime T: type) type { + \\ return struct { items: []T }; + \\} + \\test "count" {} + \\test {} + \\extern fn tick() void; + \\ + ; + const lines = try symbolLines(gpa, "a.zig", source); + defer gpa.free(lines); + try std.testing.expectEqualStrings( + \\n std + \\t Counts + \\m Counts.lines + \\c Counts.zero + \\f Counts.add + \\t Mode + \\m Mode.fast + \\m Mode.slow + \\t Failure + \\t Self + \\v hits + \\f List + \\m List.items + \\· "count" + \\f tick + \\ + , lines); +} + +test "syntax symbols: C, C++, Rust, Go, Python and JavaScript by their kind tables, members named in their types, an impl's in its type, locals none" { + if (!full_grammars) return error.SkipZigTest; + const gpa = std.testing.allocator; + start(gpa); + defer stop(); + const cases = [_]struct { path: []const u8, source: []const u8, want: []const u8 }{ + .{ .path = "a.c", .source = "#define LIMIT 4\nstruct point { int x; int *y; };\ntypedef struct { int a; } pair;\nenum color { RED };\nstatic int counter = 0;\nconst int limit = 4;\nint add(int a) { int local = a; return local; }\nint later(void);\nstruct point p;\n", .want = "· LIMIT\nt point\nm point.x\nm point.y\nt pair\nm pair.a\nt color\nm color.RED\nv counter\nc limit\nf add\nf later\nv p\n" }, + .{ .path = "a.cc", .source = "namespace torque {\nclass Parser : public Base {\n public:\n Parser();\n int Parse(int depth) const { return depth; }\n int depth_;\n};\nint Parser::Run(int n) { int local = n; return local; }\nusing Alias = int;\n}\n", .want = "n torque\nt torque.Parser\nf torque.Parser.Parser\nf torque.Parser.Parse\nm torque.Parser.depth_\nf torque.Parser::Run\nt torque.Alias\n" }, + .{ .path = "a.rs", .source = "mod m {\npub struct S { pub a: u32 }\nenum E { A, B(u32) }\ntrait T { fn f(&self); }\nimpl S { pub fn new() -> Self { let x = 1; S { a: x } } }\nconst C: u32 = 1;\nstatic G: u32 = 2;\nmacro_rules! mac { () => {} }\n}\n", .want = "n m\nt m.S\nm m.S.a\nt m.E\nm m.E.A\nm m.E.B\nt m.T\nf m.T.f\nf m.S.new\nc m.C\nv m.G\n· m.mac\n" }, + .{ .path = "a.go", .source = "package main\ntype S struct { A int }\ntype I interface { M() }\nconst C = 1\nvar V = 2\nfunc F() { var x = 1; _ = x }\nfunc (s *S) M() {}\n", .want = "t S\nm S.A\nt I\nf I.M\nc C\nv V\nf F\nf M\n" }, + .{ .path = "a.py", .source = "X = 1\nclass C:\n attr = 2\n def m(self):\n y = 3\n self.z = 4\ndef f():\n pass\n", .want = "v X\nt C\nm C.attr\nf C.m\nf f\n" }, + .{ .path = "a.js", .source = "const A = 1;\nlet b = 2;\nfunction f() { const local = 1; }\nclass K { field = 1; m() {} }\nconst arrow = () => 1;\nconst Klass = class {};\n", .want = "c A\nv b\nf f\nt K\nm K.field\nf K.m\nf arrow\nt Klass\n" }, + }; + for (cases) |case| { + const lines = try symbolLines(gpa, case.path, case.source); + defer gpa.free(lines); + std.testing.expectEqualStrings(case.want, lines) catch |err| { + std.debug.print("in {s}\n", .{case.path}); + return err; + }; + } +} + +test "syntax symbols: every kind table names nodes of its grammar, and a grammar with none (JSON) lists no symbol" { + if (!full_grammars) return error.SkipZigTest; + const gpa = std.testing.allocator; + start(gpa); + defer stop(); + var tables: usize = 0; + for (symbol_rules) |entry| { + const spec = for (&specs) |*spec| { + if (std.mem.eql(u8, spec.name, entry[0])) break spec; + } else return error.NoGrammar; + for (entry[1]) |rule| std.testing.expect(langOf(spec).idForNodeKind(rule.node, true) != 0) catch |err| { + std.debug.print("{s} has no node {s}\n", .{ entry[0], rule.node }); + return err; + }; + tables += 1; + } + try std.testing.expectEqual(@as(usize, 23), tables); + var made = try context(gpa, "a.json", "{\"a\": 1}\n"); + defer made.deinit(gpa); + try std.testing.expectEqual(@as(usize, 0), made.symbols.len); +} -- cgit v1.3 From 60e85abe53debc0c8dd8986b748e9c86086e0007 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 02:44:20 -0300 Subject: body_layer, Places, Query, Output, Tables, File, Prompt, Pick, Core: the body draws every colour from the chrome (the themes programme's L2b; DESIGN.md R7-R12, B5, B6, G7), worked out once a theme change by Chrome.of and read by `p.chrome()`, never by a theme's own fields or the old views: ONE SELECTION FAMILY (R7): the primary range, a `gw` label and a target with no number on `page.selection` in its ink, a multi-cursor head that selection reversed; every other range, a hover, a look preview, `m a`/`m i`'s region, a selecting prompt's dimmed preview and a query pane's current row on `selection_secondary` (the page halfway toward the selection in OKLab) in the text's own ink, where they were four sRGB mixes (25 % and 50 % toward a page that was `dark`'s tag) and a secondary drew `sel_fg`; the B1, B2 and B3 sweeps the chrome's `sweeps` (select, exec on the error hue, look on the added hue; acme its own), the body's and the tags' alike, where body_layer.buttonTints tinted the selection toward the keyword, string and number; HITS (R8, G7 as the designer's position): every place, a picker's landing line, a query pane's and a results pane's match on `hit` in the text's ink (was the theme's search ink), the current place and a landing line's matched span solid in the hue with the page's ink (`hit_current`, `hit_current_text`), where Roles drew a third tone step (1.9:1) that 68 themes could not show and a query pane its search ground; a search whose field is no regex dims its last places, the current on `hit` and the rest on `hit_faint` (new: the page halfway toward the hit, R7's secondary for hits; DESIGN.md is silent); SEVERITIES (R9): a message's words and detail after its line (Messages.inkOn, new: an error, a warning and a question their severity's ink on that ground, an echo, a notice and progress its dim ink), a diagnostics list's labels, a rename's struck name and its new one, each `page.severity`, where they were the theme's raw diagnostic inks or Roles' pushed ones; DIFF GROUNDS (R10): a patch's rows, changed words and faint lines (File.recolorSyntax), a pipe prompt's and a code action's ghost rows, `add` and `del` with the page's text, where colors.Grounds mixed the page 18 %, 28 % and 7 % toward the palette's green and red once a frame; THE REST: line numbers `line_number` and the caret's `line_number_current` (R12: derived where a theme has none, it was the plain number), the wrap marker the line numbers', a tree's guides (a call stack's) and their wrap pads the page's dim ink (were the info ink: a guide is meta, B5's dim row), a location the line numbers' ink, keys, `▸` and the sam fence `page.key`, context rows, a table's header and a hover's ghost lines on the plain tag's ground (its ink for the hover), a table's rules the page's rule ink (were `border orelse lineno`), the rail and thumb the chrome's, the body's page and text `page` (a theme that leaves its page to the host leaves it its text, as before), syntax `syntax`; DELETED: Core.bodyChrome and its cache (`body_chrome`: a whole Theme compared with meta.eql for every decorated row and every wrap-pad cell, C1's A7), body_layer.buttonTints and buttonInks, the Grounds recipe (colors.Grounds is the library's view on the chrome now: lib_syntax exports it, test/consumer pins its relations), Roles.hit and hit_current with hitOf and their floors, ChromeTheme's search_fg, diagnostic_info, diagnostic_hint and lineno (nothing reads them now); every value is Chrome.of's, worked out at a theme change (finishThemeInitialization, setThemeIndex, previewTheme, loadThemeFile), never a frame, a row or a cell: the one new one, `hit_faint`, is one OKLab mix there; RUN (TEST FIRST): Places.zig "places: each on the hit ground in its text's own ink, the current one solid ... the selection over it; a search whose field is no regex dims them, the rest faint" (orchard: after `/alpha`, Enter and `j`, the current place `hit_current` in `hit_current_text`, the other `hit` in the page's text; searched again, its current under the selection; with `(` the others `hit_faint`): fails on the base at its current place (Roles' 1.9:1 step under the text's ink, where the hue in the page's ink is asked; its first version, asked during the live prompt, failed there on #3c614a: the body's selection is the current place then, drawn over it as before); Query.zig "a query pane's hits are the body's ..." (a `/alpha` query pane: the row's match `hit` in the text's ink, the owner's current place solid, the current row `selection_secondary` between its places and to its end, none below): fails on the base at Query.zig (expected #917a53, found #5e4923, the search ground); body_layer.zig "the body's selections are one family (R7) ..." (`eC` in orchard: the primary on `page.selection` in its ink, the other range on `selection_secondary` in the text's ink, its head reversed, a B2 sweep held over beta on `sweeps[1]`): fails on the base at body_layer.zig (expected #24382c, found #243a2d); body_layer.zig "the body's surfaces take every colour from the chrome: none reads a theme's own fields or the old views (DESIGN.md B6)" (the source test: body_layer, Places, Query, Output, Tables, File, Prompt, Pick, jj and ansi, their code before their tests: `theme()` read for its name alone, no chromeTheme(), bodyChrome, .roles, Grounds or LegacyTheme); re-pinned to the chrome and failing on the base: Prompt.zig's pipe ghosts (del.row #331a12, was Grounds' #302b25) and `/`'s `▸` (page.key #add38a, was Roles' #bada9d), Pick.zig's code action ghosts and its landing line, body_layer's motion targets, the build error's `✗` in `page.severity[0]`; colors.zig "line numbers stay quiet ..." (a ThemeFile with no current number: R12's derived one, 4.5:1), look.zig's hover preview on `selection_secondary`, test/output.zig and test/panes.zig's results colours (hit, page text, line numbers, the warning severity); GOLDENS re-recorded (13, orchard unless said), each class read: (1) R8 hit ink: a match on #5e4923 (orchard's own search ground, kept as its `hit`) in the text #e5eee5 where its search ink #f7e4a5 was: callstack 6 cells, psearch 15, stepgrain 26, lsprelpath 11; (2) G7 current hit: lsprelpath row 20, the owner's current place in a query row, #0d1410 on #917a53 (the hue held 4.5:1) where it was #f7e4a5 on #5e4923, 9 cells; (3) R7 secondary: #243a2d (sRGB half) to #24382c (OKLab half), the text's own ink where `sel_fg` #f5f7ee was: multicursor 2 cells and selregex 24 (secondary ranges), stepgrain 285 and lsprelpath 185 (a query pane's current row); (4) R10 diff grounds: diffview rows 12-19 (the diff pane's own rows: added #263025 to #132503, deleted #302b25 to #331a12, 558 cells; the same values the command pane's diff took in L2c), diffstack rows 26-29 (a faint added line #171f18 to #101c0b, changed words #364131 to #203900 and #453832 to #53251b), pagercolor rows 36-37 (a +Pager's faint lines: #1a1d18 to #211812, #171f18 to #101c0b); markers and syntax inks unchanged; (5) a tree's guides: callstack rows 11-21, #92d1de (the info ink) to #666f68 (the page's dim ink), 35 cells; (6) key ink: fsearch's `▸`, #bada9d (pushed over seven tag grounds) to #add38a (the accent held on the page); (7) R7 exec sweep: headersweep and headersweep-restored, a B2 sweep on the header, #f5f7ee on #5b7e5a (the selection tinted toward the string) to #e5eee5 on #4c251b (the error hue a selection step off the page), 8 and 16 cells (draw.zig's sweeps, moved with buttonTints); (8) R12: themesel row 26, the caret line's number in solarized_dark (#586e75 to #7f9193) and acme (#999980 to #74746a), themes with no current-line number of their own; no text moved, no other golden; GATES: core-test 1132/1305 (173 skipped; the merge's 1128/1301 + 4), shell-test 1353/1356 (3 skipped), pane-test 184/185 (1 skipped), behaviour-test 280/280 and --replay 20 seeds of 70 steps, 0 failures, process-test 0 of 147 failed (3 skipped; 13 re-recorded above, ttyhelp unmoved), term-test 17/17, kitty-test 45/45; gui unit-test 1957/1961 (4 skipped; its one failure the known BaselineHarnessMismatch; test/consumer's Grounds relations pass on the chrome's rows); PICTURES (the S kit, 26 px, 100x30, `Jumps walk`; before = install74's pardes-gui, after = this tree's Debug gui): .scratch/themes/L2b/png/, `--before|after.png` and `pair--.png` side by side, in dark, neonotte84, orchard and acme: `search` (a live `/words`: the current place is the body's selection, as before), `landed` (Enter, then `j`: the current place the solid chip), `selhit` (`x` over a hit), `grep` (SPC f g count: the preview's landing line and matched span), `error` (`:zig build`'s error words after report.zig's line 11: dark's were its grey text, red now), `diff` (a .diff file's rows); the dump and the digest unchanged (`body_chrome` was derived, `theme_chrome` local), so no fuzz or soak; load 3.2 to 9.7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/Core.zig | 14 +- core/File.zig | 21 ++- core/Messages.zig | 12 ++ core/Output.zig | 25 ++-- core/Pick.zig | 30 ++-- core/Places.zig | 59 ++++++-- core/Prompt.zig | 26 ++-- core/Query.zig | 62 ++++++-- core/Tables.zig | 8 +- core/body_layer.zig | 220 ++++++++++++++++++----------- core/colors.zig | 133 +++-------------- core/draw.zig | 9 +- core/look.zig | 3 +- core/root.zig | 4 +- test/output.zig | 24 ++-- test/panes.zig | 2 +- test/snapshots/callstack.golden | 24 ++-- test/snapshots/diffstack.golden | 6 +- test/snapshots/diffview.golden | 12 +- test/snapshots/fsearch.golden | 2 +- test/snapshots/headersweep-restored.golden | 4 +- test/snapshots/headersweep.golden | 2 +- test/snapshots/lsprelpath.golden | 8 +- test/snapshots/multicursor.golden | 4 +- test/snapshots/pagercolor.golden | 4 +- test/snapshots/psearch.golden | 6 +- test/snapshots/selregex.golden | 12 +- test/snapshots/stepgrain.golden | 8 +- test/snapshots/themesel.golden | 4 +- 29 files changed, 391 insertions(+), 357 deletions(-) (limited to 'core/File.zig') diff --git a/core/Core.zig b/core/Core.zig index cbcf4324..e458dab4 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -351,8 +351,6 @@ custom_theme: ?LegacyTheme = null, /// session's own theme untouched under it. theme_preview: ?u16 = null, preview_chrome: ChromeTheme = undefined, -/// bodyChrome's: the theme it was worked out for, and it. -body_chrome: ?struct { theme: LegacyTheme, chrome: ChromeTheme } = null, theme_file_path: config.Settings.Text(limits.host_path_cap) = .{}, /// The ThemeFile last loaded whole: what /ctl and DumpConfig name, and /// what a failed ThemeFile goes back to (colors.revertThemeFile). @@ -547,7 +545,7 @@ pub const replica = .{ "opts", "dump_out", "dump_export", "tape", }, - .derived = .{ "shell_rows", "diff_output", "locations_cache", "retired_panes", "tty_filter_palette", "body_chrome", "theme_preview", "preview_chrome" }, + .derived = .{ "shell_rows", "diff_output", "locations_cache", "retired_panes", "tty_filter_palette", "theme_preview", "preview_chrome" }, // The host's handles, the state file every session of the user // shares (and Recent read from it), this session's closed panes, and // the files of a host with no file system of its own. (The 9P @@ -2175,16 +2173,6 @@ pub fn chrome(p: *const Pardes) *const colors.Chrome { return &p.chromeTheme().resolved; } -/// The theme's own chrome, not a fade's (`theme()`'s, worked out once -/// per theme: its contrast searches take pow calls, too many for a -/// grapheme or a row). -pub fn bodyChrome(p: *Pardes) *const ChromeTheme { - const th = p.theme(); - if (p.body_chrome) |*cached| if (std.meta.eql(cached.theme, th.*)) return &cached.chrome; - p.body_chrome = .{ .theme = th.*, .chrome = ChromeTheme.fromTheme(th) }; - return &p.body_chrome.?.chrome; -} - /// When the core next needs a frame, on the `stepped_ns` timeline: a /// frame from now while work goes on (places to find, a picture /// decoding, a PDF page on a lane), the end of the wait while something diff --git a/core/File.zig b/core/File.zig index 332499b4..e246285c 100644 --- a/core/File.zig +++ b/core/File.zig @@ -2917,7 +2917,8 @@ pub const Layers = struct { pub const SynStyle = struct { fg: [3]u8, bold: bool }; pub fn synStyle(p: *Pardes, sy: syntax.Syn) ?SynStyle { - return .{ .fg = Colors.synInk(p.theme(), sy) orelse return null, .bold = false }; + if (sy == .none) return null; + return .{ .fg = p.chrome().syntax[@intFromEnum(sy)], .bold = false }; } /// syntax colors: recolor each content cell from its tree-sitter style byte; @@ -2940,8 +2941,8 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes. const tz_recolor = tracy.zone(@src(), "synRecolor"); defer tz_recolor.end(); // A row whose first byte names a hue (syntax.ground_add, _del): its - // grounds, the theme's, worked out once a frame and only for one. - var grounds: ?Colors.Grounds = null; + // grounds, the chrome's (R10). + const chrome = p.chrome(); const ink = ansi.inkOf(p); var filtered_storage: pardes.Term.Filter = undefined; const filtered: ?*pardes.Term.Filter = if (pane.tty_filter and spans.len > 0) blk: { @@ -2980,14 +2981,11 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes. const row_index: usize = @intCast(@max(0, pane.wrapAt(p.settings.tab, vr).line)); const metadata: ?locations.Row = if (row_index < f.location_rows.len) f.location_rows[row_index] else null; const decoration = Output.decorateRow(f.output, line, metadata); - const chrome: ?*const pardes.ChromeTheme = if (decoration.plain()) null else p.bodyChrome(); + const decorated = !decoration.plain(); // The row's first byte: its hue and its ground, on every wrapped // row of it (syntax.ground_add). const lead: u8 = if (base >= highlight_start and base - highlight_start < highlights.len) highlights[base - highlight_start] else 0; - const tint: ?Colors.Grounds.Ground = if (lead & (syntax.ground_add | syntax.ground_del) == 0) null else (grounds orelse ground: { - grounds = .of(p.theme()); - break :ground grounds.?; - }).forStyle(lead); + const tint: ?*const Colors.Chrome.Diff = if (lead & syntax.ground_add != 0) &chrome.add else if (lead & syntax.ground_del != 0) &chrome.del else null; // 2, the patch: the row's ground. if (tint) |t| if (prefix_width < tw) { const ground: ?[3]u8 = if (lead & syntax.ground_emph != 0) t.row else if (lead & syntax.ground_line != 0) t.line else null; @@ -3004,7 +3002,7 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes. var c: usize = 0; const pad: usize = if (vr < pane.wrap_n) pane.wrap_pad[vr] else 0; for (0..@min(pad, tw -| prefix_width)) |col| { - s.at(tx + @as(u16, @intCast(prefix_width + col)), body_y + vr).style.fg = .{ .rgb = p.bodyChrome().diagnostic_info }; + s.at(tx + @as(u16, @intCast(prefix_width + col)), body_y + vr).style.fg = .{ .rgb = chrome.page.dim }; } var screen_c: usize = pad; var table_buf: [Tables.max_pads]Tables.Pad = undefined; @@ -3052,7 +3050,7 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes. } // Results keep their exact live text. Only the location, // matched source range and diagnostic label gain emphasis. - if (if (chrome) |ch| decoration.styleAt(ch, hs + c) else null) |style| { + if (if (decorated) decoration.styleAt(chrome, hs + c) else null) |style| { var fill: usize = 0; while (fill < cells and prefix_width + screen_c + fill < tw) : (fill += 1) { const cell = s.at(tx + @as(u16, @intCast(prefix_width + screen_c + fill)), body_y + vr); @@ -3104,6 +3102,7 @@ pub fn paintWordSelection( word_lo: i32, word_hi: i32, bg: [3]u8, + fg: ?[3]u8, ) void { const tx = r.x + config.GUTTER; const tw = r.w - config.GUTTER; @@ -3122,7 +3121,7 @@ pub fn paintWordSelection( const c1 = @as(i32, prefix_width) + here.pad + displayEndOffset(p.settings.tab, pane, row, here.at, hi - 1); const col = @max(@as(i32, prefix_width), c0); const end = @min(c1 + 1, @as(i32, tw)); - if (col < end) s.tint(tx + @as(u16, @intCast(col)), body_y + @as(u16, @intCast(vr)), @intCast(end - col), bg, null); + if (col < end) s.tint(tx + @as(u16, @intCast(col)), body_y + @as(u16, @intCast(vr)), @intCast(end - col), bg, fg); } } diff --git a/core/Messages.zig b/core/Messages.zig index e05961b5..eca5ec9f 100644 --- a/core/Messages.zig +++ b/core/Messages.zig @@ -435,6 +435,18 @@ pub fn ink(chrome: *const pardes.colors.ChromeTheme, kind: Kind) [3]u8 { }; } +/// A message's ink on a ground of the chrome (R9): an error's, a warning's +/// and a question's their severity's held there (a question info's), an +/// echo, a notice and progress the ground's dim ink. +pub fn inkOn(inks: *const pardes.colors.Chrome.Inks, kind: Kind) [3]u8 { + return switch (kind) { + .@"error" => inks.severity[0], + .warn => inks.severity[1], + .question => inks.severity[2], + .echo, .notice, .progress => inks.dim, + }; +} + /// The places a compiler's report names put on `s`: each /// `path:line:col: error|warning|note: words` row (a relative path is /// `dir`'s), its words there, each place once, and the rows after the diff --git a/core/Output.zig b/core/Output.zig index fe1543fe..8807e55d 100644 --- a/core/Output.zig +++ b/core/Output.zig @@ -70,27 +70,20 @@ const RowDecoration = struct { return row.guide_end == 0 and !row.declaration and row.location_end == 0 and row.prefix_end == 0 and row.mark_end <= row.mark_start; } - /// `chrome` is the theme's own (Pardes.bodyChrome): body paper changes - /// immediately, so its ink must change with it even while the - /// surrounding tags are still fading. Once a frame, never a grapheme: - /// working it out takes the contrast searches' pow calls. - pub fn styleAt(row: RowDecoration, chrome: *const pardes.ChromeTheme, byte: usize) ?pardes.CellStyle { + /// On the page (`chrome`, Pardes.chrome): a tree's guides in the dim + /// ink, a location in the line numbers', the match a hit, a + /// diagnostic's label in its severity's ink (R8, R9). + pub fn styleAt(row: RowDecoration, chrome: *const pardes.colors.Chrome, byte: usize) ?pardes.CellStyle { if (row.plain()) return null; - if (byte < row.guide_end) return .{ .fg = .{ .rgb = chrome.diagnostic_info } }; + if (byte < row.guide_end) return .{ .fg = .{ .rgb = chrome.page.dim } }; if (row.declaration or byte < @max(row.location_end, row.prefix_end)) - return .{ .fg = .{ .rgb = chrome.lineno } }; + return .{ .fg = .{ .rgb = chrome.line_number } }; if (byte < row.mark_start or byte >= row.mark_end) return null; if (row.severity == .none) return .{ - .fg = .{ .rgb = chrome.search_fg }, - .bg = .{ .rgb = chrome.search_bg }, + .fg = .{ .rgb = chrome.page.text }, + .bg = .{ .rgb = chrome.hit }, }; - return .{ .fg = .{ .rgb = switch (row.severity) { - .err => chrome.diagnostic_error, - .warning => chrome.diagnostic_warning, - .info => chrome.diagnostic_info, - .hint => chrome.diagnostic_hint, - .none => unreachable, - } }, .bold = true }; + return .{ .fg = .{ .rgb = chrome.page.severity[@intFromEnum(row.severity) - 1] }, .bold = true }; } }; diff --git a/core/Pick.zig b/core/Pick.zig index 1d332f25..7c40a234 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -1176,8 +1176,8 @@ pub fn ghosts(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: if (rows <= first) return; const w: usize = s.cols; const old = try arena.dupe(Cell, s.cells[(y0 + first) * w .. (y0 + rows) * w]); - const grounds = colors.Grounds.of(p.theme()); - const ink = p.theme().fg orelse p.theme().tag_fg; + const chrome = p.chrome(); + const ink = chrome.page.text; const x0 = r.x + config.GUTTER + File.gutterWidth(pane); const width = r.w -| (x0 - r.x); var out: usize = first; @@ -1194,15 +1194,15 @@ pub fn ghosts(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: if (out >= rows) break; const y: u16 = @intCast(y0 + out); s.fill(0, y, @intCast(s.cols), 1, .{}); - s.fill(x0, y, width, 1, .{ .bg = .{ .rgb = grounds.add.row } }); - _ = s.print(x0, y, width, l, .{ .fg = .{ .rgb = ink }, .bg = .{ .rgb = grounds.add.row } }); + s.fill(x0, y, width, 1, .{ .bg = .{ .rgb = chrome.add.row } }); + _ = s.print(x0, y, width, l, .{ .fg = .{ .rgb = ink }, .bg = .{ .rgb = chrome.add.row } }); out += 1; }; } } if (out >= rows) break; @memcpy(s.cells[(y0 + out) * w ..][0..w], old[(vr - first) * w ..][0..w]); - if (g < groups.items.len and line >= groups.items[g].lo and line < groups.items[g].hi) s.tint(x0, @intCast(y0 + out), width, grounds.del.row, null); + if (g < groups.items.len and line >= groups.items[g].lo and line < groups.items[g].hi) s.tint(x0, @intCast(y0 + out), width, chrome.del.row, null); out += 1; } } @@ -2585,15 +2585,15 @@ test "code actions: a picker in the asking pane's tag, the one under the cursor const r = p.view().rects[id]; const x = r.x + config.GUTTER + File.gutterWidth(pane); const y = p.bodyTop(pane, r); - const grounds = colors.Grounds.of(p.theme()); + const chrome = p.chrome(); for ([_][]const u8{ "o", "t", "t", "t" }, [_][]const u8{ "n", "w", "w", "h" }, 0..) |c0, c1, row| { try std.testing.expectEqualStrings(c0, shot.at(x, y + @as(u16, @intCast(row))).grapheme()); try std.testing.expectEqualStrings(c1, shot.at(x + 1, y + @as(u16, @intCast(row))).grapheme()); } try std.testing.expectEqualStrings("a", shot.at(x + 4, y + 1).grapheme()); try std.testing.expectEqualStrings("s", shot.at(x + 4, y + 2).grapheme()); - try std.testing.expectEqual(pardes.Color{ .rgb = grounds.del.row }, shot.at(x, y + 1).style.bg); - try std.testing.expectEqual(pardes.Color{ .rgb = grounds.add.row }, shot.at(x, y + 2).style.bg); + try std.testing.expectEqual(pardes.Color{ .rgb = chrome.del.row }, shot.at(x, y + 1).style.bg); + try std.testing.expectEqual(pardes.Color{ .rgb = chrome.add.row }, shot.at(x, y + 2).style.bg); try std.testing.expectEqualStrings("one\ntwo add\nthree\n", pane.file.?.content); // An action lands nowhere: no landing line, no `▸` before the line it // changes, no sentence of where Enter lands (UX D7's are a jump's; an @@ -2610,10 +2610,10 @@ test "code actions: a picker in the asking pane's tag, the one under the cursor frame = std.heap.ArenaAllocator.init(std.testing.allocator); shot = try p.render(frame.allocator()); try std.testing.expectEqualStrings("/", shot.at(x, y).grapheme()); - try std.testing.expectEqual(pardes.Color{ .rgb = grounds.add.row }, shot.at(x, y).style.bg); + try std.testing.expectEqual(pardes.Color{ .rgb = chrome.add.row }, shot.at(x, y).style.bg); try std.testing.expectEqualStrings("o", shot.at(x, y + 1).grapheme()); - try std.testing.expect(!std.meta.eql(pardes.Color{ .rgb = grounds.del.row }, shot.at(x, y + 1).style.bg)); - try std.testing.expect(!std.meta.eql(pardes.Color{ .rgb = p.chromeTheme().roles.hit }, shot.at(x, y + 1).style.bg)); + try std.testing.expect(!std.meta.eql(pardes.Color{ .rgb = chrome.del.row }, shot.at(x, y + 1).style.bg)); + try std.testing.expect(!std.meta.eql(pardes.Color{ .rgb = p.chrome().hit }, shot.at(x, y + 1).style.bg)); // `3`: the rename applied, the tag at rest; one undo takes it back. p.update(.{ .key = .{ .cp = '3', .text = "3" } }); try std.testing.expectEqual(TagState.Kind.rest, s.kind); @@ -2720,16 +2720,16 @@ test "a picker's preview is legible as one (UX D7): its landing line on the hit }; try std.testing.expectEqual(@as(?u16, @intCast((pane.rows + 2) / 3)), at); const y = body_y + at.?; - const roles = &p.chromeTheme().roles; + const c = p.chrome(); const tx = r.x + pardes.config.GUTTER; const gutter = File.gutterWidth(pane); // Its text on the hit ground across the row; the row above as it was. - for (gutter..r.w - pardes.config.GUTTER) |x| try std.testing.expectEqual(pardes.Color{ .rgb = roles.hit }, s.at(tx + @as(u16, @intCast(x)), y).style.bg); - try std.testing.expect(!std.meta.eql(s.at(tx + gutter + 2, y - 1).style.bg, pardes.Color{ .rgb = roles.hit })); + for (gutter..r.w - pardes.config.GUTTER) |x| try std.testing.expectEqual(pardes.Color{ .rgb = c.hit }, s.at(tx + @as(u16, @intCast(x)), y).style.bg); + try std.testing.expect(!std.meta.eql(s.at(tx + gutter + 2, y - 1).style.bg, pardes.Color{ .rgb = c.hit })); // `▸` in the key ink in the gutter's cell after the number. const mark = s.at(tx + gutter - 1, y); try std.testing.expectEqualStrings("▸", mark.grapheme()); - try std.testing.expectEqual(pardes.Color{ .rgb = roles.key }, mark.style.fg); + try std.testing.expectEqual(pardes.Color{ .rgb = c.page.key }, mark.style.fg); // The notice row: where Enter lands, the owner's address a word in it. var buf: [pardes.Messages.notice_row_cap]u8 = undefined; const said = pardes.Messages.noticeRow(p, 120, &buf); diff --git a/core/Places.zig b/core/Places.zig index 8563d7c8..63f9ced6 100644 --- a/core/Places.zig +++ b/core/Places.zig @@ -659,19 +659,17 @@ pub fn origin(set: *const Places, pane: *Pane) usize { } /// Every place on the rows shown, tinted over the text: the hit ground, -/// the current one the current hit's (colors.Roles, UX D4, D14). +/// the current one solid in the hue with the page's ink (R8, UX D14); a +/// search prompt's pattern that is no regex, its last places dimmed: the +/// current on the hit ground, the rest faint. pub fn paint(set: *Places, p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, body_h: u16) void { if (!set.shows(pane)) return; const f = &pane.file.?; - const th = p.theme(); - const roles = &p.chromeTheme().roles; - var strong = roles.hit_current; - var quiet = roles.hit; - // A search prompt's pattern that is no regex: its last places, dimmed. - if (pardes.Prompt.dims(p, pane)) { - strong = quiet; - quiet = colors.mix(th.bg orelse th.tag_bg, quiet); - } + const c = p.chrome(); + const dim = pardes.Prompt.dims(p, pane); + const strong = if (dim) c.hit else c.hit_current; + const strong_ink: ?[3]u8 = if (dim) null else c.hit_current_text; + const quiet = if (dim) c.hit_faint else c.hit; const hits = set.hits.items; if (hits.len == 0) return; const nlines = File.nlines(p.gpa, f); @@ -697,7 +695,7 @@ pub fn paint(set: *Places, p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, const b = @min(hits[i].end, le) - ls; if (b <= a) continue; const current = set.current != null and set.current.? == i; - File.paintWordSelection(p, s, pane, r, line, @intCast(a), @intCast(b), if (current) strong else quiet); + File.paintWordSelection(p, s, pane, r, line, @intCast(a), @intCast(b), if (current) strong else quiet, if (current) strong_ink else null); } } } @@ -903,3 +901,42 @@ test "a session's places loaded from its dump find what an edit makes as the ses b.panes[b.view().active].?.file.?.mtime = a.panes[a.view().active].?.file.?.mtime; try std.testing.expectEqual(pardes.walk.digest(Pardes, a), pardes.walk.digest(Pardes, b)); } + +test "places: each on the hit ground in its text's own ink, the current one solid, the hue its ground and the page its ink (R8, G7), the selection over it; a search whose field is no regex dims them, the rest faint" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); + defer p.deinit(); + colors.setThemeIndex(p, colors.themeIndex("orchard").?); + const pane = try p.setTestFile("alpha beta\ngamma alpha\nb\nb\nb\nb\nb\nb\nb\nzeta alpha\n"); + // Landed on the first, the caret then moved off it: the places stay. + typeKeys(p, "/alpha"); + p.update(.{ .key = .{ .cp = pardes.Key.enter } }); + typeKeys(p, "j"); + try std.testing.expect(pane.places.shows(pane)); + try std.testing.expectEqual(@as(?usize, 0), pane.places.current); + const c = p.chrome(); + var frame: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer frame.deinit(); + const r = p.view().rects[0]; + const x = r.x + pardes.config.GUTTER + File.gutterWidth(pane); + const y = p.bodyTop(pane, r); + var s = try p.render(frame.allocator()); + for (0..5) |i| { + const current = s.at(x + @as(u16, @intCast(i)), y).style; + try std.testing.expectEqual(pardes.Color{ .rgb = c.hit_current }, current.bg); + try std.testing.expectEqual(pardes.Color{ .rgb = c.hit_current_text }, current.fg); + const other = s.at(x + 6 + @as(u16, @intCast(i)), y + 1).style; + try std.testing.expectEqual(pardes.Color{ .rgb = c.hit }, other.bg); + try std.testing.expectEqual(pardes.Color{ .rgb = c.page.text }, other.fg); + } + // Searched again from line 2: its place current and selected, the + // selection over the hit; then `(`, no regex: the others faint (line + // 10's: the prompt's words lie over the top rows). + typeKeys(p, "/alpha"); + try std.testing.expectEqual(@as(?usize, 1), pane.places.current); + s = try p.render(frame.allocator()); + for (0..4) |i| try std.testing.expectEqual(pardes.Color{ .rgb = c.page.selection.ground }, s.at(x + 6 + @as(u16, @intCast(i)), y + 1).style.bg); + typeKeys(p, "("); + try std.testing.expect(pardes.Prompt.dims(p, pane)); + s = try p.render(frame.allocator()); + for (5..10) |i| try std.testing.expectEqual(pardes.Color{ .rgb = c.hit_faint }, s.at(x + @as(u16, @intCast(i)), y + 9).style.bg); +} diff --git a/core/Prompt.zig b/core/Prompt.zig index b76b2d9a..49a9645d 100644 --- a/core/Prompt.zig +++ b/core/Prompt.zig @@ -874,7 +874,7 @@ pub fn paintGutter(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, body_h: const tab = p.settings.tab; const x = gutterX(pane, r); const y = p.bodyTop(pane, r); - const ink = p.chromeTheme().roles.key; + const ink = p.chrome().page.key; const nlines = File.nlines(p.gpa, f); // `▸` on the current place's line alone: the lines with places are the // rail's ticks (Places.addTicks), never glyphs of their own (UX D14). @@ -953,8 +953,8 @@ pub fn ghosts(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: if (rows <= first) return; const w: usize = s.cols; const old = try arena.dupe(Cell, s.cells[(y0 + first) * w .. (y0 + rows) * w]); - const grounds = colors.Grounds.of(p.theme()); - const ink = p.theme().fg orelse p.theme().tag_fg; + const chrome = p.chrome(); + const ink = chrome.page.text; const x0 = r.x + config.GUTTER + File.gutterWidth(pane); const width = r.w -| (x0 - r.x); const ranges = live_run.ranges[0..live_run.nranges]; @@ -969,18 +969,18 @@ pub fn ghosts(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: // `!`: its output before the selection's first line. var j = k; if (how == .insert and opens) while (j < ranges.len and lineAt(index, @min(ranges[j].anchor, ranges[j].head)) == line) : (j += 1) { - out = ghostRows(s, live_run, j, out, rows, y0, x0, width, grounds.add.row, ink); + out = ghostRows(s, live_run, j, out, rows, y0, x0, width, chrome.add.row, ink); }; if (out >= rows) break; @memcpy(s.cells[(y0 + out) * w ..][0..w], old[(vr - first) * w ..][0..w]); j = k; while (j < ranges.len and lineAt(index, @min(ranges[j].anchor, ranges[j].head)) <= line) : (j += 1) { - if (how == .replace and outcome(live_run, j) == 0) s.tint(x0, @intCast(y0 + out), width, grounds.del.row, null); + if (how == .replace and outcome(live_run, j) == 0) s.tint(x0, @intCast(y0 + out), width, chrome.del.row, null); } out += 1; // `|` and `A-!`: after the selection's last line. if (how != .insert and closes) while (k < ranges.len and lineAt(index, @max(ranges[k].anchor, ranges[k].head) -| 1) == line) : (k += 1) { - out = ghostRows(s, live_run, k, out, rows, y0, x0, width, grounds.add.row, ink); + out = ghostRows(s, live_run, k, out, rows, y0, x0, width, chrome.add.row, ink); }; } // What was pushed past the view leaves blank rows behind it, none. @@ -1027,7 +1027,7 @@ fn fence(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, body_h: u16) void if (snap.len == 0) return; const x = gutterX(pane, r); const y = p.bodyTop(pane, r); - const ink = p.chromeTheme().box; + const ink = p.chrome().page.key; const nlines = File.nlines(p.gpa, f); const op = p.view().tag_state.prompt.op; var kept: [Text.max_selections]modal.Selection = undefined; @@ -1500,12 +1500,12 @@ test "/ searches the body as it is typed: the current place selected, `▸` in t { const s = try p.render(frame.allocator()); const r = p.view().rects[0]; - const roles = &p.chromeTheme().roles; + const c = p.chrome(); const x = r.x + config.GUTTER + File.gutterWidth(pane); const y = p.bodyTop(pane, r); - try std.testing.expectEqual(pardes.Color{ .rgb = roles.key }, s.at(x - 1 - File.laneCells(pane) - pane.layers.heat, y + 2).style.fg); + try std.testing.expectEqual(pardes.Color{ .rgb = c.page.key }, s.at(x - 1 - File.laneCells(pane) - pane.layers.heat, y + 2).style.fg); // Line 1's place (`dirty` at its start) on the hit ground. - try std.testing.expectEqual(pardes.Color{ .rgb = roles.hit }, s.at(x, y).style.bg); + try std.testing.expectEqual(pardes.Color{ .rgb = c.hit }, s.at(x, y).style.bg); } p.update(.{ .key = .{ .cp = Key.enter } }); try std.testing.expectEqual(TagState.Kind.rest, p.view().tag_state.kind); @@ -1651,8 +1651,10 @@ test "a pipe prompt runs a known filter live, a run a selection: the outputs gho const x = r.x + config.GUTTER + File.gutterWidth(pane); const y = p.bodyTop(pane, r); for ([_][]const u8{ "b", "B", "a", "A", "c" }, 0..) |want, row| try std.testing.expectEqualStrings(want, s.at(x, y + @as(u16, @intCast(row))).grapheme()); - try std.testing.expectEqual(pardes.Color{ .rgb = colors.Grounds.of(p.theme()).del.row }, s.at(x, y).style.bg); - try std.testing.expectEqual(pardes.Color{ .rgb = colors.Grounds.of(p.theme()).add.row }, s.at(x, y + 1).style.bg); + // On the chrome's diff rows (R10), the ghost in the page's text. + try std.testing.expectEqual(pardes.Color{ .rgb = p.chrome().del.row }, s.at(x, y).style.bg); + try std.testing.expectEqual(pardes.Color{ .rgb = p.chrome().add.row }, s.at(x, y + 1).style.bg); + try std.testing.expectEqual(pardes.Color{ .rgb = p.chrome().page.text }, s.at(x, y + 1).style.fg); try std.testing.expectEqualStrings("b\na\nc\n", pane.file.?.content); // Enter: what the live run made, applied. p.update(.{ .key = .{ .cp = Key.enter } }); diff --git a/core/Query.zig b/core/Query.zig index 2b2abebb..f3673dd6 100644 --- a/core/Query.zig +++ b/core/Query.zig @@ -471,8 +471,8 @@ fn makeNameRows(p: *Pardes, id: usize) !void { var rows: std.ArrayList(locations.Row) = .empty; var spans: std.ArrayList(pardes.Term.Span) = .empty; errdefer spans.deinit(p.gpa); - const chrome = p.bodyChrome(); - const tint: pardes.CellStyle = .{ .fg = .{ .rgb = chrome.search_fg }, .bg = .{ .rgb = chrome.search_bg }, .bold = true }; + const chrome = p.chrome(); + const tint: pardes.CellStyle = .{ .fg = .{ .rgb = chrome.page.text }, .bg = .{ .rgb = chrome.hit }, .bold = true }; const shown = @min(q.names.hits.items.len, Names.max_rows); var marks: [Names.max_query * 4]u16 = undefined; const base = lineOne(rp.file.?.content).len + 1; @@ -510,7 +510,7 @@ fn makeNameRows(p: *Pardes, id: usize) !void { // A closed pane's row is dimmer, the gutter's colour, between its // marks (spans are walked in order, never overlapping). const dim = q.source == .panes and p.paneBySerial(cand.ref) == null; - const dimmed: pardes.CellStyle = .{ .fg = .{ .rgb = chrome.lineno } }; + const dimmed: pardes.CellStyle = .{ .fg = .{ .rgb = chrome.line_number } }; var gap: usize = 0; var k: usize = 0; while (k < nmarks) { @@ -2092,8 +2092,7 @@ pub fn tagPrefix(q: *const Query, arena: std.mem.Allocator, path: []const u8) er pub fn paintMark(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, body_h: u16) void { const q = pane.query orelse return; const c = q.current orelse return; - const th = p.theme(); - const mark = colors.mix(th.bg orelse th.tag_bg, th.sel_bg); + const mark = p.chrome().selection_secondary; const tx = r.x + config.GUTTER; const tw = r.w -| config.GUTTER; const col = File.gutterWidth(pane); @@ -2106,13 +2105,11 @@ pub fn paintMark(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, body_h: u /// The other places on a hit row's line tinted, from the pane its rows are /// in (the first is the row's own mark, Output.decorateRow): the current -/// one strongest, as in that pane's text. +/// one solid, as in that pane's text (Places.paint). pub fn paint(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, body_h: u16) void { const q = pane.query orelse return; const f = if (pane.file) |*file| file else return; - const th = p.theme(); - const strong = p.chromeTheme().search_bg; - const quiet = colors.mix(th.bg orelse th.tag_bg, strong); + const c = p.chrome(); var vr: i32 = 0; var last: i32 = -1; while (vr < body_h) : (vr += 1) { @@ -2144,7 +2141,7 @@ pub fn paint(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, body_h: u16) const b = @min(line.len, meta.code_start + (@min(h.end, next) - ls - meta.source_column)); if (b <= a or a >= line.len) continue; const current = set.current != null and set.current.? == hi; - File.paintWordSelection(p, s, pane, r, row, @intCast(a), @intCast(b), if (current) strong else quiet); + File.paintWordSelection(p, s, pane, r, row, @intCast(a), @intCast(b), if (current) c.hit_current else c.hit, if (current) c.hit_current_text else null); } } } @@ -2815,3 +2812,48 @@ test "Grep: a row whose numbers a Found cannot hold (a column past u32) is passe // Taken or passed over, each: never cast (main: Query.zig:1267). try std.testing.expect(q.found.items.len <= 3); } + +test "a query pane's hits are the body's: a row's match on the hit ground in the text's ink, the owner's current place solid in the hue with the page's ink, the current row marked with the selection's faint half" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }); + defer p.deinit(); + p.settings.jumps = .@"new-pane"; + colors.setThemeIndex(p, colors.themeIndex("orchard").?); + const pane = try p.setTestFile("alpha one alpha\nbeta\ngamma alpha\n"); + slash(p, "/alpha"); + const qid = queryPane(p).?; + const qp = p.panes[qid].?; + try std.testing.expectEqual(@as(?usize, 0), qp.query.?.current); + try std.testing.expectEqual(@as(?usize, 0), pane.places.current); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const s = try p.render(frame.allocator()); + const c = p.chrome(); + const r = p.view().rects[qid]; + // Row 1 (line 1 is the query) the first place's line, row 2 the third's. + var rows: [2][]const u8 = undefined; + for (&rows, 1..) |*row, k| { + var text: std.ArrayList(u8) = .empty; + for (0..r.w) |x| try text.appendSlice(frame.allocator(), s.at(r.x + @as(u16, @intCast(x)), p.bodyTop(qp, r) + @as(u16, @intCast(k))).grapheme()); + row.* = text.items; + } + const y = p.bodyTop(qp, r) + 1; + const first = std.mem.indexOf(u8, rows[0], "alpha").?; + const second = std.mem.lastIndexOf(u8, rows[0], "alpha").?; + const third = std.mem.indexOf(u8, rows[1], "alpha").?; + try std.testing.expect(second > first + 5); + for (0..5) |i| { + const current = s.at(r.x + @as(u16, @intCast(first + i)), y).style; + try std.testing.expectEqual(pardes.Color{ .rgb = c.hit_current }, current.bg); + try std.testing.expectEqual(pardes.Color{ .rgb = c.hit_current_text }, current.fg); + const other = s.at(r.x + @as(u16, @intCast(second + i)), y).style; + try std.testing.expectEqual(pardes.Color{ .rgb = c.hit }, other.bg); + try std.testing.expectEqual(pardes.Color{ .rgb = c.page.text }, other.fg); + const below = s.at(r.x + @as(u16, @intCast(third + i)), y + 1).style; + try std.testing.expectEqual(pardes.Color{ .rgb = c.hit }, below.bg); + try std.testing.expectEqual(pardes.Color{ .rgb = c.page.text }, below.fg); + } + // The current row's mark between its places and to its end; none below. + try std.testing.expectEqual(pardes.Color{ .rgb = c.selection_secondary }, s.at(r.x + @as(u16, @intCast(first + 6)), y).style.bg); + try std.testing.expectEqual(pardes.Color{ .rgb = c.selection_secondary }, s.at(r.x + r.w - 2, y).style.bg); + try std.testing.expectEqual(pardes.Color{ .rgb = c.page.ground }, s.at(r.x + r.w - 2, y + 1).style.bg); +} diff --git a/core/Tables.zig b/core/Tables.zig index a0256d8a..99e464ac 100644 --- a/core/Tables.zig +++ b/core/Tables.zig @@ -645,16 +645,16 @@ fn glyph(cell: *Cell, g: []const u8) void { /// A pane's table rows drawn as tables: every unescaped `|` a rule, the /// delimiter row one rule across (its dashes, its blanks and its pads, its /// `:` kept in the rule's colour, since they say the alignment), the header -/// row bold on the tag's ground, as compact context rows are. Only glyphs +/// row bold on the tag's ground, as compact context rows are, the rules in +/// the page's rule ink (R11). Only glyphs /// and colours change, on the cells the row has: where each byte is and how /// wide is fillBody's, so nothing is drawn over anything, B1 on a rule is /// B1 on its `|`, and a selection's tint lies over the rules as over text. pub fn paint(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, tx: u16, tw: u16, body_h: u16) void { const f = if (pane.file) |*file| file else return; if (f.tables.list.items.len == 0) return; - const th = p.theme(); - const rule_fg: Color = .{ .rgb = th.border orelse th.lineno }; - const head_bg: Color = .{ .rgb = th.tag_bg }; + const rule_fg: Color = .{ .rgb = p.chrome().page.rule }; + const head_bg: Color = .{ .rgb = p.chrome().tag[0].ground }; const prefix: usize = File.gutterWidth(pane); const body_y = p.bodyTop(pane, r); var vr: u16 = 0; diff --git a/core/body_layer.zig b/core/body_layer.zig index 513f9a6d..1eb3bf54 100644 --- a/core/body_layer.zig +++ b/core/body_layer.zig @@ -148,21 +148,12 @@ pub fn paintPointerSelection( } } -/// The selection colour of each pointer button's sweep: the select button's -/// and the look and exec buttons', each tinted toward its own accent. -pub fn buttonTints(th: *const colors.LegacyTheme) [3][3]u8 { - if (th.sweep_bg) |own| return own; - const accent2 = if (std.mem.eql(u8, &th.num, &th.str)) th.comment else th.num; - return .{ - colors.mix(th.sel_bg, colors.mix(th.sel_bg, th.kw)), - colors.mix(th.sel_bg, colors.mix(th.sel_bg, th.str)), - colors.mix(th.sel_bg, colors.mix(th.sel_bg, accent2)), - }; -} - -/// The ink over each button's sweep. -pub fn buttonInks(th: *const colors.LegacyTheme) [3][3]u8 { - return th.sweep_fg orelse @splat(th.sel_fg); +/// The rail's column in the theme's rail and thumb, and the column right +/// of it the page. +fn paintRail(c: *const colors.Chrome, s: *Surface, bar: pardes.Region) void { + s.fill(bar.rect.x, bar.rect.y, 1, bar.rect.h, .{ .bg = .{ .rgb = c.rail } }); + s.fill(bar.rect.x + 1, bar.rect.y, 1, bar.rect.h, .{ .bg = if (c.host_page) .default else .{ .rgb = c.page.ground } }); + s.fill(bar.rect.x, bar.rect.y + bar.thumb_y, 1, bar.thumb_h, .{ .bg = .{ .rgb = c.rail_thumb } }); } /// A pane's body, painted once. A file body with compact tree-sitter @@ -221,14 +212,7 @@ pub fn joinBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, if (layer.cursor) |cursor| if (cursor.y < viewport_rows) { s.cursor = .{ .x = body.rect.x + cursor.x, .y = body.rect.y + cursor.y, .bar = cursor.bar }; }; - const chrome = p.chromeTheme(); - const theme = p.theme(); - const pane_bg: Color = if (theme.bg) |c| .{ .rgb = c } else .default; - if (rail.rect.h > 0) { - s.fill(rail.rect.x, rail.rect.y, 1, rail.rect.h, .{ .bg = .{ .rgb = chrome.scroll_track } }); - s.fill(rail.rect.x + 1, rail.rect.y, 1, rail.rect.h, .{ .bg = pane_bg }); - s.fill(rail.rect.x, rail.rect.y + rail.thumb_y, 1, rail.thumb_h, .{ .bg = .{ .rgb = chrome.scroll_thumb } }); - } + if (rail.rect.h > 0) paintRail(p.chrome(), s, rail); } fn drawGutter(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, tx: u16, tw: u16, body_h: u16, active: bool) void { @@ -239,12 +223,13 @@ fn drawGutter(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, tx: u16, tw: const cur_line: i32 = if (active and typing_body) gcrow else std.math.minInt(i32); // the body's first row, the way renderPane derives it const body_y = p.bodyTop(pane, r); - const context_bg = p.theme().tag_bg; + const chrome = p.chrome(); + // The context rows on the tag's ground, as a header. for (0..@min(pane.context_rows, body_h)) |context_row| { for (0..tw) |col| { const cell = s.at(tx + @as(u16, @intCast(col)), body_y + @as(u16, @intCast(context_row))); cell.default = false; - cell.style.bg = .{ .rgb = context_bg }; + cell.style.bg = .{ .rgb = chrome.tag[0].ground }; cell.style.font_role = .tagline; } } @@ -259,10 +244,7 @@ fn drawGutter(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, tx: u16, tw: while (c < prefix_width and c < tw) : (c += 1) { const cell = s.at(tx + c, body_y + vr); cell.default = false; // paints blank gutter rows too - cell.style.fg = .{ .rgb = if (on_cursor) - p.theme().lineno_active orelse p.theme().lineno - else - p.theme().lineno }; + cell.style.fg = .{ .rgb = if (on_cursor) chrome.line_number_current else chrome.line_number }; cell.style.bold = on_cursor; } } @@ -280,7 +262,7 @@ fn drawWrapMarkers( ) void { if (tw <= panes.File.gutterWidth(pane) + 1) return; const body_y = p.bodyTop(pane, r); - const marker_fg = p.chromeTheme().lineno; + const marker_fg = p.chrome().line_number; var row: u16 = 0; while (row + 1 < pane.wrap_n and row + 1 < body_h) : (row += 1) { if (pane.wrap_line[row + 1] != pane.wrap_line[row] or pane.wrap_col[row] < 0) continue; @@ -292,21 +274,20 @@ fn drawWrapMarkers( } pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool, rail: ?pardes.Region) !void { - const th = p.theme(); - const chrome = p.chromeTheme(); + const c = p.chrome(); const tx = r.x + config.GUTTER; const tw = r.w - config.GUTTER; // Below the notice bands: they are stacked at the top of the body the // way tree-sitter context rows are, so the body starts under them // rather than being painted over by them. const body_y = p.bodyTop(pane, r); - const pane_bg: Color = if (th.bg) |c| .{ .rgb = c } else .default; - const page_rgb = th.bg orelse th.tag_bg; + // A theme that leaves its page to the host leaves it its text too. + const pane_bg: Color = if (c.host_page) .default else .{ .rgb = c.page.ground }; // body: emulator rows, prompt rows hidden outside tty mode const body_h = r.h -| pane.tag_rows; const body_bottom = r.h; const body_style: CellStyle = .{ - .fg = if (th.fg) |c| .{ .rgb = c } else .default, + .fg = if (c.host_page) .default else .{ .rgb = c.page.text }, .bg = pane_bg, }; const tz_body = tracy.zone(@src(), "bodyText"); @@ -319,7 +300,7 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane // the rows, which paint over it. const sweep = pane.sel[pardes.sel_slot]; if (sweep.state != .none and (sweep.state != .done or pardes.sel_slot == 0) and @min(sweep.r0, sweep.r1) < pane.tag_rows) - paintPointerSelection(p, s, pane, r, sweep, pane.tag_rows, th.sel_bg, th.sel_fg); + paintPointerSelection(p, s, pane, r, sweep, pane.tag_rows, c.sweeps[pardes.sel_slot].ground, c.sweeps[pardes.sel_slot].text); { // The rows themselves. `bodyText` above is only the string BUILD; // this is what writes it into the surface. @@ -363,16 +344,14 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane tz_color.end(); if (pane.isTerminal()) ansi.images(p, s, pane, id, tx, tw, body_y, body_h); - const sel_btn = buttonTints(th); if (p.look_hover_preview) |preview| { if (preview.pane == id and preview.serial == pane.serial) { // Preserve body ink, then let every real user selection below // win over this quiet affordance. - const preview_bg = colors.mix(page_rgb, colors.mix(page_rgb, th.sel_bg)); if (preview.file_word) |word| - panes.File.paintWordSelection(p, s, pane, r, word.row, word.lo, word.hi, preview_bg) + panes.File.paintWordSelection(p, s, pane, r, word.row, word.lo, word.hi, c.selection_secondary, null) else if (preview.sel) |sel| - paintPointerSelection(p, s, pane, r, sel, pane.tag_rows, preview_bg, null); + paintPointerSelection(p, s, pane, r, sel, pane.tag_rows, c.selection_secondary, null); } } const modal_hover = if (p.look_hover_preview) |preview| @@ -385,7 +364,7 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane // A select sweep over the tag is the tag's selection, painted there // in the tag's own selection colours. if (b == pardes.sel_slot and @min(sl.r0, sl.r1) < pane.tag_rows) continue; - paintPointerSelection(p, s, pane, r, sl, pane.tag_rows, sel_btn[b], buttonInks(th)[b]); + paintPointerSelection(p, s, pane, r, sl, pane.tag_rows, c.sweeps[b].ground, c.sweeps[b].text); } // A selecting prompt's live result (Prompt.zig), dimmed while its // field is no regex. @@ -408,12 +387,11 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane } else pane.body.sels[si]; const bnd = edit.cellBounds(sr); const hover_only = primary and modal_hover and pane.body.mode != .normal and !preview; - const bg = if (hover_only or (selecting != null and selecting.?.dim)) - colors.mix(page_rgb, colors.mix(page_rgb, th.sel_bg)) - else if (primary) - th.sel_bg - else - colors.mix(th.sel_bg, page_rgb); + // The primary on the selection in its ink; every other range, + // a hover and a dimmed preview on its faint half, the text's + // own ink kept (R7). + const full = primary and !hover_only and !(selecting != null and selecting.?.dim); + const bg = if (full) c.page.selection.ground else c.selection_secondary; var vr: i32 = 0; while (vr + @as(i32, pane.tag_rows) < @as(i32, body_bottom)) : (vr += 1) { const w = pane.wrapAt(p.settings.tab, vr); @@ -452,7 +430,7 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane @as(i32, tw) - 1; const col: i32 = @max(cstart, vpfx); const end = @min(cend + 1, tw); - if (col < end) s.tint(tx + @as(u16, @intCast(col)), body_y + @as(u16, @intCast(vr)), @intCast(end - col), bg, if (hover_only) null else th.sel_fg); + if (col < end) s.tint(tx + @as(u16, @intCast(col)), body_y + @as(u16, @intCast(vr)), @intCast(end - col), bg, if (full) c.page.selection.text else null); } if (primary and !preview and !hover_only) continue; // the hardware cursor IS the primary's if (hover_only) continue; // quiet preview preserves the source ink @@ -473,8 +451,8 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane if (crow >= pane.tag_rows and crow < @as(i32, body_bottom) and ccol >= vpfx and ccol < tw) { const cell = s.at(tx + @as(u16, @intCast(ccol)), body_y + @as(u16, @intCast(crow - pane.tag_rows))); cell.default = false; - cell.style.bg = .{ .rgb = th.sel_fg }; - cell.style.fg = .{ .rgb = th.sel_bg }; + cell.style.bg = .{ .rgb = c.page.selection.text }; + cell.style.fg = .{ .rgb = c.page.selection.ground }; } } } @@ -492,7 +470,7 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane if (pane.jump.items.len > 0) labels: { const flat = edit.flatSurface(p.editor(), &pane.body) catch break :labels; const letters = config.jump_label_alphabet; - const style: CellStyle = .{ .fg = .{ .rgb = th.sel_fg }, .bg = .{ .rgb = th.sel_bg }, .bold = true }; + const style: CellStyle = .{ .fg = .{ .rgb = c.page.selection.text }, .bg = .{ .rgb = c.page.selection.ground }, .bold = true }; for (pane.jump.items, 0..) |word, i| { if (pane.jump_first) |first| if (i / letters.len != first) continue; var at = @min(word.anchor, word.head); @@ -563,14 +541,10 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane if (pane.file != null) try pardes.Prompt.ghosts(p, s, arena, pane, r, body_h); // A code action's edit, previewed (Pick.zig). if (pane.file != null) try pardes.Pick.ghosts(p, s, arena, pane, r, body_h); - if (rail) |bar| if (bar.rect.h > 0) { - // The rail covers the notice bands too: nothing else paints those - // two gutter columns, so a gap there keeps the frame-wide border - // fill and reads as a notch cut out of the scrollbar. - s.fill(bar.rect.x, bar.rect.y, 1, bar.rect.h, .{ .bg = .{ .rgb = chrome.scroll_track } }); - s.fill(bar.rect.x + 1, bar.rect.y, 1, bar.rect.h, .{ .bg = pane_bg }); - s.fill(bar.rect.x, bar.rect.y + bar.thumb_y, 1, bar.thumb_h, .{ .bg = .{ .rgb = chrome.scroll_thumb } }); - }; + // The rail covers the notice bands too: nothing else paints those two + // gutter columns, so a gap there keeps the frame-wide border fill and + // reads as a notch cut out of the scrollbar. + if (rail) |bar| if (bar.rect.h > 0) paintRail(c, s, bar); } /// A message at the lines it names, drawn and never written (SPEC §10.2, @@ -585,9 +559,8 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane fn messageGhosts(p: *Pardes, s: *Surface, pane: *Pane, tx: u16, tw: u16, body_y: u16, body_h: u16) void { const Messages = pardes.Messages; const f = pane.file.?; - const chrome = p.chromeTheme(); - const th = p.theme(); - const pane_bg: Color = if (th.bg) |c| .{ .rgb = c } else .default; + const page = &p.chrome().page; + const pane_bg: Color = if (p.chrome().host_page) .default else .{ .rgb = page.ground }; const Hit = struct { line: usize, said: *const Messages.Said, place: *const Messages.Place }; var hits: [Messages.max_live * Messages.Said.max_places]Hit = undefined; var n: usize = 0; @@ -615,7 +588,7 @@ fn messageGhosts(p: *Pardes, s: *Surface, pane: *Pane, tx: u16, tw: u16, body_y: if (at < tw) { var buf: [160]u8 = undefined; const words = std.fmt.bufPrint(&buf, "{s} {s}", .{ hit.said.kind.glyph(), hit.place.text.slice() }) catch &buf; - _ = s.print(tx + @as(u16, @intCast(at)), body_y + row, @intCast(tw - at), words, .{ .fg = .{ .rgb = Messages.ink(chrome, hit.said.kind) }, .bg = pane_bg }); + _ = s.print(tx + @as(u16, @intCast(at)), body_y + row, @intCast(tw - at), words, .{ .fg = .{ .rgb = Messages.inkOn(page, hit.said.kind) }, .bg = pane_bg }); } if (pane.ghost_rows > 0 and row == pane.ghost_at) detail = hit.said; } @@ -634,7 +607,7 @@ fn messageGhosts(p: *Pardes, s: *Surface, pane: *Pane, tx: u16, tw: u16, body_y: for (said.detail[0..k], 0..) |*text, i| { const y = body_y + under_row + 1 + @as(u16, @intCast(i)); s.fill(tx, y, tw, 1, .{ .bg = pane_bg }); - if (gutter + 2 < tw) _ = s.print(tx + gutter + 2, y, tw - gutter - 2, text.slice(), .{ .fg = .{ .rgb = Messages.ink(chrome, said.kind) }, .bg = pane_bg }); + if (gutter + 2 < tw) _ = s.print(tx + gutter + 2, y, tw - gutter - 2, text.slice(), .{ .fg = .{ .rgb = Messages.inkOn(page, said.kind) }, .bg = pane_bg }); } } @@ -682,7 +655,7 @@ fn drawnRow(p: *Pardes, arena: std.mem.Allocator, id: usize, row: usize) !?[]con /// number (the one a prompt's current place has, Prompt.paintGutter), on /// each row it wraps onto. fn paintLanding(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, tx: u16, tw: u16, body_h: u16, line: usize) void { - const roles = &p.chromeTheme().roles; + const c = p.chrome(); const gutter = File.gutterWidth(pane); const number = gutter -| File.laneCells(pane) -| pane.layers.heat -| 1; const body_y = p.bodyTop(pane, r); @@ -693,18 +666,19 @@ fn paintLanding(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, tx: u16, tw: u16, for (gutter..tw) |x| { const cell = s.at(tx + @as(u16, @intCast(x)), body_y + vr); cell.default = false; - cell.style.bg = .{ .rgb = roles.hit }; + cell.style.bg = .{ .rgb = c.hit }; } if (gutter > 0 and w.at == 0) { var style = s.at(tx + number, body_y + vr).style; - style.fg = .{ .rgb = roles.key }; + style.fg = .{ .rgb = c.page.key }; s.set(tx + number, body_y + vr, "▸", style); } } } -/// The landing line's matched span (a Grep's match at the row's column) on -/// the current hit's ground, over the places lit on it (UX D7). +/// The landing line's matched span (a Grep's match at the row's column) as +/// the current hit, solid in the hue with the page's ink, over the places +/// lit on it (UX D7, R8). fn paintLandingSpan(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, f: *panes.File.State, line: usize) void { if (!pane.places.shows(pane)) return; const hits = pane.places.hits.items; @@ -713,7 +687,7 @@ fn paintLandingSpan(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, f: *panes.Fil var i = panes.Places.firstFrom(hits, ls); while (i < hits.len and hits[i].start <= caret) : (i += 1) { if (hits[i].end <= caret) continue; - File.paintWordSelection(p, s, pane, r, @intCast(line), @intCast(hits[i].start - ls), @intCast(hits[i].end - ls), p.chromeTheme().roles.hit_current); + File.paintWordSelection(p, s, pane, r, @intCast(line), @intCast(hits[i].start - ls), @intCast(hits[i].end - ls), p.chrome().hit_current, p.chrome().hit_current_text); return; } } @@ -768,9 +742,7 @@ fn paintTargets(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, .hi = if (line == last) to - lineStart(f, line) else File.sourceLine(pane, @intCast(line)).len, .to_edge = line != last, }; - const th = p.theme(); - const page = th.bg orelse th.tag_bg; - paintSourceSelection(p, s, pane, r, rows, colors.mix(page, colors.mix(page, th.sel_bg)), null); + paintSourceSelection(p, s, pane, r, rows, p.chrome().selection_secondary, null); return; } if (cur.root != .goto and cur.root != .next and cur.root != .prev) return; @@ -796,7 +768,7 @@ fn paintTargets(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, // row's keys, as many as they hold, right-aligned to its last digit, // bold in the key ink on the gutter's ground. With no numbers, over // the line's first cells on the selection's ground. Never a shift. - const ink = p.chromeTheme().roles.key; + const ink = p.chrome().page.key; const number = File.gutterWidth(pane) -| File.laneCells(pane) -| pane.layers.heat -| 1; const cells = @min(if (number > 0) number else tw, tw); for (rows[0..n], 0..) |row, i| { @@ -811,7 +783,7 @@ fn paintTargets(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, for (rows[i..n], keys[i..n]) |other, key| { if (other != row) continue; if (x >= (if (number > 0) cells else shown)) break; - const bg = if (number > 0) s.at(tx + x, y).style.bg else pardes.Color{ .rgb = p.theme().sel_bg }; + const bg = if (number > 0) s.at(tx + x, y).style.bg else pardes.Color{ .rgb = p.chrome().page.selection.ground }; s.set(tx + x, y, bindings.keyName(key), .{ .fg = .{ .rgb = ink }, .bg = bg, .bold = true }); x += 1; } @@ -844,13 +816,14 @@ fn hoverGhosts(p: *Pardes, s: *Surface, pane: *Pane, tx: u16, tw: u16, body_y: u const from = @as(usize, body_y + dst - k) * s.cols + tx; @memcpy(s.cells[to..][0..tw], s.cells[from..][0..tw]); } - const th = p.theme(); - const style: CellStyle = .{ .fg = .{ .rgb = th.tag_fg }, .bg = .{ .rgb = th.tag_bg } }; + // On the tag's ground in its ink, as a header. + const tag = &p.chrome().tag[0]; + const style: CellStyle = .{ .fg = .{ .rgb = tag.text }, .bg = .{ .rgb = tag.ground } }; const gutter: u16 = File.gutterWidth(pane); var lines = std.mem.splitScalar(u8, text, '\n'); for (0..k) |i| { const y = body_y + at + 1 + @as(u16, @intCast(i)); - s.fill(tx, y, tw, 1, .{ .bg = .{ .rgb = th.tag_bg } }); + s.fill(tx, y, tw, 1, .{ .bg = .{ .rgb = tag.ground } }); if (gutter + 2 < tw) _ = s.print(tx + gutter + 2, y, tw - gutter - 2, lines.next() orelse "", style); } } @@ -865,9 +838,8 @@ fn renameGhosts(p: *Pardes, s: *Surface, pane: *Pane, tx: u16, tw: u16, body_y: const old = @import("lsp/Ask.zig").renamedWord(pane) orelse return; const new = p.view().tag_state.field.text(); const tab = p.settings.tab; - const chrome = p.chromeTheme(); - const th = p.theme(); - const added: CellStyle = .{ .fg = .{ .rgb = chrome.diagnostic_hint }, .bg = if (th.bg) |c| .{ .rgb = c } else .default, .bold = true }; + const chrome = p.chrome(); + const added: CellStyle = .{ .fg = .{ .rgb = chrome.page.severity[3] }, .bg = if (chrome.host_page) .default else .{ .rgb = chrome.page.ground }, .bold = true }; const wide: u16 = @intCast(@min(File.displayWidth(tab, new), tw)); const gutter: i32 = File.gutterWidth(pane); var row: u16 = pane.context_rows; @@ -894,7 +866,7 @@ fn renameGhosts(p: *Pardes, s: *Surface, pane: *Pane, tx: u16, tw: u16, body_y: while (c < c1) : (c += 1) { const cell = s.at(tx + c, y); cell.style.strikethrough = true; - cell.style.fg = .{ .rgb = chrome.diagnostic_error }; + cell.style.fg = .{ .rgb = chrome.page.severity[0] }; } const x: u16 = @intCast(c1); if (x + wide < tw) { @@ -1193,6 +1165,12 @@ test "a build error is said where its cause is: the mark on its file's tag, its // elsewhere. try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 2, &buf), "three \u{2717} expected 2 argument(s), found 3") != null); try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 3, &buf), "four") != null); + // In the error's ink on the page (R9). + const mark = for (0..body.w) |i| { + const cell = s.at(body.x + @as(u16, @intCast(i)), body.y + 2); + if (std.mem.eql(u8, cell.grapheme(), "\u{2717}")) break cell; + } else return error.TestUnexpectedResult; + try std.testing.expectEqual(pardes.Color{ .rgb = p.chrome().page.severity[0] }, mark.style.fg); // The caret on line 3 and its detail asked for (K, UX D13): under the // line, the rows below two rows down. pane.body.cur_row = 2; @@ -1312,7 +1290,7 @@ test "a motion root's level paints its targets in place of their lines' numbers, try std.testing.expectEqualStrings("p", Field.of(s, gutter, body.y + 4, number, &buf)); const key = s.at(gutter + number - 1, body.y + 4); try std.testing.expectEqualStrings("p", key.grapheme()); - try std.testing.expectEqual(pardes.Color{ .rgb = p.chromeTheme().roles.key }, key.style.fg); + try std.testing.expectEqual(pardes.Color{ .rgb = p.chrome().page.key }, key.style.fg); try std.testing.expect(key.style.bold); try std.testing.expect(std.mem.indexOfScalar(u8, Field.of(s, gutter, body.y + 5, number, &buf), 'g') != null); try std.testing.expect(std.mem.indexOfAny(u8, Field.of(s, gutter, body.y + 5, number, &buf), "0123456789") == null); @@ -1417,3 +1395,79 @@ test "a message's detail unrolls only on request (UX D13): the caret passing its p.update(.{ .key = .{ .cp = 'K' } }); try std.testing.expectEqual(pardes.TagState.Kind.prompt, p.view().tag_state.kind); } + +test "the body's selections are one family (R7): the primary on the selection in its ink, another range on its faint half in the text's own ink, its head the selection reversed, a B2 sweep on the chrome's exec sweep" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 20 }); + defer p.deinit(); + colors.setThemeIndex(p, colors.themeIndex("orchard").?); + const pane = try p.setTestFile("alpha beta\ngamma delta\n"); + const id = p.view().active; + pane.focus = .body; + // `e` selects alpha, `C` copies it below: gamma the primary. + for ("eC") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row); + try std.testing.expect(pane.body.vsel.active and pane.body.nsel == 1); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const c = p.chrome(); + const r = p.view().rects[id]; + const x = r.x + config.GUTTER + panes.File.gutterWidth(pane); + const y = p.bodyTop(pane, r); + var s = try p.render(frame.allocator()); + for (0..5) |i| { + const primary = s.at(x + @as(u16, @intCast(i)), y + 1).style; + try std.testing.expectEqual(pardes.Color{ .rgb = c.page.selection.ground }, primary.bg); + if (i < 4) try std.testing.expectEqual(pardes.Color{ .rgb = c.page.selection.text }, primary.fg); + const other = s.at(x + @as(u16, @intCast(i)), y).style; + if (i < 4) { + try std.testing.expectEqual(pardes.Color{ .rgb = c.selection_secondary }, other.bg); + try std.testing.expectEqual(pardes.Color{ .rgb = c.page.text }, other.fg); + } else { + try std.testing.expectEqual(pardes.Color{ .rgb = c.page.selection.text }, other.bg); + try std.testing.expectEqual(pardes.Color{ .rgb = c.page.selection.ground }, other.fg); + } + } + // B2 swept over beta, not let go: the exec sweep. + p.update(.{ .mouse = .{ .button = .middle, .kind = .press, .col = x + 6, .row = y } }); + p.update(.{ .mouse = .{ .button = .middle, .kind = .drag, .col = x + 9, .row = y } }); + _ = frame.reset(.retain_capacity); + s = try p.render(frame.allocator()); + for (6..10) |i| { + const swept = s.at(x + @as(u16, @intCast(i)), y).style; + try std.testing.expectEqual(pardes.Color{ .rgb = c.sweeps[1].ground }, swept.bg); + try std.testing.expectEqual(pardes.Color{ .rgb = c.sweeps[1].text }, swept.fg); + } +} + +test "the body's surfaces take every colour from the chrome: none reads a theme's own fields or the old views (DESIGN.md B6)" { + const sources = [_]struct { []const u8, []const u8 }{ + .{ "body_layer.zig", @embedFile("body_layer.zig") }, + .{ "Places.zig", @embedFile("Places.zig") }, + .{ "Query.zig", @embedFile("Query.zig") }, + .{ "Output.zig", @embedFile("Output.zig") }, + .{ "Tables.zig", @embedFile("Tables.zig") }, + .{ "File.zig", @embedFile("File.zig") }, + .{ "Prompt.zig", @embedFile("Prompt.zig") }, + .{ "Pick.zig", @embedFile("Pick.zig") }, + .{ "jj.zig", @embedFile("jj.zig") }, + .{ "ansi.zig", @embedFile("ansi.zig") }, + }; + var wrong: usize = 0; + for (sources) |source| { + const name, const text = source; + // The code, not its tests. + const code = text[0 .. std.mem.indexOf(u8, text, "\ntest \"") orelse text.len]; + // A theme is read for its name alone. + var at: usize = 0; + while (std.mem.indexOfPos(u8, code, at, "theme()")) |i| : (at = i + 1) { + if (std.mem.startsWith(u8, code[i + "theme()".len ..], ".name")) continue; + std.debug.print("{s}: a theme's own colours read at byte {d}\n", .{ name, i }); + wrong += 1; + } + for ([_][]const u8{ "chromeTheme()", "bodyChrome", ".roles", "Grounds", "LegacyTheme" }) |old| if (std.mem.indexOf(u8, code, old)) |i| { + std.debug.print("{s}: `{s}` at byte {d}\n", .{ name, old, i }); + wrong += 1; + }; + } + try std.testing.expectEqual(@as(usize, 0), wrong); +} diff --git a/core/colors.zig b/core/colors.zig index 315d1fc9..44a2d415 100644 --- a/core/colors.zig +++ b/core/colors.zig @@ -553,10 +553,13 @@ pub const Chrome = struct { selection_secondary: [3]u8, /// The pointer buttons' sweeps: select, exec, look (acme's meanings). sweeps: [3]Theme.Sweep, - /// Search: a hit's ground, and the current one's ground and ink. + /// Search: a hit's ground, and the current one's ground and ink; a + /// search's last places while its field is no regex, dimmed: the page + /// halfway toward the hit (as `selection_secondary` is the selection's). hit: [3]u8, hit_current: [3]u8, hit_current_text: [3]u8, + hit_faint: [3]u8, add: Diff, del: Diff, /// The Changes layer's lanes, a pin each (`lanes_len` of them), and @@ -726,6 +729,7 @@ pub const Chrome = struct { // ink (vim's IncSearch): room for it in every theme. c.hit_current = hold(hue, &.{page}, text_floor); c.hit_current_text = page; + c.hit_faint = mixOklab(page, c.hit, 0.5); // Every ground's inks; on the tags and the status row, the // tag's selection rebuilt on each where it stands too near it. @@ -1061,31 +1065,17 @@ pub fn synInk(th: *const LegacyTheme, sy: @import("syntax.zig").Syn) ?[3]u8 { } /// The grounds a style byte's high bits name (syntax.ground_add and the -/// rest) in a theme: a row added or removed on a ground a little way from -/// the page toward the theme's green or red (its own ANSI ones where it has -/// a palette), a stronger one, a faint one, and the row's marker in that -/// hue, pushed toward the ink until it reads on the row's ground. Syntax -/// colours are drawn over a ground unchanged. +/// rest) in a theme, for the library: its chrome's added and deleted rows +/// (R10). Syntax colours are drawn over a ground unchanged. pub const Grounds = struct { add: Ground, del: Ground, - pub const Ground = struct { row: [3]u8, emph: [3]u8, line: [3]u8, ink: [3]u8 }; + pub const Ground = Chrome.Diff; pub fn of(th: *const LegacyTheme) Grounds { - const page = th.bg orelse th.tag_bg; - const ink = th.fg orelse th.tag_fg; - const green: [3]u8 = if (th.palette) |pal| pal[2] else .{ 0x2e, 0xa0, 0x43 }; - const red: [3]u8 = if (th.palette) |pal| pal[1] else .{ 0xcf, 0x22, 0x2e }; - return .{ .add = ground(page, ink, green), .del = ground(page, ink, red) }; - } - - fn ground(page: [3]u8, ink: [3]u8, hue: [3]u8) Ground { - const row = mixOklab(page, hue, 0.18); - var marker = hue; - var step: usize = 0; - while (step < 4 and contrast(marker, row) < 3) : (step += 1) marker = mixOklab(marker, ink, 0.4); - return .{ .row = row, .emph = mixOklab(page, hue, 0.28), .line = mixOklab(page, hue, 0.07), .ink = marker }; + const c = Chrome.of(&.fromLegacy(th.*)); + return .{ .add = c.add, .del = c.del }; } /// The ground of a byte's hue, if it has one. @@ -1294,17 +1284,13 @@ pub const ChromeTheme = struct { border: [3]u8, empty_col: [3]u8, search_bg: [3]u8, - search_fg: [3]u8, tag_reading_bg: [3]u8, diagnostic_error: [3]u8, diagnostic_warning: [3]u8, - diagnostic_info: [3]u8, - diagnostic_hint: [3]u8, box: [3]u8, box_dim: [3]u8, column_box: [3]u8, column_box_dim: [3]u8, - lineno: [3]u8, scroll_track: [3]u8, scroll_thumb: [3]u8, roles: Roles, @@ -1342,18 +1328,14 @@ pub const ChromeTheme = struct { .border = separatorOf(th), .empty_col = th.empty_col orelse separatorOf(th), .search_bg = th.search_bg orelse th.sel_bg, - .search_fg = th.search_fg orelse th.sel_fg, .tag_reading_bg = reading, // A theme's error ink, else its palette's red (UX E3). .diagnostic_error = th.diagnostic_error orelse if (th.palette) |pal| pal[1] else (th.fg orelse th.tag_fg), .diagnostic_warning = th.diagnostic_warning orelse (th.fg orelse th.tag_fg), - .diagnostic_info = th.diagnostic_info orelse (th.fg orelse th.tag_fg), - .diagnostic_hint = th.diagnostic_hint orelse (th.fg orelse th.tag_fg), .box = th.box, .box_dim = th.box_dim, .column_box = th.column_box orelse th.num, .column_box_dim = th.column_box_dim orelse mix(th.column_box orelse th.num, th.tag_bg), - .lineno = th.lineno, .scroll_track = th.scroll_track, .scroll_thumb = th.scroll_thumb, .roles = .of(th, th.tag_bg, active_bg, reading), @@ -1387,10 +1369,6 @@ pub const Roles = struct { /// The letters a query matched: an ink, never a ground, 4.5:1 on every /// tag ground and on the selection. match: [3]u8, - /// The body's places and a preview's landing line, and the current - /// one (its matched span): grounds off the page, its ink on them 4.5:1. - hit: [3]u8, - hit_current: [3]u8, /// A message's ink by its kind (Messages.ink): 4.5:1 on the tags and /// the page. err: [3]u8, @@ -1403,8 +1381,6 @@ pub const Roles = struct { pub const rule_floor: f32 = 1.8; pub const rule_ceiling: f32 = 2.5; pub const ink_floor: f32 = 4.5; - pub const hit_floor: f32 = 1.5; - pub const hit_current_floor: f32 = 1.9; pub const reading_distance: f32 = 0.04; pub fn on(r: *const Roles, ground: TagGround) *const RoleInks { @@ -1436,20 +1412,6 @@ pub const Roles = struct { r.key = pushAway(th.box, &tag_grounds, ink_floor); r.match = pushAway(matchHue(th), &tag_grounds, ink_floor); const page = th.bg orelse null_page; - const body_ink = th.fg orelse th.tag_fg; - const dark = relativeLuminance(page) < 0.18; - // The theme's search ground where it stands off the page and the - // body reads on it; else the page a little way toward its hue (the - // warm accent's without one). The current one as far past the hit - // as 32 % is past 18 % (38 past 22 on a light page). - const hue = th.search_bg orelse th.num; - const own = th.search_bg != null and contrast(hue, page) >= hit_floor and contrast(body_ink, hue) >= ink_floor; - const at: f32 = if (own) 1 else if (dark) 0.18 else 0.22; - r.hit = if (own) hue else hitOf(page, hue, body_ink, at, hit_floor); - const past: f32 = if (dark) 0.32 / 0.18 else 0.38 / 0.22; - r.hit_current = hitOf(page, hue, body_ink, at * past, hit_current_floor); - // Never fainter than the hit, where the ink holds both short. - if (contrast(r.hit_current, page) < contrast(r.hit, page)) r.hit_current = r.hit; const message_grounds = [_][3]u8{ plain, focused, reading, page }; const ink = th.fg orelse th.tag_fg; r.err = pushAway(th.diagnostic_error orelse if (th.palette) |pal| pal[1] else ink, &message_grounds, ink_floor); @@ -1552,48 +1514,6 @@ fn selectionOf(own: [3]u8, ground: [3]u8, text: [3]u8) [3]u8 { return best; } -/// A ground off `page` toward `hue` at `t` (past 1, beyond the hue, as far -/// as the gamut goes), held where the body's `ink` reads on it at 4.5:1 -/// (or its own on the page, where that is less); on toward the hue, the -/// least way that stands off the page at `floor`, where the ink still -/// reads on it; else moved on toward the ink until it stands off the page -/// at `floor`, as far as the ink allows. -fn hitOf(page: [3]u8, hue: [3]u8, ink: [3]u8, t: f32, floor: f32) [3]u8 { - const a = toOklab(page); - const b = toOklab(hue); - const ink_floor = @min(Roles.ink_floor, contrast(ink, page)); - var k = t; - var c = fromOklab(.{ a[0] + (b[0] - a[0]) * k, a[1] + (b[1] - a[1]) * k, a[2] + (b[2] - a[2]) * k }); - while (contrast(ink, c) < ink_floor and k > 0) { - k -= t / 50; - c = fromOklab(.{ a[0] + (b[0] - a[0]) * k, a[1] + (b[1] - a[1]) * k, a[2] + (b[2] - a[2]) * k }); - } - // Found by halves, seven mixes: the nearer the hue, the further off - // the page (UX E7 7b: a landing line 1.5:1, its span 1.9:1). - if (contrast(c, page) < floor and k < 1 and contrast(hue, page) >= floor) { - var lo = k; - var hi: f32 = 1; - var far = hue; - for (0..7) |_| { - const mid = (lo + hi) / 2; - const m = fromOklab(.{ a[0] + (b[0] - a[0]) * mid, a[1] + (b[1] - a[1]) * mid, a[2] + (b[2] - a[2]) * mid }); - if (contrast(m, page) < floor) lo = mid else { - hi = mid; - far = m; - } - } - if (contrast(ink, far) >= ink_floor) c = far; - } - const start = c; - var step: f32 = 1; - while (contrast(c, page) < floor and step <= 50) : (step += 1) { - const next = mixOklab(start, ink, step / 100); - if (contrast(ink, next) < ink_floor) break; - c = next; - } - return c; -} - /// A reading pane's tag (UX DESIGN.md D4): the theme's own where it stands /// off the tag, else the tag shifted toward paper yellow by 0.04 in OKLab /// and lighter by half that on a dark tag (darker on a light), so it reads @@ -1791,7 +1711,6 @@ pub fn loadThemeFile(p: *Pardes, generation: u32, bytes: []const u8) bool { theme.name = view.name; p.theme_chrome = .of(&theme, &view); - p.body_chrome = .{ .theme = view, .chrome = p.theme_chrome }; const old = p.custom_theme; p.custom_theme = view; if (old) |theme_value| p.gpa.free(theme_value.name); @@ -1828,13 +1747,10 @@ fn inOldNames(source: [:0]const u8) bool { } /// The session's theme's chrome, at its start (Pardes.init, a Restore): -/// never one the window previews (`previewTheme`); the body's copy of it -/// (Core.bodyChrome's, keyed by the theme) made with it, not again at the -/// first frame. +/// never one the window previews (`previewTheme`). pub fn finishThemeInitialization(p: *Pardes) void { const theme = if (p.custom_theme) |*custom| custom else &legacy_themes[p.settings.theme]; p.theme_chrome = if (p.custom_theme != null) .fromTheme(theme) else .of(&themes[p.settings.theme], theme); - p.body_chrome = .{ .theme = theme.*, .chrome = p.theme_chrome }; } /// Themes near `name`, a line of them, for a Theme given a name there is @@ -1915,7 +1831,6 @@ pub fn previewTheme(p: *Pardes, index: ?usize) void { if (p.theme_preview) |had| if (had == i) return; p.theme_preview = @intCast(i); p.preview_chrome = .of(&themes[i], &legacy_themes[i]); - p.body_chrome = .{ .theme = legacy_themes[i], .chrome = p.preview_chrome }; } pub fn setThemeIndex(p: *Pardes, index: usize) void { @@ -1923,7 +1838,6 @@ pub fn setThemeIndex(p: *Pardes, index: usize) void { (p.custom_theme == null and p.theme_file_path.get().len == 0 and index == @as(usize, p.settings.theme))) return; p.theme_chrome = .of(&themes[index], &legacy_themes[index]); - p.body_chrome = .{ .theme = legacy_themes[index], .chrome = p.theme_chrome }; if (p.custom_theme) |theme_value| { p.custom_theme = null; p.gpa.free(theme_value.name); @@ -2131,9 +2045,8 @@ test "native themes keep text and UI roles readable on their own surfaces" { const chrome = ChromeTheme.fromTheme(&th); const minimum: f32 = if (std.mem.eql(u8, name, "ink") or std.mem.eql(u8, name, "daybreak")) 7 else 4.5; const text_colors = [_][3]u8{ - th.fg.?, th.kw, th.str, th.num, th.comment, - chrome.diagnostic_error, chrome.diagnostic_warning, chrome.diagnostic_info, chrome.diagnostic_hint, - }; + th.fg.?, th.kw, th.str, th.num, th.comment, + } ++ chrome.resolved.page.severity; for (text_colors) |fg| try std.testing.expect(contrast(fg, th.bg.?) >= minimum); // Gutters are orientation aids, not source text: stay visible without // competing with comments or pulling attention away from the body. @@ -2153,7 +2066,7 @@ test "native themes keep text and UI roles readable on their own surfaces" { try std.testing.expect(contrast(chrome.tag_active_bg, th.tag_bg) <= 1.6); try std.testing.expect(contrast(chrome.tag_active_fg, th.tag_fg) <= 1.6); try std.testing.expect(contrast(th.sel_fg, th.sel_bg) >= minimum); - try std.testing.expect(contrast(chrome.search_fg, chrome.search_bg) >= minimum); + try std.testing.expect(contrast(chrome.resolved.hit_current_text, chrome.resolved.hit_current) >= Chrome.text_floor); // ANSI black can intentionally match the page (for backgrounds). All // other ANSI foregrounds, including bright black, remain legible. for (th.palette.?[1..]) |fg| try std.testing.expect(contrast(fg, th.bg.?) >= minimum); @@ -2219,6 +2132,7 @@ test "line numbers stay quiet without a current-line tag background" { custom.lineno = .{ 70, 70, 70 }; custom.lineno_active = .{ 95, 95, 95 }; p.custom_theme = custom; + finishThemeInitialization(p); p.sync(); const x = p.view().rects[0].x + config.GUTTER; const y = p.view().rects[0].y + BOX_H; @@ -2228,10 +2142,13 @@ test "line numbers stay quiet without a current-line tag background" { try std.testing.expectEqual(Color{ .rgb = custom.bg.? }, surface.at(x, y).style.bg); try std.testing.expect(surface.at(x, y).style.bold); try std.testing.expect(!surface.at(x, y + 1).style.bold); - // Old ThemeFile palettes need no new field, and do not regain the block. + // Old ThemeFile palettes need no new field: the current number is the + // text toward the page to 4.5:1 (R12), and the block not regained. p.custom_theme.?.lineno_active = null; + finishThemeInitialization(p); const fallback = try p.render(p.scratch.allocator()); - try std.testing.expectEqual(Color{ .rgb = .{ 70, 70, 70 } }, fallback.at(x, y).style.fg); + try std.testing.expectEqual(Color{ .rgb = p.chrome().line_number_current }, fallback.at(x, y).style.fg); + try std.testing.expect(contrast(p.chrome().line_number_current, custom.bg.?) >= Chrome.text_floor - 0.05); try std.testing.expectEqual(Color{ .rgb = custom.bg.? }, fallback.at(x, y).style.bg); try std.testing.expect(fallback.at(x, y).style.bold); // Moving the caret clears the previous cue; editing the tag parks it. @@ -2374,7 +2291,6 @@ test "every theme's walk UI roles meet their floors on every ground they are dra const chrome = ChromeTheme.fromTheme(th); const r = &chrome.roles; const page = th.bg orelse null_page; - const body_ink = th.fg orelse th.tag_fg; const tags = [_][3]u8{ r.tag[0].ground, r.tag[1].ground, r.tag[2].ground, r.selected[0].ground, r.selected[1].ground, r.selected[2].ground, r.selected[3].ground }; const messages = [_][3]u8{ r.tag[0].ground, r.tag[1].ground, r.tag[2].ground, page }; for (r.tag ++ r.selected ++ [1]RoleInks{r.notice}) |inks| { @@ -2401,15 +2317,6 @@ test "every theme's walk UI roles meet their floors on every ground they are dra try checks.append(a, .{ .what = "reading", .got = oklabDistance(toOklab(chrome.tag_reading_bg), toOklab(th.tag_bg)), .floor = Roles.reading_distance }); for ([_][3]u8{ th.tag_fg, th.tag_active_fg orelse th.tag_fg }) |ink| try checks.append(a, .{ .what = "text on reading", .got = contrast(ink, chrome.tag_reading_bg), .floor = @min(7, contrast(ink, th.tag_bg)) - 0.02 }); - const ink_floor = @min(Roles.ink_floor, contrast(body_ink, page)); - // A preview's landing line 1.5:1 off the page, its matched span (the - // current hit) a step stronger, 1.9:1 (UX E7 7b: 1.29 read as faint). - for ([_][3]u8{ r.hit, r.hit_current }, [_]f32{ 1.5, 1.9 }) |ground, floor| { - const on = contrast(body_ink, ground); - try checks.append(a, .{ .what = "hit", .got = contrast(ground, page), .floor = if (on < ink_floor + 0.3) 0 else floor }); - try checks.append(a, .{ .what = "ink on hit", .got = on, .floor = ink_floor - 0.01 }); - } - try checks.append(a, .{ .what = "current over hit", .got = contrast(r.hit_current, page) - contrast(r.hit, page), .floor = 0 }); for (checks.items) |c| if (c.got < c.floor - 0.005) { failed += 1; std.debug.print("{s}: {s} {d:.2} under {d:.2}\n", .{ th.name, c.what, c.got, c.floor }); diff --git a/core/draw.zig b/core/draw.zig index 7f178bfb..e90535b5 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -842,8 +842,8 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v var col = panes.File.rawDisplayCol(p.settings.tab, shown, @max(swept.lo, start) - start) -| scroll; const stop = panes.File.rawDisplayCol(p.settings.tab, shown, @min(swept.hi, end) - start) -| scroll; while (col < stop and col < columns) : (col += 1) { - surface.at(@intCast(col), 0).style.bg = .{ .rgb = body_layer.buttonTints(p.theme())[button] }; - surface.at(@intCast(col), 0).style.fg = .{ .rgb = body_layer.buttonInks(p.theme())[button] }; + surface.at(@intCast(col), 0).style.bg = .{ .rgb = p.chrome().sweeps[button].ground }; + surface.at(@intCast(col), 0).style.fg = .{ .rgb = p.chrome().sweeps[button].text }; } } } else |_| {}; @@ -1221,12 +1221,11 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, body_layer.paintPointerSelection(p, s, pane, r, sel, 0, preview_bg, null); }; } - const sel_btn = body_layer.buttonTints(th); - const sel_ink = body_layer.buttonInks(th); + const sweeps = &p.chrome().sweeps; for (pane.sel, 0..) |selection, button| { if (selection.state == .none or (selection.state == .done and button != 0)) continue; if (button == pardes.sel_slot or @min(selection.r0, selection.r1) >= rows) continue; - body_layer.paintPointerSelection(p, s, pane, r, selection, 0, sel_btn[button], sel_ink[button]); + body_layer.paintPointerSelection(p, s, pane, r, selection, 0, sweeps[button].ground, sweeps[button].text); } } diff --git a/core/look.zig b/core/look.zig index 41c59cf3..d9dfe0e1 100644 --- a/core/look.zig +++ b/core/look.zig @@ -2134,8 +2134,9 @@ test "Look hover waits without mutating the pane and input cancels it" { _ = frame.reset(.retain_capacity); const surface = try p.render(frame.allocator()); + // On the selection's faint half (R7); a tag's (below) is the tags' own. + try std.testing.expectEqual(Color{ .rgb = p.chrome().selection_secondary }, surface.at(word_x, body_y).style.bg); const expected_bg = colors.mix(p.theme().bg orelse p.theme().tag_bg, colors.mix(p.theme().bg orelse p.theme().tag_bg, p.theme().sel_bg)); - try std.testing.expectEqual(Color{ .rgb = expected_bg }, surface.at(word_x, body_y).style.bg); // Background traffic in another pane does not change the text or geometry // under this pointer and must not strand a stationary hover unarmed. diff --git a/core/root.zig b/core/root.zig index 11cb5058..e07cbed6 100644 --- a/core/root.zig +++ b/core/root.zig @@ -764,11 +764,11 @@ test "what core/ asks of the machine is where the list says, with why: a new lin /// state did not make it diverged a client: Pane.notices, then Tables' /// reading, 2026-11-19). A file, its names, the reason. const kept_out = [_]struct { []const u8, []const u8, []const u8 }{ - .{ "Core.zig", "surface facts frames own_frames theme_chrome frame_arena scratch echo undrawn", "the frame's own and the views drawn here: written by frames (and chrome by a theme's step), read by frames and the runner; no step reads them" }, + .{ "Core.zig", "surface facts frames own_frames theme_chrome frame_arena scratch echo undrawn", "the frame's own and the views drawn here: written by frames (and chrome by a theme's step), read by frames and the runner, and the chrome by a query's rows for colours only (out of their digest, locations.Row.digest); no step's outcome reads them" }, .{ "Core.zig", "needs_frame", "whether to draw: steps set it, the loop reads it; no step's outcome reads it" }, .{ "Core.zig", "effects effects_head effects_len in_q in_head in_len opts dump_out dump_export tape", "this process's queues, options and tape, drained or set by its host" }, .{ "Core.zig", "shell_rows", "a terminal's rows as read here, swept at every update; the terminal's own digest covers its active area, not its history (Term.zig `calls`)" }, - .{ "Core.zig", "diff_output locations_cache tty_filter_palette body_chrome", "caches of pure functions of their key (a text, a theme): a step finds what it would make; a query row's colours from them are out of its digest (locations.Row.digest), and what a step asks a worker to paint is never decided by them (Stream.paintRows)" }, + .{ "Core.zig", "diff_output locations_cache tty_filter_palette", "caches of pure functions of their key (a text, a theme): a step finds what it would make; a query row's colours from them are out of its digest (locations.Row.digest), and what a step asks a worker to paint is never decided by them (Stream.paintRows)" }, .{ "Core.zig", "retired_panes", "panes torn down this step, freed at its end" }, .{ "Core.zig", "theme_preview preview_chrome", "a themes picker's preview (colors.previewTheme): made from the live picker's cursor, in the digest with it, after every step (Pick.produceAll) and gone at its roll-up; a step reading a theme meanwhile reads the one its own state previews" }, .{ "Core.zig", "multi_first multi_stop multi_index multi_count exec_depth exec_column", "a step's own: set by a key's replay across the ranges (normal.replaySels) and a word's run (exec.zig), each put back before the step ends; between steps what `init` makes, so a load takes them as it makes them (a dump's said 2^30 ranges once: a yank sized its register by it)" }, diff --git a/test/output.zig b/test/output.zig index 77de7649..f2a35c01 100644 --- a/test/output.zig +++ b/test/output.zig @@ -41,7 +41,7 @@ test "search tint survives wrapping and theme changes while selections remain au const surface = try p.render(frame.allocator()); var marked: usize = 0; for (surface.cells) |cell| { - if (std.meta.eql(cell.style.bg, pardes.Color{ .rgb = p.theme().search_bg.? })) marked += 1; + if (std.meta.eql(cell.style.bg, pardes.Color{ .rgb = p.chrome().hit })) marked += 1; } try std.testing.expectEqual(@as(usize, 3), marked); _ = frame.reset(.retain_capacity); @@ -50,8 +50,8 @@ test "search tint survives wrapping and theme changes while selections remain au const light = try p.render(frame.allocator()); var light_matches: usize = 0; for (light.cells) |cell| { - if (!std.meta.eql(cell.style.bg, pardes.Color{ .rgb = p.theme().search_bg.? })) continue; - try std.testing.expectEqualDeep(pardes.Color{ .rgb = p.theme().search_fg.? }, cell.style.fg); + if (!std.meta.eql(cell.style.bg, pardes.Color{ .rgb = p.chrome().hit })) continue; + try std.testing.expectEqualDeep(pardes.Color{ .rgb = p.chrome().page.text }, cell.style.fg); light_matches += 1; } try std.testing.expectEqual(@as(usize, 3), light_matches); @@ -61,7 +61,7 @@ test "search tint survives wrapping and theme changes while selections remain au pane.body.vsel = .{ .active = true, .row = 0, .col = pane.body.cur_col - 2, .explicit = true }; const selected = try p.render(frame.allocator()); for (selected.cells) |cell| - try std.testing.expect(!std.meta.eql(cell.style.bg, pardes.Color{ .rgb = p.theme().search_bg.? })); + try std.testing.expect(!std.meta.eql(cell.style.bg, pardes.Color{ .rgb = p.chrome().hit })); try std.testing.expectEqualStrings(text, pane.file.?.content); } } @@ -128,15 +128,15 @@ test "location producers retain rendered location match and diagnostic styles" { 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()); - try std.testing.expectEqual(pardes.Color{ .rgb = chrome.lineno }, outputCell(p, surface, id, 0).style.fg); + const chrome = p.chrome(); + try std.testing.expectEqual(pardes.Color{ .rgb = chrome.line_number }, outputCell(p, surface, id, 0).style.fg); const start = file.location_rows[0].code_start; const first = outputCell(p, surface, id, start); if (diagnostic) { - try std.testing.expectEqual(pardes.Color{ .rgb = chrome.diagnostic_warning }, first.style.fg); + try std.testing.expectEqual(pardes.Color{ .rgb = chrome.page.severity[1] }, first.style.fg); try std.testing.expect(first.style.bold); } else if (origin == .search or origin == .cmd) { - try std.testing.expectEqual(pardes.Color{ .rgb = chrome.search_bg }, first.style.bg); + try std.testing.expectEqual(pardes.Color{ .rgb = chrome.hit }, first.style.bg); } if (!diagnostic) { const number = start + std.mem.indexOf(u8, code, "42").?; @@ -1145,10 +1145,10 @@ test "LSP occurrence tint follows the supplied source span through context" { 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()); + const chrome = p.chrome(); var marked: usize = 0; for (surface.cells) |cell| { - if (!std.meta.eql(cell.style.bg, pardes.Color{ .rgb = chrome.search_bg })) continue; + if (!std.meta.eql(cell.style.bg, pardes.Color{ .rgb = chrome.hit })) continue; try std.testing.expect(cell.text[0] == 'f' or cell.text[0] == 'o'); marked += 1; } @@ -1294,10 +1294,10 @@ test "stacked search and LSP results retain source tint navigation and dump owne var arena = std.heap.ArenaAllocator.init(p.gpa); defer arena.deinit(); const surface = try p.render(arena.allocator()); - const chrome = pardes.ChromeTheme.fromTheme(p.theme()); + const chrome = p.chrome(); var marked: usize = 0; for (surface.cells) |cell| { - if (!std.meta.eql(cell.style.bg, pardes.Color{ .rgb = chrome.search_bg })) continue; + if (!std.meta.eql(cell.style.bg, pardes.Color{ .rgb = chrome.hit })) continue; try std.testing.expect(cell.text[0] == 'f' or cell.text[0] == 'o'); marked += 1; } diff --git a/test/panes.zig b/test/panes.zig index 3acd5769..8f0a352c 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -2056,7 +2056,7 @@ const OutputTests = struct { const y = body_y + @as(u16, @intCast(index)); const cell = surface.at(x, y); try std.testing.expect(!cell.style.bold); - try std.testing.expectEqual(pardes.Color{ .rgb = pardes.ChromeTheme.fromTheme(p.theme()).lineno }, cell.style.fg); + try std.testing.expectEqual(pardes.Color{ .rgb = p.chrome().line_number }, cell.style.fg); } // Old dumps and edited outputs still identify both context prefixes. panes.File.setContent(p, file, try p.gpa.dupe(u8, "| old.zig:1 old\n new.zig:2 new\nmain.zig:42 ***\t\tmatch\n")); diff --git a/test/snapshots/callstack.golden b/test/snapshots/callstack.golden index d1140d0c..58e04798 100644 --- a/test/snapshots/callstack.golden +++ b/test/snapshots/callstack.golden @@ -51,18 +51,18 @@ |8: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-14 #c9a7ed,#0d1410, 15-109 #e5eee5,#0d1410, |9: 0-0 d,#152019, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-109 #e5eee5,#0d1410, |10: 0-1 d,#add38a, 2-32 #becfc4,#314738, 33-43 #dfbce5,#314738, 44-109 #becfc4,#314738, -|11: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-11 #92d1de,#0d1410, 12-109 #59675c,#0d1410, -|12: 0-0 d,#608269, 1-4 d,#0d1410, 5-9 #59675c,#0d1410, 10-11 #92d1de,#0d1410, 12-14 #c9a7ed,#0d1410, 15-109 #e5eee5,#0d1410, -|13: 0-0 d,#608269, 1-4 d,#0d1410, 5-9 #59675c,#0d1410, 10-12 #92d1de,#0d1410, 13-109 #59675c,#0d1410, -|14: 0-0 d,#608269, 1-4 d,#0d1410, 5-9 #59675c,#0d1410, 10-12 #92d1de,#0d1410, 13-16 #c9a7ed,#0d1410, 17-109 #e5eee5,#0d1410, -|15: 0-0 d,#608269, 1-4 d,#0d1410, 5-9 #59675c,#0d1410, 10-12 #92d1de,#0d1410, 13-109 #59675c,#0d1410, -|16: 0-0 d,#608269, 1-4 d,#0d1410, 5-9 #59675c,#0d1410, 10-12 #92d1de,#0d1410, 13-16 #c9a7ed,#0d1410, 17-109 #e5eee5,#0d1410, -|17: 0-0 d,#608269, 1-4 d,#0d1410, 5-9 #59675c,#0d1410, 10-14 #92d1de,#0d1410, 15-109 #59675c,#0d1410, -|18: 0-0 d,#608269, 1-4 d,#0d1410, 5-12 #59675c,#0d1410, 13-14 #92d1de,#0d1410, 15-17 #c9a7ed,#0d1410, 18-109 #e5eee5,#0d1410, -|19: 0-0 d,#608269, 1-4 d,#0d1410, 5-12 #59675c,#0d1410, 13-15 #92d1de,#0d1410, 16-109 #59675c,#0d1410, -|20: 0-0 d,#608269, 1-3 d,#0d1410, 4-12 #59675c,#0d1410, 13-15 #92d1de,#0d1410, 16-19 #c9a7ed,#0d1410, 20-23 #e5eee5,#0d1410, 24-26 #f7e4a5,#5e4923, 27-109 #e5eee5,#0d1410, -|21: 0-0 d,#608269, 1-3 d,#0d1410, 4-12 #59675c,#0d1410, 13-15 #92d1de,#0d1410, 16-109 #59675c,#0d1410, -|22: 0-0 d,#608269, 1-3 d,#0d1410, 4-15 #59675c,#0d1410, 16-19 #c9a7ed,#0d1410, 20-23 #e5eee5,#0d1410, 24-26 #f7e4a5,#5e4923, 27-109 #e5eee5,#0d1410, +|11: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-11 #666f68,#0d1410, 12-109 #59675c,#0d1410, +|12: 0-0 d,#608269, 1-4 d,#0d1410, 5-9 #59675c,#0d1410, 10-11 #666f68,#0d1410, 12-14 #c9a7ed,#0d1410, 15-109 #e5eee5,#0d1410, +|13: 0-0 d,#608269, 1-4 d,#0d1410, 5-9 #59675c,#0d1410, 10-12 #666f68,#0d1410, 13-109 #59675c,#0d1410, +|14: 0-0 d,#608269, 1-4 d,#0d1410, 5-9 #59675c,#0d1410, 10-12 #666f68,#0d1410, 13-16 #c9a7ed,#0d1410, 17-109 #e5eee5,#0d1410, +|15: 0-0 d,#608269, 1-4 d,#0d1410, 5-9 #59675c,#0d1410, 10-12 #666f68,#0d1410, 13-109 #59675c,#0d1410, +|16: 0-0 d,#608269, 1-4 d,#0d1410, 5-9 #59675c,#0d1410, 10-12 #666f68,#0d1410, 13-16 #c9a7ed,#0d1410, 17-109 #e5eee5,#0d1410, +|17: 0-0 d,#608269, 1-4 d,#0d1410, 5-9 #59675c,#0d1410, 10-14 #666f68,#0d1410, 15-109 #59675c,#0d1410, +|18: 0-0 d,#608269, 1-4 d,#0d1410, 5-12 #59675c,#0d1410, 13-14 #666f68,#0d1410, 15-17 #c9a7ed,#0d1410, 18-109 #e5eee5,#0d1410, +|19: 0-0 d,#608269, 1-4 d,#0d1410, 5-12 #59675c,#0d1410, 13-15 #666f68,#0d1410, 16-109 #59675c,#0d1410, +|20: 0-0 d,#608269, 1-3 d,#0d1410, 4-12 #59675c,#0d1410, 13-15 #666f68,#0d1410, 16-19 #c9a7ed,#0d1410, 20-23 #e5eee5,#0d1410, 24-26 #e5eee5,#5e4923, 27-109 #e5eee5,#0d1410, +|21: 0-0 d,#608269, 1-3 d,#0d1410, 4-12 #59675c,#0d1410, 13-15 #666f68,#0d1410, 16-109 #59675c,#0d1410, +|22: 0-0 d,#608269, 1-3 d,#0d1410, 4-15 #59675c,#0d1410, 16-19 #c9a7ed,#0d1410, 20-23 #e5eee5,#0d1410, 24-26 #e5eee5,#5e4923, 27-109 #e5eee5,#0d1410, |23: 0-0 d,#608269, 1-4 d,#0d1410, 5-109 #59675c,#0d1410, |24: 0-0 d,#608269, 1-109 d,#0d1410, |25: 0-0 d,#608269, 1-109 d,#0d1410, diff --git a/test/snapshots/diffstack.golden b/test/snapshots/diffstack.golden index 68c58062..1ffa87a4 100644 --- a/test/snapshots/diffstack.golden +++ b/test/snapshots/diffstack.golden @@ -57,8 +57,8 @@ |23: 0-0 d,#608269, 1-2 d,#0d1410, 3-99 #59675c,#0d1410, |24: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #59675c,#0d1410, |25: 0-0 d,#608269, 1-6 d,#0d1410, 7-9 #c9a7ed,#0d1410, 10-99 #e5eee5,#0d1410, -|26: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #f1a39b,#0d1410,b 3-10 #f1a39b,#0d1410, 11-11 #e5eee5,#453832, 12-99 #e5eee5,#0d1410, -|27: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #b6ce94,#0d1410,b 3-10 #b6ce94,#0d1410, 11-11 #e5eee5,#364131, 12-99 #e5eee5,#0d1410, +|26: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #f1a39b,#0d1410,b 3-10 #f1a39b,#0d1410, 11-11 #e5eee5,#53251b, 12-99 #e5eee5,#0d1410, +|27: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #b6ce94,#0d1410,b 3-10 #b6ce94,#0d1410, 11-11 #e5eee5,#203900, 12-99 #e5eee5,#0d1410, |28: 0-0 d,#152019, 1-10 d,#0d1410, 11-99 #e5eee5,#0d1410, -|29: 0-0 d,#152019, 1-1 d,#0d1410, 2-2 #b6ce94,#171f18,b 3-10 #b6ce94,#171f18, 11-99 #e5eee5,#171f18, +|29: 0-0 d,#152019, 1-1 d,#0d1410, 2-2 #b6ce94,#101c0b,b 3-10 #b6ce94,#101c0b, 11-99 #e5eee5,#101c0b, |30: 0-1 d,#1d2824, 2-99 #b2c3b8,#1d2824, diff --git a/test/snapshots/diffview.golden b/test/snapshots/diffview.golden index c441e19c..c0cc6194 100644 --- a/test/snapshots/diffview.golden +++ b/test/snapshots/diffview.golden @@ -43,14 +43,14 @@ |9: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, |10: 0-0 d,#608269, 1-4 d,#0d1410, 5-7 #59675c,#0d1410, 8-25 #e5eee5,#0d1410, 26-30 #c9a7ed,#0d1410, 31-31 #e5eee5,#0d1410, 32-35 #c9a7ed,#0d1410, 36-99 #e5eee5,#0d1410, |11: 0-0 d,#608269, 1-4 d,#0d1410, 5-11 #59675c,#0d1410, 12-99 #e5eee5,#0d1410, -|12: 0-0 d,#608269, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-7 #f1a39b,#302b25,b 8-11 #f1a39b,#302b25, 12-24 #e5eee5,#302b25, 25-25 #f8c082,#302b25, 26-99 #e5eee5,#302b25, -|13: 0-0 d,#608269, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-7 #b6ce94,#263025,b 8-11 #b6ce94,#263025, 12-99 #e5eee5,#263025, -|14: 0-0 d,#608269, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-7 #b6ce94,#263025,b 8-11 #b6ce94,#263025, 12-21 #e5eee5,#263025, 22-28 #c9a7ed,#263025, 29-99 #e5eee5,#263025, +|12: 0-0 d,#608269, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-7 #f1a39b,#331a12,b 8-11 #f1a39b,#331a12, 12-24 #e5eee5,#331a12, 25-25 #f8c082,#331a12, 26-99 #e5eee5,#331a12, +|13: 0-0 d,#608269, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-7 #b6ce94,#132503,b 8-11 #b6ce94,#132503, 12-99 #e5eee5,#132503, +|14: 0-0 d,#608269, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-7 #b6ce94,#132503,b 8-11 #b6ce94,#132503, 12-21 #e5eee5,#132503, 22-28 #c9a7ed,#132503, 29-99 #e5eee5,#132503, |15: 0-0 d,#608269, 1-3 d,#0d1410, 4-99 #59675c,#0d1410, |16: 0-0 d,#608269, 1-3 d,#0d1410, 4-11 #59675c,#0d1410, 12-99 #e5eee5,#0d1410, -|17: 0-0 d,#608269, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-7 #f1a39b,#302b25,b 8-15 #f1a39b,#302b25, 16-99 #b8d88a,#302b25, -|18: 0-0 d,#608269, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-7 #b6ce94,#263025,b 8-15 #b6ce94,#263025, 16-99 #b8d88a,#263025, -|19: 0-0 d,#608269, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-7 #b6ce94,#263025,b 8-15 #b6ce94,#263025, 16-99 #b8d88a,#263025, +|17: 0-0 d,#608269, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-7 #f1a39b,#331a12,b 8-15 #f1a39b,#331a12, 16-99 #b8d88a,#331a12, +|18: 0-0 d,#608269, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-7 #b6ce94,#132503,b 8-15 #b6ce94,#132503, 16-99 #b8d88a,#132503, +|19: 0-0 d,#608269, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-7 #b6ce94,#132503,b 8-15 #b6ce94,#132503, 16-99 #b8d88a,#132503, |20: 0-0 d,#608269, 1-3 d,#0d1410, 4-11 #59675c,#0d1410, 12-99 #e5eee5,#0d1410, |21: 0-0 d,#608269, 1-3 d,#0d1410, 4-7 #59675c,#0d1410, 8-99 #e5eee5,#0d1410, |22: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, diff --git a/test/snapshots/fsearch.golden b/test/snapshots/fsearch.golden index 6a70d3c4..e9b15f4c 100644 --- a/test/snapshots/fsearch.golden +++ b/test/snapshots/fsearch.golden @@ -54,7 +54,7 @@ |15: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, |16: 0-1 d,#496656, 2-30 #b2c3b8,#1d2824, 31-40 #d3b0d9,#1d2824, 41-89 #b2c3b8,#1d2824, 90-91 #000000,#add38a, 92-98 #becfc4,#2c2c0f, 99-99 #bada9d,#2c2c0f,b 100-100 #bada9d,#2c2c0f, 101-106 #becfc4,#2c2c0f, 107-113 #79836f,#2c2c0f, 114-126 #becfc4,#2c2c0f, 127-179 #79836f,#2c2c0f, |17: 0-0 d,#608269, 1-1 d,#0d1410, 2-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-94 #e5eee5,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, -|18: 0-0 d,#608269, 1-1 d,#0d1410, 2-89 #e5eee5,#0d1410, 90-90 #e5eee5,#e5eee5, 91-91 #e5eee5,#0d1410, 92-94 #e5eee5,#0d1410,b 95-95 #616f64,#0d1410,b 96-96 #bada9d,#0d1410,b 97-100 #f5f7ee,#3c614a, 101-101 #f5f7ee,#0d1410, 102-179 #e5eee5,#0d1410, +|18: 0-0 d,#608269, 1-1 d,#0d1410, 2-89 #e5eee5,#0d1410, 90-90 #e5eee5,#e5eee5, 91-91 #e5eee5,#0d1410, 92-94 #e5eee5,#0d1410,b 95-95 #616f64,#0d1410,b 96-96 #add38a,#0d1410,b 97-100 #f5f7ee,#3c614a, 101-101 #f5f7ee,#0d1410, 102-179 #e5eee5,#0d1410, |19: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-94 d,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, |20: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-94 d,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, |21: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-94 d,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, diff --git a/test/snapshots/headersweep-restored.golden b/test/snapshots/headersweep-restored.golden index 26a0c80b..6e0dff27 100644 --- a/test/snapshots/headersweep-restored.golden +++ b/test/snapshots/headersweep-restored.golden @@ -1,6 +1,6 @@ == style col-sweeping grid=120x21 |0: 0-1 d,#1d2824, 2-119 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-35 #becfc4,#314738, 36-43 #f5f7ee,#5b7e5a, 44-59 #becfc4,#314738, 60-61 #becfc4,#887455, 62-119 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-35 #becfc4,#314738, 36-43 #e5eee5,#4c251b, 44-59 #becfc4,#314738, 60-61 #becfc4,#887455, 62-119 #b2c3b8,#1d2824, |2: 0-1 d,#add38a, 2-43 #becfc4,#314738, 44-53 #dfbce5,#314738, 54-59 #becfc4,#314738, 60-61 #becfc4,#496656, 62-103 #b2c3b8,#1d2824, 104-113 #d3b0d9,#1d2824, 114-119 #b2c3b8,#1d2824, |3: 0-1 d,#314738, 2-59 #becfc4,#314738, 60-61 #becfc4,#1d2824, 62-119 #b2c3b8,#1d2824, |4: 0-0 d,#608269, 1-1 d,#0d1410, 2-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, @@ -43,7 +43,7 @@ | | ✓ @p1 Dump 1 message · SPC h m == style ws-sweeping grid=120x21 -|0: 0-1 d,#1d2824, 2-100 #b2c3b8,#1d2824, 101-108 #f5f7ee,#5b7e5a, 109-119 #b2c3b8,#1d2824, +|0: 0-1 d,#1d2824, 2-100 #b2c3b8,#1d2824, 101-108 #e5eee5,#4c251b, 109-119 #b2c3b8,#1d2824, |1: 0-1 d,#887455, 2-59 #becfc4,#314738, 60-61 #becfc4,#887455, 62-119 #b2c3b8,#1d2824, |13: 0-0 d,#608269, 1-59 d,#0d1410, 60-60 d,#608269, 61-119 d,#0d1410, |14: 0-0 d,#608269, 1-1 d,#0d1410, 2-59 #666f68,#0d1410, 60-60 #666f68,#608269, 61-119 #666f68,#0d1410, diff --git a/test/snapshots/headersweep.golden b/test/snapshots/headersweep.golden index 8763fbb2..49eda692 100644 --- a/test/snapshots/headersweep.golden +++ b/test/snapshots/headersweep.golden @@ -1,6 +1,6 @@ == style col-sweeping grid=120x21 |0: 0-1 d,#1d2824, 2-119 #b2c3b8,#1d2824, -|1: 0-1 d,#887455, 2-35 #becfc4,#314738, 36-43 #f5f7ee,#5b7e5a, 44-59 #becfc4,#314738, 60-61 #becfc4,#887455, 62-119 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-35 #becfc4,#314738, 36-43 #e5eee5,#4c251b, 44-59 #becfc4,#314738, 60-61 #becfc4,#887455, 62-119 #b2c3b8,#1d2824, |2: 0-1 d,#add38a, 2-34 #becfc4,#314738, 35-44 #dfbce5,#314738, 45-59 #becfc4,#314738, 60-61 #becfc4,#496656, 62-94 #b2c3b8,#1d2824, 95-104 #d3b0d9,#1d2824, 105-119 #b2c3b8,#1d2824, |3: 0-1 d,#314738, 2-59 #becfc4,#314738, 60-61 #becfc4,#1d2824, 62-119 #b2c3b8,#1d2824, |4: 0-0 d,#608269, 1-1 d,#0d1410, 2-59 #e5eee5,#0d1410, 60-60 #e5eee5,#608269, 61-119 #e5eee5,#0d1410, diff --git a/test/snapshots/lsprelpath.golden b/test/snapshots/lsprelpath.golden index bd2dc172..48fbfbd1 100644 --- a/test/snapshots/lsprelpath.golden +++ b/test/snapshots/lsprelpath.golden @@ -62,9 +62,9 @@ |15: 0-1 d,#496656, 2-99 #b2c3b8,#1d2824, |16: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, |17: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, -|18: 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, +|18: 0-0 d,#608269, 1-1 d,#0d1410, 2-21 #59675c,#24382c, 22-31 #e5eee5,#24382c, 32-36 #e5eee5,#5e4923, 37-39 #e5eee5,#24382c, 40-44 #c9a7ed,#24382c, 45-99 #e5eee5,#24382c, |19: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, -|20: 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, +|20: 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 #0d1410,#917a53, 46-99 #e5eee5,#0d1410, |21: 0-0 d,#608269, 1-99 d,#0d1410, |22: 0-0 d,#608269, 1-99 d,#0d1410, |23: 0-0 d,#608269, 1-99 d,#0d1410, @@ -144,9 +144,9 @@ |15: 0-1 d,#496656, 2-99 #b2c3b8,#1d2824, |16: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, |17: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, -|18: 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, +|18: 0-0 d,#608269, 1-1 d,#0d1410, 2-23 #59675c,#24382c, 24-33 #e5eee5,#24382c, 34-37 #e5eee5,#5e4923, 38-40 #e5eee5,#24382c, 41-45 #c9a7ed,#24382c, 46-99 #e5eee5,#24382c, |19: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, -|20: 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, +|20: 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 #0d1410,#917a53, 43-99 #e5eee5,#0d1410, |21: 0-0 d,#608269, 1-99 d,#0d1410, |22: 0-0 d,#608269, 1-99 d,#0d1410, |23: 0-0 d,#608269, 1-99 d,#0d1410, diff --git a/test/snapshots/multicursor.golden b/test/snapshots/multicursor.golden index 267fba5e..9c992e04 100644 --- a/test/snapshots/multicursor.golden +++ b/test/snapshots/multicursor.golden @@ -80,8 +80,8 @@ == snap three-selections grid=150x31 cursor=83,19 == style three-selections grid=150x31 |16: 0-1 d,#496656, 2-34 #b2c3b8,#1d2824, 35-44 #d3b0d9,#1d2824, 45-74 #b2c3b8,#1d2824, 75-75 #b2c3b8,#add38a, 76-76 #000000,#f9cb70,b 77-109 #becfc4,#314738, 110-115 #dfbce5,#314738, 116-149 #becfc4,#314738, -|17: 0-0 d,#608269, 1-1 d,#0d1410, 2-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-79 #e5eee5,#0d1410, 80-81 #59675c,#0d1410, 82-82 #f5f7ee,#243a2d, 83-83 #3c614a,#f5f7ee, 84-149 #e5eee5,#0d1410, -|18: 0-0 d,#608269, 1-1 d,#0d1410, 2-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-79 #e5eee5,#0d1410, 80-81 #59675c,#0d1410, 82-82 #f5f7ee,#243a2d, 83-83 #3c614a,#f5f7ee, 84-149 #e5eee5,#0d1410, +|17: 0-0 d,#608269, 1-1 d,#0d1410, 2-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-79 #e5eee5,#0d1410, 80-81 #59675c,#0d1410, 82-82 #e5eee5,#24382c, 83-83 #3c614a,#f5f7ee, 84-149 #e5eee5,#0d1410, +|18: 0-0 d,#608269, 1-1 d,#0d1410, 2-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-79 #e5eee5,#0d1410, 80-81 #59675c,#0d1410, 82-82 #e5eee5,#24382c, 83-83 #3c614a,#f5f7ee, 84-149 #e5eee5,#0d1410, |19: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-76 d,#0d1410, 77-79 d,#0d1410,b 80-81 #616f64,#0d1410,b 82-83 #f5f7ee,#3c614a, 84-149 #e5eee5,#0d1410, |20: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-79 d,#0d1410, 80-81 #59675c,#0d1410, 82-149 #e5eee5,#0d1410, |26: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-78 d,#0d1410, 79-81 #59675c,#0d1410, 82-149 #e5eee5,#0d1410, diff --git a/test/snapshots/pagercolor.golden b/test/snapshots/pagercolor.golden index beaaf7f5..f665b6bf 100644 --- a/test/snapshots/pagercolor.golden +++ b/test/snapshots/pagercolor.golden @@ -121,8 +121,8 @@ |33: 0-1 d,#496656, 2-33 #b2c3b8,#1d2824, 34-47 #d3b0d9,#1d2824, 48-99 #b2c3b8,#1d2824, |34: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, |35: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #59675c,#0d1410, -|36: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #f1a39b,#1a1d18,b 3-99 #f8c082,#1a1d18, -|37: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #b6ce94,#171f18,b 3-99 #b8d88a,#171f18, +|36: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #f1a39b,#211812,b 3-99 #f8c082,#211812, +|37: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #b6ce94,#101c0b,b 3-99 #b8d88a,#101c0b, |41: 0-0 d,#608269, 1-99 d,#0d1410, |42: 0-0 d,#608269, 1-99 d,#0d1410, |45: 0-1 d,#496656, 2-33 #b2c3b8,#1d2824, 34-40 #d3b0d9,#1d2824, 41-99 #b2c3b8,#1d2824, diff --git a/test/snapshots/psearch.golden b/test/snapshots/psearch.golden index 9f7eab39..fca566b4 100644 --- a/test/snapshots/psearch.golden +++ b/test/snapshots/psearch.golden @@ -66,11 +66,11 @@ |20: 0-0 d,#608269, 1-139 d,#0d1410, |21: 0-1 d,#496656, 2-30 #b2c3b8,#1d2824, 31-38 #d3b0d9,#1d2824, 39-139 #b2c3b8,#1d2824, |22: 0-0 d,#608269, 1-4 d,#0d1410, 5-139 #59675c,#0d1410, -|23: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-8 #e5eee5,#0d1410, 9-12 #f7e4a5,#5e4923, 13-13 #f7e4a5,#0d1410, 14-139 #e5eee5,#0d1410, +|23: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-8 #e5eee5,#0d1410, 9-12 #e5eee5,#5e4923, 13-139 #e5eee5,#0d1410, |24: 0-0 d,#608269, 1-4 d,#0d1410, 5-139 #59675c,#0d1410, -|25: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-8 #e5eee5,#0d1410, 9-12 #f7e4a5,#5e4923, 13-13 #f7e4a5,#0d1410, 14-139 #e5eee5,#0d1410, +|25: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-8 #e5eee5,#0d1410, 9-12 #e5eee5,#5e4923, 13-139 #e5eee5,#0d1410, |26: 0-0 d,#608269, 1-4 d,#0d1410, 5-139 #59675c,#0d1410, -|27: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-8 #e5eee5,#0d1410, 9-12 #f7e4a5,#5e4923, 13-13 #f7e4a5,#0d1410, 14-139 #e5eee5,#0d1410, +|27: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-8 #e5eee5,#0d1410, 9-12 #e5eee5,#5e4923, 13-139 #e5eee5,#0d1410, |28: 0-0 d,#608269, 1-4 d,#0d1410, 5-139 #59675c,#0d1410, |29: 0-0 d,#608269, 1-139 d,#0d1410, |30: 0-1 d,#1d2824, 2-139 #b2c3b8,#1d2824, diff --git a/test/snapshots/selregex.golden b/test/snapshots/selregex.golden index fa7ec980..621018b7 100644 --- a/test/snapshots/selregex.golden +++ b/test/snapshots/selregex.golden @@ -32,8 +32,8 @@ |1: 0-1 d,#887455, 2-159 #becfc4,#314738, |2: 0-1 #000000,#add38a, 2-2 #bada9d,#2c2c0f,b 3-3 #bada9d,#2c2c0f, 4-10 #becfc4,#2c2c0f, 11-17 #79836f,#2c2c0f, 18-115 #becfc4,#2c2c0f, 116-159 #79836f,#2c2c0f, |3: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-5 #616f64,#0d1410,b 6-6 #add38a,#0d1410,b 7-10 #f5f7ee,#3c614a, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-159 #e5eee5,#0d1410, -|4: 0-0 d,#608269, 1-4 d,#0d1410, 5-5 #59675c,#0d1410, 6-6 #add38a,#0d1410, 7-10 #f5f7ee,#243a2d, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-159 #e5eee5,#0d1410, -|5: 0-0 d,#608269, 1-4 d,#0d1410, 5-5 #59675c,#0d1410, 6-6 #add38a,#0d1410, 7-10 #f5f7ee,#243a2d, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-20 #e5eee5,#0d1410, 21-21 #f8c082,#0d1410, 22-159 #e5eee5,#0d1410, +|4: 0-0 d,#608269, 1-4 d,#0d1410, 5-5 #59675c,#0d1410, 6-6 #add38a,#0d1410, 7-10 #e5eee5,#24382c, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-159 #e5eee5,#0d1410, +|5: 0-0 d,#608269, 1-4 d,#0d1410, 5-5 #59675c,#0d1410, 6-6 #add38a,#0d1410, 7-10 #e5eee5,#24382c, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-20 #e5eee5,#0d1410, 21-21 #f8c082,#0d1410, 22-159 #e5eee5,#0d1410, |6: 0-0 d,#608269, 1-4 d,#0d1410, 5-159 #59675c,#0d1410, |7: 0-0 d,#608269, 1-159 d,#0d1410, |8: 0-0 d,#608269, 1-159 d,#0d1410, @@ -61,8 +61,8 @@ == style three-selected grid=160x25 |2: 0-1 d,#add38a, 2-47 #becfc4,#2c2c0f, 48-53 #dfbce5,#2c2c0f, 54-159 #becfc4,#2c2c0f, |3: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-11 #f5f7ee,#3c614a, 12-12 #f5f7ee,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-159 #e5eee5,#0d1410, -|4: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f5f7ee,#243a2d, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-159 #e5eee5,#0d1410, -|5: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f5f7ee,#243a2d, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-20 #e5eee5,#0d1410, 21-21 #f8c082,#0d1410, 22-159 #e5eee5,#0d1410, +|4: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #e5eee5,#24382c, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-159 #e5eee5,#0d1410, +|5: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #e5eee5,#24382c, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-20 #e5eee5,#0d1410, 21-21 #f8c082,#0d1410, 22-159 #e5eee5,#0d1410, == snap narrowed grid=160x25 cursor=21,2 |2: ^ Edit x/const/ › s t = Exec Edit x/t/ 3 selections in 3 lines ⏎ select · M-⏎ as a list · C-r history · esc |3: 1┃const one = 1; @@ -81,8 +81,8 @@ == style esc-restores grid=160x25 |2: 0-1 d,#add38a, 2-47 #becfc4,#2c2c0f, 48-53 #dfbce5,#2c2c0f, 54-159 #becfc4,#2c2c0f, |3: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-11 #f5f7ee,#3c614a, 12-12 #f5f7ee,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-159 #e5eee5,#0d1410, -|4: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f5f7ee,#243a2d, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-159 #e5eee5,#0d1410, -|5: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f5f7ee,#243a2d, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-20 #e5eee5,#0d1410, 21-21 #f8c082,#0d1410, 22-159 #e5eee5,#0d1410, +|4: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #e5eee5,#24382c, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-159 #e5eee5,#0d1410, +|5: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #e5eee5,#24382c, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-20 #e5eee5,#0d1410, 21-21 #f8c082,#0d1410, 22-159 #e5eee5,#0d1410, == snap commented grid=160x25 cursor=14,3 |2: *Edit x/const/ › /tmp/pardes-snap/selregex/cwd/m.zig Save Term Collapse Follow TreeContext Def Refs Del |3: 1 // const one = 1; diff --git a/test/snapshots/stepgrain.golden b/test/snapshots/stepgrain.golden index 5f73bd1f..e24b19a8 100644 --- a/test/snapshots/stepgrain.golden +++ b/test/snapshots/stepgrain.golden @@ -47,10 +47,10 @@ |11: 0-1 #000000,#add38a, 2-149 #becfc4,#314738, |12: 0-0 d,#608269, 1-1 d,#0d1410, 2-149 #e5eee5,#0d1410, |13: 0-0 d,#608269, 1-1 d,#0d1410, 2-149 #e5eee5,#0d1410, -|14: 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, -|15: 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, +|14: 0-0 d,#608269, 1-1 d,#0d1410, 2-14 #59675c,#0d1410, 15-20 #e5eee5,#0d1410, 21-26 #e5eee5,#5e4923, 27-149 #e5eee5,#0d1410, +|15: 0-0 d,#608269, 1-1 d,#0d1410, 2-14 #59675c,#24382c, 15-37 #e5eee5,#24382c, 38-43 #e5eee5,#5e4923, 44-149 #e5eee5,#24382c, |16: 0-0 d,#608269, 1-1 d,#0d1410, 2-149 #e5eee5,#0d1410, -|17: 0-0 d,#608269, 1-1 d,#0d1410, 2-18 #59675c,#0d1410, 19-24 #f7e4a5,#5e4923, 25-25 #f7e4a5,#0d1410, 26-149 #e5eee5,#0d1410, +|17: 0-0 d,#608269, 1-1 d,#0d1410, 2-18 #59675c,#0d1410, 19-24 #e5eee5,#5e4923, 25-149 #e5eee5,#0d1410, |18: 0-0 d,#608269, 1-149 d,#0d1410, |19: 0-0 d,#608269, 1-149 d,#0d1410, |20: 0-0 d,#608269, 1-149 d,#0d1410, @@ -85,7 +85,7 @@ |3: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, |4: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, |7: 0-0 d,#608269, 1-149 d,#0d1410, -|13: 0-0 d,#608269, 1-1 d,#0d1410, 2-5 #e5eee5,#243a2d, 6-10 #f7e4a5,#5e4923,b 11-149 #e5eee5,#243a2d, +|13: 0-0 d,#608269, 1-1 d,#0d1410, 2-5 #e5eee5,#24382c, 6-10 #e5eee5,#5e4923,b 11-149 #e5eee5,#24382c, |14: 0-0 d,#608269, 1-149 d,#0d1410, |15: 0-0 d,#608269, 1-149 d,#0d1410, |16: 0-0 d,#608269, 1-149 d,#0d1410, diff --git a/test/snapshots/themesel.golden b/test/snapshots/themesel.golden index b975c35b..e13e0618 100644 --- a/test/snapshots/themesel.golden +++ b/test/snapshots/themesel.golden @@ -574,7 +574,7 @@ |23: 0-0 d,#99994c, 1-3 d,#ffffea, 4-6 #999980,#ffffea, 7-99 #000000,#ffffea, |24: 0-0 d,#99994c, 1-3 d,#ffffea, 4-6 #999980,#ffffea, 7-99 #000000,#ffffea, |25: 0-0 d,#99994c, 1-3 d,#ffffea, 4-6 #999980,#ffffea, 7-99 #000000,#ffffea, -|26: 0-0 d,#99994c, 1-1 d,#ffffea, 2-3 d,#ffffea,b 4-6 #999980,#ffffea,b 7-99 #000000,#ffffea, +|26: 0-0 d,#99994c, 1-1 d,#ffffea, 2-3 d,#ffffea,b 4-6 #74746a,#ffffea,b 7-99 #000000,#ffffea, |27: 0-0 d,#99994c, 1-3 d,#ffffea, 4-6 #999980,#ffffea, 7-99 #000000,#ffffea, |28: 0-0 d,#99994c, 1-3 d,#ffffea, 4-99 #999980,#ffffea, |29: 0-0 d,#99994c, 1-3 d,#ffffea, 4-6 #999980,#ffffea, 7-99 #000000,#ffffea, @@ -715,7 +715,7 @@ |23: 0-0 d,#eee8d5, 1-3 d,#002b36, 4-6 #586e75,#002b36, 7-99 #839496,#002b36, |24: 0-0 d,#eee8d5, 1-3 d,#002b36, 4-99 #586e75,#002b36, |25: 0-0 d,#eee8d5, 1-3 d,#002b36, 4-6 #586e75,#002b36, 7-99 #839496,#002b36, -|26: 0-0 d,#eee8d5, 1-1 d,#002b36, 2-3 d,#002b36,b 4-6 #586e75,#002b36,b 7-99 #839496,#002b36, +|26: 0-0 d,#eee8d5, 1-1 d,#002b36, 2-3 d,#002b36,b 4-6 #7f9193,#002b36,b 7-99 #839496,#002b36, |27: 0-0 d,#eee8d5, 1-3 d,#002b36, 4-6 #586e75,#002b36, 7-99 #839496,#002b36, |28: 0-0 d,#eee8d5, 1-3 d,#002b36, 4-99 #586e75,#002b36, |29: 0-0 d,#eee8d5, 1-3 d,#002b36, 4-6 #586e75,#002b36, 7-99 #839496,#002b36, -- cgit v1.3 From 02b64ff90ae2f82fb83a604f6d4ded3459a84620 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 04:54:39 -0300 Subject: Lsp, lsp_client, File, dump: a file of a language a server speaks, opened in a pane (a Look, a landing, a walk step, the boot's file, a restored session's), starts that server and tells it of the file on a worker of its own, so the file's first question finds it ready (agent V4's find for the comparison video, VIDEO2/STORY.md §4.1 and §10.2: pardes's first `gd` cost about 2.5 s where Helix's, LazyVim's and Doom's cost 0.05 s; the user was asked, the default yes); THE CAUSE: dev/lsp/lsp_client.zig spawned a server on the first query that needed it (its header's lifecycle), and that query paid the spawn, the handshake and the server's first parse of the file; THE FIX: an effect `lsp_open`, emitted beside the file's watch by File.open (look.open, Trail's step, the boot document) and dump.revivePane (a restored or upgraded session), performed through a Host entry `lsp_open` (tui, gui and macOS: Inbox.openLsp; not held for `threads_ok`: the boot's file and a restored session's are opened before the loop's threads start); dev/Lsp.zig `open` asks nothing for a file no spec speaks for (lsp.speaks, on the loop), else copies the pane's file (`snapshot`) and hands it to a worker of its own (`Opener`, one at a time: a file opened while one is under way is let go and told at its first query, syncDoc; one done is awaited, at once, before the next), which calls lsp_client.open: a spec disabled asks nothing, a binary not found disables the spec without a word (its first query says `language server for .py not found`, not every file opened), else `ensure` (the server started as a query starts it, `starting` and `ready` narrated as before, one per spec) and `syncDoc` (didOpen); nothing in the query log; not through Lsp.start (its cancel and join of the query in flight waits out a protected handshake, up to init_ms = 8 s, on the loop) nor `work` (the queries' one fixed region, memory.takeLspQuery); a picker's preview (Pick.preview, no pane) and a 9P `ctl get` (ninep/ctl.zig getFile, no File.open) start none; Lspinfo says `not started yet (a file of its opened starts it)`; docs/typ/setup.typ and reference.typ say when a server starts; THE HARNESSES (the coordinator's ruling: no test starts a server of this machine's): PARDES_LSP_OPEN=off starts none and is the process harnesses' default (test/process.zig's child environment, test/tty.zig, and test/fs.py, selfmount.py and daemon.py's base_env), so the `lsp` tty cases' zls is started by their first query as before; a test binary (builtin.is_test) starts none unless it says `on`, as the behaviour harness's language sessions do (Session.initLanguage, every spec the mock or off, `.lsp_open` drained as a host performs it, awaited); RUN (TEST FIRST): behaviour/language_servers.zig "a file of a server's language opened in a pane starts that server and tells it of the file, with no query asked; a picker's preview of one starts none, a second file no second server, and a server not installed is found silently" previews a.zig in Find's picker (Lspinfo: zls `not started yet`), opens it (zls `ready`, `docs 1`, the query count unchanged), opens b.zig (`docs 2`: the same server), and opens c.py and d.py with PARDES_LSP_PY naming no binary (pyright `disabled`, no query, nothing on the screen): fails on the base at language_servers.zig:367 (zls not started by the open), passes now; lsp_client.zig "a file opened whose server is not installed disables it without a word ..." opens two .py files with a status sink set: the spec disabled, no word posted, a query then `not found`; MEASURED (.scratch/walkui/T23/measure-v8.sh: VIDEO's probe.py, the screen polled every 50 ms, this change's Debug tui, a reflink copy of VIDEO2's V8 tree with clangd and its 27-file compile database, torque-parser.cc opened, `743ggfI` then `gd` 4 s after the start, until utils.h's `bool IsUpperCamelCase` shows): with PARDES_LSP_OPEN=off (the base's way) 1.97, 1.98, 1.97 s; started at the open 0.05, 0.05, 0.05 s; on VIDEO's tally with zls (measure.sh) both ways 0.05-0.10 s (zls starts and answers within one poll there); a user hit it on the first question of every file of a session's languages, about 2 s with clangd over a real project; NEW HOT PATHS: none per key or frame; per file opened, one effect more and on the loop lsp.speaks (the spec table's extensions); for a file a spec speaks for, a copy of its text (the snapshot a query makes) and a worker started; GATES: core-test 1130/1304 (174 skipped: +1), shell-test 1352/1355 (3 skipped: +1), pane-test 183/184, behaviour-test 286/286 (+1) and --replay 20 seeds of 70 steps, 0 failures, process-test 0 of 147 failed (3 skipped), term-test 17/17, kitty-test 45/45; the wire's semantics move (a Host entry, tape.shape); no dump change (effects are local, not dumped); the soak `replicas -- --clients 5 --rtt 30,80,207` dies on the base too (5dab435d7262, run here: `allocator leaks detected` at seed 0 rtt 80, MuPDF's allocations of documents a picker previewed, Pick.showKind), so run without the pdf addon (its binary, `--addon` image and life): diverged 0, unequal 0, quiet checks 468/0 251/0 657/0, stops not on may_wait 0, the corpus 22 of 22 scenes the same, no leak (a first run had one key stop at `spawn` at seed 3 rtt 80, exec.zig's rerun of a command pane, which emits a spawn with no `open a terminal` stop; the base's run and a second run had none); the gui unit-test run once, on T3's change over this one (its description); no frame or perf gate (the user's rule of 2026-11-26); load 1.1 to 9.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/Effect.zig | 6 +++ core/File.zig | 8 +++- core/dump.zig | 6 ++- core/lsp/lsp.zig | 6 +++ dev/Host.zig | 3 ++ dev/Inbox.zig | 11 +++++ dev/Lsp.zig | 40 +++++++++++++++++ dev/gui/gui.zig | 8 ++++ dev/lsp/lsp_client.zig | 88 ++++++++++++++++++++++++++++++++++--- dev/tui/tui.zig | 8 ++++ docs/typ/reference.typ | 2 +- docs/typ/setup.typ | 6 ++- runtime/macos.zig | 6 +++ test/behaviour/language_servers.zig | 57 ++++++++++++++++++++++++ test/daemon.py | 3 ++ test/fs.py | 2 + test/process.zig | 5 ++- test/selfmount.py | 2 + test/session.zig | 19 +++++++- test/tty.zig | 5 ++- 20 files changed, 274 insertions(+), 17 deletions(-) (limited to 'core/File.zig') diff --git a/core/Effect.zig b/core/Effect.zig index 3bca04c9..72244f2b 100644 --- a/core/Effect.zig +++ b/core/Effect.zig @@ -64,6 +64,10 @@ pub const Effect = union(enum) { /// `arg` up to 128 bytes, or for `explain` the query it explains, /// ` `. lsp: struct { id: u32, kind: lsp.Kind, pane: Pane.Id, offset: u32, arg: Buf(160) }, + /// A file opened in pane `pane` (File.open, a session's revived pane): + /// the server its language speaks to started and told of it, off the + /// loop (dev/Lsp.zig open), so its first query finds it ready. + lsp_open: struct { pane: Pane.Id }, /// Snapshot the matching request with pipeRequest(id), then run it away /// from the UI/event loop and answer with pipe_resp. pipe: struct { id: u32 }, @@ -216,6 +220,8 @@ fn performInner(p: *Pardes, e: Effect) void { }, .lsp => |q| p.tape.host(p, .lsp, .{.{ .id = q.id, .kind = q.kind, .pane = q.pane, .offset = q.offset, .arg = q.arg.slice() }}) orelse p.update(.{ .lsp_resp = .{ .id = q.id, .rows = "" } }), + // No workers here (a test, a board): no server starts before a query. + .lsp_open => |o| _ = p.tape.host(p, .lsp_open, .{o.pane}), .pipe => |q| p.tape.host(p, .pipe, .{q.id}) orelse p.update(.{ .pipe_resp = .{ .id = q.id, .success = false, .outputs = &.{} } }), // No workers here (a test, a board): it runs on the loop. diff --git a/core/File.zig b/core/File.zig index 0f9178ac..d16b0c73 100644 --- a/core/File.zig +++ b/core/File.zig @@ -922,7 +922,13 @@ pub fn open(p: *Pardes, id: usize, path: []const u8, line: usize) !*Pane { pane.body.cur_pinned = true; pane.body.cur_row = @intCast(scroll); p.installPane(id, pane); - if (filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = .at(id), .on = true } }); + if (filesystem.localPath(path) != null) { + p.emit(.{ .watch = .{ .pane = .at(id), .on = true } }); + // Its language's server started now, off the loop: the first + // question asked of it finds it ready. Not a picker's preview's, + // which opens no pane (Pick.preview). + p.emit(.{ .lsp_open = .{ .pane = .at(id) } }); + } return pane; } diff --git a/core/dump.zig b/core/dump.zig index 2dde9c8c..d7c44b71 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -718,8 +718,9 @@ fn reviveSession(p: *Pardes, previous: ?*Pardes, resumed: bool) !void { } /// A loaded pane given to this host: a terminal a new shell in its old -/// one's directory under its history, a file watched again (one changed on -/// disk since comes back as it is now, one unsaved is marked changed), a +/// one's directory under its history, a file watched again and its +/// language's server started (one changed on disk since comes back as it +/// is now, one unsaved is marked changed), a /// kind's pane opened again (a PDF a build before the pdf addon dumped, as /// the addon's). fn revivePane(p: *Pardes, id: usize, pane: *pardes.panes.Pane, was_on_disk: bool) void { @@ -762,6 +763,7 @@ fn revivePane(p: *Pardes, id: usize, pane: *pardes.panes.Pane, was_on_disk: bool } else |_| {} } p.emit(.{ .watch = .{ .pane = .at(id), .on = true } }); + p.emit(.{ .lsp_open = .{ .pane = .at(id) } }); // Its file gone from disk since the dump: its text is nowhere else, so // it is said deleted, and Del, Exit and Restore ask first. One never on // disk (a name not yet saved) comes back as it was. diff --git a/core/lsp/lsp.zig b/core/lsp/lsp.zig index 7a636f72..00ffc98b 100644 --- a/core/lsp/lsp.zig +++ b/core/lsp/lsp.zig @@ -96,6 +96,12 @@ pub fn query(io: std.Io, arena: std.mem.Allocator, req: Req, out: *std.Io.Writer return client.query(io, arena, req, out); } +/// A file opened in a pane: its language's server started and told of it +/// (lsp_client.open), on a host's worker. +pub fn open(io: std.Io, arena: std.mem.Allocator, req: Req) !void { + return client.open(io, arena, req); +} + /// The one line the client answers with when it cannot answer at all, and /// why: the core says it rather than "nothing found". pub fn none(out: *std.Io.Writer, comptime fmt: []const u8, args: anytype) std.Io.Writer.Error!void { diff --git a/dev/Host.zig b/dev/Host.zig index 52205518..0a175754 100644 --- a/dev/Host.zig +++ b/dev/Host.zig @@ -54,6 +54,9 @@ pub const VTable = struct { /// startDetached. Null once it runs, else why not. start: ?*const fn (ctx: ?*anyopaque, line: []const u8, why: []u8) ?[]const u8 = null, lsp: ?*const fn (ctx: ?*anyopaque, req: Lsp.Request) void = null, + /// Start the language server of the file `pane` opened, and tell it of + /// the file, on a worker (Lsp.open). + lsp_open: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id) void = null, pipe: ?*const fn (ctx: ?*anyopaque, id: u32) void = null, /// Start the streaming search of this generation on a worker /// (pardes.Stream.start); absent, it runs on the loop. diff --git a/dev/Inbox.zig b/dev/Inbox.zig index bc7c7e8a..a0b9494d 100644 --- a/dev/Inbox.zig +++ b/dev/Inbox.zig @@ -67,6 +67,9 @@ gpa: std.mem.Allocator, lsp_allocator: std.mem.Allocator, /// The query in flight; the UI thread's alone (spawnLsp, teardown). lsp_task: ?Lsp.Task = null, +/// The server start a file's opening asked for (openLsp); the UI +/// thread's alone. +lsp_opener: Lsp.Opener = .{}, /// The `|` pipes' and the addons' jobs' and draws' workers in flight, each /// posting its answer here (`pushPipe`, `pushJob`); the loop's thread's /// alone: joined as their answers land (`land`), canceled at the end. @@ -290,6 +293,8 @@ pub fn deinit(q: *Inbox) void { // The workers in flight end first: what they still deliver is dropped. if (q.lsp_task) |*t| t.future.cancel(q.io); q.lsp_task = null; + if (q.lsp_opener.future) |*f| f.cancel(q.io); + q.lsp_opener.future = null; q.pipe_tasks.cancelAll(q.io); q.job_tasks.cancelAll(q.io); q.close(); @@ -343,6 +348,12 @@ pub fn startLsp(q: *Inbox, core: *pardes.Pardes, e: Lsp.Request) void { Lsp.start(q.io, q.lsp_allocator, core, &q.lsp_task, e, q, pushLspRows); } +/// The language server of the file `pane` opened started, on a worker of +/// its own (Lsp.open). +pub fn openLsp(q: *Inbox, core: *const pardes.Pardes, pane: pardes.Pane.Id) void { + Lsp.open(q.io, q.lsp_allocator, core, &q.lsp_opener, pane); +} + /// A worker's answer taken off the queue, to the core (whichever frontend /// took it), its worker joined: a language server's answer or status line, /// a pipe's, a search's rows, an addon's job or draw, a handover's end. diff --git a/dev/Lsp.zig b/dev/Lsp.zig index b799c9f6..d7638c83 100644 --- a/dev/Lsp.zig +++ b/dev/Lsp.zig @@ -138,6 +138,46 @@ pub fn start(io: std.Io, gpa: std.mem.Allocator, core: *pardes.Pardes, task: *?T task.* = .{ .id = req.id, .future = future }; } +/// The server start a file's opening asks for (`open`), one at a time: +/// `busy` while its worker runs. +pub const Opener = struct { + future: ?std.Io.Future(void) = null, + busy: std.atomic.Value(bool) = .init(false), +}; + +/// Pane `pane`'s file just opened: the server of its language started and +/// told of it (lsp_client.open) on a worker of its own, so its first query +/// finds both done (that query paid a spawn and a handshake, 2.5 s of zls's +/// over the comparison video's project). Not through `start`, whose cancel +/// of the query in flight waits out a handshake on the loop, nor `work`, +/// whose fixed region is the queries'. One at a time: a file opened while +/// one is under way is let go, and told at its first query (syncDoc); one +/// done is awaited (at once) before the next. +pub fn open(io: std.Io, gpa: std.mem.Allocator, core: *const pardes.Pardes, opener: *Opener, pane: pardes.Pane.Id) void { + if (opener.busy.load(.acquire)) return; + if (opener.future) |*f| f.await(io); + opener.future = null; + const p = core.panes[pane.index()] orelse return; + const f = p.file orelse return; + if (!pardes.lsp.speaks(f.path)) return; + const job = snapshot(gpa, core, .{ .id = 0, .kind = .definition, .pane = pane, .offset = 0, .arg = "" }) catch return; + opener.busy.store(true, .release); + opener.future = io.concurrent(tell, .{ io, gpa, job, &opener.busy }) catch { + opener.busy.store(false, .release); + return job.free(gpa); + }; +} + +fn tell(io: std.Io, gpa: std.mem.Allocator, job: *Job, busy: *std.atomic.Value(bool)) void { + defer busy.store(false, .release); + defer job.free(gpa); + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + // A server that failed to start says so itself (`ensure`); one not + // started for want of memory is started by the file's first query. + pardes.lsp.open(io, arena.allocator(), .{ .kind = job.kind, .path = job.path, .source = job.source, .offset = 0, .root = job.root }) catch {}; +} + pub fn work(io: std.Io, gpa: std.mem.Allocator, job: *Job, ctx: ?*anyopaque, deliver: Deliver) void { defer job.free(gpa); // The query's memory is the fixed region memory.zig reserved at diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig index a478db03..7a87c110 100644 --- a/dev/gui/gui.zig +++ b/dev/gui/gui.zig @@ -2648,6 +2648,7 @@ const Shell = struct { .open_link = openLink, .start = host_io.startDetached, .lsp = lsp, + .lsp_open = lspOpen, .pipe = pipe, .search = search, .hand_over = handOver, @@ -3223,6 +3224,13 @@ fn lsp(ctx: ?*anyopaque, req: host_io.Lsp.Request) void { s.core.reportError(req.pane, "lsp", error.WorkersUnavailable); } +/// Not held for `threads_ok`: the boot's file and a restored session's are +/// opened before `start`. +fn lspOpen(ctx: ?*anyopaque, pane: pardes.Pane.Id) void { + const s = shellOf(ctx); + s.queue.openLsp(s.core, pane); +} + fn pipe(ctx: ?*anyopaque, id: u32) void { const s = shellOf(ctx); if (s.threads_ok) return selection_pipe.start(s.io, s.gpa, s.core, &s.queue.pipe_tasks, id, s.queue, Queue.pushPipe); diff --git a/dev/lsp/lsp_client.zig b/dev/lsp/lsp_client.zig index a53ff57f..be5069ae 100644 --- a/dev/lsp/lsp_client.zig +++ b/dev/lsp/lsp_client.zig @@ -6,9 +6,10 @@ //! //! THE PROCESS LIFECYCLE IS THE DESIGN. `lsp.query` is a synchronous call on a //! worker thread, and a language server costs tens of milliseconds to start -//! and MINUTES to index a large workspace. So a server is spawned lazily on -//! the first query that needs it, kept for the life of the editor, and each -//! spec gets at most one — `conns[i]` guards itself with an `Io.Mutex` +//! and MINUTES to index a large workspace. So a server is spawned when a +//! file of its language opens in a pane (`open`, on a worker of its own) or +//! by the first query that needs it, kept for the life of the editor, and +//! each spec gets at most one — `conns[i]` guards itself with an `Io.Mutex` //! because a canceled query can still be inside `run` when the next arrives. //! Every wait is an `Io` cancelation point: a shell cancels the worker of a //! query it no longer wants, and the worker stops there. @@ -40,7 +41,8 @@ //! (ignoring SIGPIPE process-wide would be inherited by every pty shell we //! fork and would change what `yes | head` does in a pane), //! - a binary missing from PATH costs one cached probe, disables the spec -//! for the session, and says so ONCE on the message row. +//! for the session, and says so ONCE on the message row (a query's; a +//! file opened says nothing). //! //! Position encoding is negotiated to utf-8 and the SERVER'S ANSWER is //! believed, not our request; the utf-16 conversion is implemented in both @@ -478,8 +480,8 @@ fn status(io: std.Io, path: []const u8, out: *std.Io.Writer) !void { const thier = c.caps.type_hier; c.mu.unlock(io); const env_v = if (libc.getenv(s.env)) |v| std.mem.span(v) else null; - // Never spawned is not off: the first query of its files starts it. - try out.print(" {s:<28} {s}", .{ s.name, if (state == .off) "not started yet (its first query starts it)" else @tagName(state) }); + // Never spawned is not off: a file of its opened starts it. + try out.print(" {s:<28} {s}", .{ s.name, if (state == .off) "not started yet (a file of its opened starts it)" else @tagName(state) }); if (state == .ready or state == .starting) { try out.print(" root {s} {s}", .{ root, @tagName(enc) }); if (pull) try out.print(" pull-diags", .{}); @@ -757,6 +759,36 @@ pub fn query(io: std.Io, arena: std.mem.Allocator, asked: lsp.Req, out: *std.Io. try out.writeAll(scratch.buffered()); } +/// A file opened in a pane (dev/Lsp.zig open): the server of its language +/// started as its first query would start it (`ensure`, which says +/// `starting` and `ready` on the message row) and told of the file +/// (didOpen), so that query finds both done. A server not installed is +/// disabled without a word: the file's first query says it is not found, +/// not every file opened. Nothing in the query log: none was asked. +/// PARDES_LSP_OPEN=off starts none (the process harnesses' default), and a +/// test binary starts none unless it says `on` (the behaviour harness's +/// language sessions, their servers the mock): no test starts a server of +/// this machine's by opening a file. +pub fn open(io: std.Io, arena: std.mem.Allocator, req: lsp.Req) Err!void { + const said = if (libc.getenv("PARDES_LSP_OPEN")) |v| std.mem.span(v) else ""; + if (std.mem.eql(u8, said, "off") or (builtin.is_test and !std.mem.eql(u8, said, "on"))) return; + const si = specFor(req.path) orelse return; + const c = &conns[si]; + try c.mu.lock(io); + defer c.mu.unlock(io); + if (c.state == .disabled) return; + var exe_buf: [4096:0]u8 = undefined; + if (!c.alive() and binOf(&specs[si], &exe_buf) == null) { + c.state = .disabled; + return; + } + var tr: Trace = .{}; + _ = try ensure(c, io, si, arena, req, &tr); + var uri: std.ArrayList(u8) = .empty; + try uriOf(&uri, arena, req.path); + try syncDoc(c, io, si, arena, uri.items, req.source); +} + fn traceOut(tr: *const Trace, req: lsp.Req, out: *std.Io.Writer, rows: usize, us: u64) std.Io.Writer.Error!void { if (req.kind != .explain) return; try out.print("lsp explain — the {s} query at byte {d} of {s}\n\n", .{ @@ -3162,11 +3194,53 @@ test "a language with no server to start says so, not that it did not answer" { try std.testing.expectEqualStrings("@none language server for .py not found\n", out.buffered()); } +test "a file opened whose server is not installed disables it without a word, at every file's open; a query of it then says it is not found" { + const host_io = @import("../host_io.zig"); + const io = std.testing.io; + const si = specFor("/x/a.py") orelse return; + const c = &conns[si]; + const was_state = c.state; + defer c.state = was_state; + // A test binary's files start servers only where it says so. + const names = [_][*:0]const u8{ "PARDES_LSP_PY", "PARDES_LSP_OPEN" }; + var was_buf: [names.len][4096:0]u8 = undefined; + var was: [names.len]?[:0]const u8 = undefined; + for (names, &was, &was_buf) |name, *w, *b| w.* = if (libc.getenv(name)) |v| try std.fmt.bufPrintSentinel(b, "{s}", .{std.mem.span(v)}, 0) else null; + defer for (names, was) |name, w| { + _ = if (w) |v| host_io.Shell.setenv(name, v.ptr, 1) else host_io.testUnsetenv(name); + }; + _ = host_io.Shell.setenv("PARDES_LSP_PY", "/nonexistent/pyright-langserver", 1); + _ = host_io.Shell.setenv("PARDES_LSP_OPEN", "on", 1); + const Said = struct { + var n: usize = 0; + fn post(_: ?*anyopaque, _: []const u8) void { + n += 1; + } + }; + Said.n = 0; + // A word said before is never said twice in a row (`post`): forgotten. + sink_last_len[si] = 0; + setStatusSink(null, Said.post); + defer setStatusSink(null, null); + c.state = .off; + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + for ([_][]const u8{ "/x/a.py", "/x/b.py" }) |path| { + try open(io, arena.allocator(), .{ .kind = .definition, .path = path, .source = "", .offset = 0, .root = "/x" }); + try std.testing.expectEqual(State.disabled, c.state); + } + try std.testing.expectEqual(@as(usize, 0), Said.n); + var buf: [256]u8 = undefined; + var out: std.Io.Writer = .fixed(&buf); + try query(io, arena.allocator(), .{ .kind = .hover, .path = "/x/a.py", .source = "", .offset = 0 }, &out); + try std.testing.expectEqualStrings("@none language server for .py not found\n", out.buffered()); +} + test "Lspinfo before any query says a server is not started yet, not off" { var out: std.Io.Writer.Allocating = .init(std.testing.allocator); defer out.deinit(); try status(std.testing.io, "/x/notes.txt", &out.writer); - try std.testing.expect(std.mem.indexOf(u8, out.written(), "not started yet (its first query starts it)") != null); + try std.testing.expect(std.mem.indexOf(u8, out.written(), "not started yet (a file of its opened starts it)") != null); } test "a server that failed a moment ago is said to have failed, and when it is tried again, not to be missing" { diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index aa1f8849..f7b9cae8 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -1328,6 +1328,7 @@ const Shell = struct { .open_link = openLink, .start = host_io.startDetached, .lsp = lsp, + .lsp_open = lspOpen, .pipe = pipe, .search = search, .job = job, @@ -2047,6 +2048,13 @@ const Shell = struct { s.core.reportError(req.pane, "lsp", error.WorkersUnavailable); } + /// Not held for `threads_ok`: the boot's file and a restored + /// session's are opened before `start`. + fn lspOpen(ctx: ?*anyopaque, pane: pardes.Pane.Id) void { + const s = of(ctx); + s.ptys.queue.openLsp(s.core, pane); + } + fn pipe(ctx: ?*anyopaque, id: u32) void { const s = of(ctx); if (!s.threads_ok) { diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ index 42b44fc9..a08d3acc 100644 --- a/docs/typ/reference.typ +++ b/docs/typ/reference.typ @@ -295,7 +295,7 @@ A line written to #file("exec") is #word("Exec"): index the file asks (`scip: , , , , indexed , files newer`, or `scip: no index.scip above ; Index runs `), which server serves it and its state (`not - started yet` until its first query starts it, ` failed recently; + started yet` until a file of its opened starts it, ` failed recently; retry in Ns` while it backs off), and what answered each query lately (`scip`, or the server); #word("Lspwhy") narrates the last query step by step (in `+Lsp`). The diff --git a/docs/typ/setup.typ b/docs/typ/setup.typ index c9556c61..3ef67da5 100644 --- a/docs/typ/setup.typ +++ b/docs/typ/setup.typ @@ -119,8 +119,10 @@ script on that `PATH` is a word you can click. = Language servers -pardes starts a language server for a file it knows, searching `PATH` first -and then `~/.local/bin` (desktop launchers may leave it out of `PATH`): +pardes starts a language server when a file it knows opens in a pane (a +picker's preview starts none), searching `PATH` first and then +`~/.local/bin` (desktop launchers may leave it out of `PATH`), so the +file's first question finds it ready: #pairs( [`.zig`], [`zls` (`PARDES_LSP_ZIG`)], diff --git a/runtime/macos.zig b/runtime/macos.zig index 7e0f50e7..6a6d39a2 100644 --- a/runtime/macos.zig +++ b/runtime/macos.zig @@ -1628,6 +1628,7 @@ const vtable: pardes.Host.VTable = .{ .open_link = openLink, .start = host_io.startDetached, .lsp = lspRequest, + .lsp_open = lspOpen, .pipe = pipeRequest, }; @@ -1640,6 +1641,11 @@ fn lspRequest(ctx: ?*anyopaque, req: host_io.Lsp.Request) void { st.inbox.startLsp(st.core, req); } +fn lspOpen(ctx: ?*anyopaque, pane: pardes.Pane.Id) void { + const st = hostState(ctx); + st.inbox.openLsp(st.core, pane); +} + fn pipeRequest(ctx: ?*anyopaque, id: u32) void { const st = hostState(ctx); selection_pipe.start(st.io, st.gpa, st.core, &st.pipe_tasks, id, &st.inbox, Inbox.pushPipe); diff --git a/test/behaviour/language_servers.zig b/test/behaviour/language_servers.zig index 13e42fa6..79b556f4 100644 --- a/test/behaviour/language_servers.zig +++ b/test/behaviour/language_servers.zig @@ -323,3 +323,60 @@ test "language-servers: SPC l a lists the server's code actions in the pane's ta try s.keys("u"); try s.expect(body, before); } + +extern "c" fn setenv(name: [*:0]const u8, value: [*:0]const u8, overwrite: c_int) c_int; + +/// The row of Lspinfo's report on the server `name` (`zls`), asked of the +/// pane with the keyboard, and how many queries its client has answered. +fn serverRow(s: *Session, name: []const u8) !struct { []const u8, []const u8 } { + try s.write(s.at("/pane/{d}/ctl", .{try s.focused()}), "Lspinfo\n"); + const info = try bodyOf(s, "+Lsp"); + const at = (std.mem.indexOf(u8, info, s.at("\n {s} ", .{name})) orelse return error.NoSuchServer) + 1; + const row = info[at .. std.mem.indexOfScalarPos(u8, info, at, '\n') orelse info.len]; + const log = std.mem.indexOf(u8, info, "client queries (") orelse return error.NoQueryLog; + return .{ row, info[log .. std.mem.indexOfPos(u8, info, log, " total") orelse return error.NoQueryLog] }; +} + +test "language-servers: a file of a server's language opened in a pane starts that server and tells it of the file, with no query asked; a picker's preview of one starts none, a second file no second server, and a server not installed is found silently" { + const io = std.testing.io; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + // A work tree of its own: Find searches it, not the one the test runs in. + try tmp.dir.createDir(io, ".git", .default_dir); + try tmp.dir.writeFile(io, .{ .sub_path = "a.zig", .data = "const a = 1;\n" }); + try tmp.dir.writeFile(io, .{ .sub_path = "b.zig", .data = "const b = 2;\n" }); + try tmp.dir.writeFile(io, .{ .sub_path = "c.py", .data = "c = 3\n" }); + try tmp.dir.writeFile(io, .{ .sub_path = "d.py", .data = "d = 4\n" }); + try tmp.dir.writeFile(io, .{ .sub_path = "notes.txt", .data = "the notes\n" }); + var buf: [4096]u8 = undefined; + const dir = buf[0..try tmp.dir.realPath(io, &buf)]; + var s = try Session.initLanguage(std.testing.allocator); + defer s.deinit(); + _ = try s.lookFile(s.at("{s}/notes.txt", .{dir})); + // a.zig previewed by Find's picker (the session's jumps walk): its text + // shown, its server (the scripted one, the session's zls) not started. + try s.keys(" ffa.zig"); + s.tick(); + try std.testing.expect(has(try s.screen(), "const a = 1;")); + try s.keys("\x1b"); + const before, const asked = try serverRow(&s, "zls"); + try std.testing.expect(has(before, "not started yet")); + // Opened: started and told of a.zig, no query asked of it. + _ = try s.lookFile(s.at("{s}/a.zig", .{dir})); + const opened, const asked_open = try serverRow(&s, "zls"); + try std.testing.expect(has(opened, "ready") and has(opened, "docs 1")); + try std.testing.expectEqualStrings(asked, asked_open); + // A second file: the same server told of it too (a second would know one). + _ = try s.lookFile(s.at("{s}/b.zig", .{dir})); + const second, _ = try serverRow(&s, "zls"); + try std.testing.expect(has(second, "ready") and has(second, "docs 2")); + // Not installed: the language's server disabled at the first file's + // open, with no word at either (its first query says it is not found). + _ = setenv("PARDES_LSP_PY", "/nonexistent/pyright-langserver", 1); + _ = try s.lookFile(s.at("{s}/c.py", .{dir})); + _ = try s.lookFile(s.at("{s}/d.py", .{dir})); + const missing, const asked_missing = try serverRow(&s, "pyright"); + try std.testing.expect(has(missing, "disabled")); + try std.testing.expectEqualStrings(asked, asked_missing); + try std.testing.expect(!has(try s.screen(), "not found")); +} diff --git a/test/daemon.py b/test/daemon.py index 3dfb0710..95a4da75 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -92,6 +92,9 @@ def base_env(): of the user's) or a pager; under `--with-pair`, PARDES_PAIR set in it, as for a user who exported it: every mode run with the variable.""" env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + # No language server starts at a file's open (lsp_client.open): none of + # this machine's. + env['PARDES_LSP_OPEN'] = 'off' if WITH_PAIR: env['PARDES_PAIR'] = '1' return env diff --git a/test/fs.py b/test/fs.py index a2b67cbc..abf9f1b6 100644 --- a/test/fs.py +++ b/test/fs.py @@ -32,6 +32,8 @@ def session(binary, root, name, *options, socket_name=None, file=None, tty=False env.update(inherited or {}) for language in ['RS', 'C', 'GO', 'TS', 'PY']: env['PARDES_LSP_' + language] = '' + # No server starts at a file's open (lsp_client.open): none of this machine's. + env['PARDES_LSP_OPEN'] = 'off' fixture = root / (name + '.txt') fixture.write_bytes(b'initial\n') address = root / ('pardes-9p-' + (socket_name or name) + '.sock') diff --git a/test/process.zig b/test/process.zig index 791a5b8e..fe5d97f0 100644 --- a/test/process.zig +++ b/test/process.zig @@ -960,9 +960,12 @@ pub const Child = struct { // never the user's: the dumps a test makes there would push the // user's out. if (root_z != null) _ = unsetenv("XDG_DATA_HOME"); + // No language server starts at a file's open (lsp_client.open): + // the `lsp` cases' zls is this machine's, started by their + // first query as before. for ([_][2][*:0]const u8{ .{ "PARDES_DAEMON", "off" }, .{ "PARDES_LSP_RS", "" }, .{ "PARDES_LSP_C", "" }, .{ "PARDES_LSP_GO", "" }, - .{ "PARDES_LSP_TS", "" }, .{ "PARDES_LSP_PY", "" }, + .{ "PARDES_LSP_TS", "" }, .{ "PARDES_LSP_PY", "" }, .{ "PARDES_LSP_OPEN", "off" }, }) |kv| if (setenv(kv[0], kv[1], 1) != 0) _exit(126); if (opts.pty != null and setenv("TERM", "xterm-256color", 1) != 0) _exit(126); // No test reaches the user's display: a window any of them diff --git a/test/selfmount.py b/test/selfmount.py index 61d32523..aa4540b0 100644 --- a/test/selfmount.py +++ b/test/selfmount.py @@ -81,6 +81,8 @@ def run(binary): env.update(PARDES_NOTIME='1', TERM='xterm-256color', PARDES_DUMP=f'/tmp/{name}.dump.zon') for language in ['RS', 'C', 'GO', 'TS', 'PY']: env['PARDES_LSP_' + language] = '' + # No server starts at a file's open (lsp_client.open): none of this machine's. + env['PARDES_LSP_OPEN'] = 'off' pid, master = pty.fork() if pid == 0: os.execve(ns, ['9ns', '--mntgen', '--', binary, '--tty', '--9p=' + name, str(fixture)], env) diff --git a/test/session.zig b/test/session.zig index 13798753..9285c13b 100644 --- a/test/session.zig +++ b/test/session.zig @@ -38,6 +38,8 @@ pub const Session = struct { /// What the language words' questions are asked of their servers /// through (initLanguage); none, and they go unanswered. languages: ?std.Io = null, + /// The server start a file's opening asks for (`languages`'s). + opener: pardes.host_io.Lsp.Opener = .{}, /// Kinds' jobs taken as a host's worker takes them and held, not run, /// until `releaseJobs`: a job under way across what a test does /// meanwhile (a reload). @@ -62,12 +64,19 @@ pub const Session = struct { } /// A session showing one scratch pane that asks language servers as a - /// host does, a `.rs` file's the scripted one (test/lspmock.zig, which - /// answers over a main.rs and the lib.rs beside it). + /// host does, a `.rs` and a `.zig` file's the scripted one + /// (test/lspmock.zig, which answers over a main.rs and the lib.rs beside + /// it), every other language's none: no test starts a server of this + /// machine's. pub fn initLanguage(gpa: std.mem.Allocator) !Session { var s = try initFile(gpa, "x\n"); const mock = try std.Io.Dir.cwd().realPathFileAlloc(std.testing.io, @import("session_options").lspmock, s.arena.allocator()); _ = setenv("PARDES_LSP_RS", mock, 1); + _ = setenv("PARDES_LSP_ZIG", mock, 1); + for ([_][*:0]const u8{ "PARDES_LSP_C", "PARDES_LSP_GO", "PARDES_LSP_TS", "PARDES_LSP_PY" }) |v| _ = setenv(v, "", 1); + // A test binary's opened files start their servers where it says + // so (lsp_client.open): here, the mock. + _ = setenv("PARDES_LSP_OPEN", "on", 1); s.languages = std.testing.io; return s; } @@ -295,6 +304,12 @@ pub const Session = struct { // held while a test holds them (`hold_jobs`). .job => |j| if (!s.hold_jobs) pardesOf(s).perform(e) else if (pardes.host_io.KindJob.take(pardesOf(s), j.pane.index(), j.serial, j.token)) |taken| s.held.append(pardesOf(s).gpa, taken) catch taken.drop(), .lsp => |q| if (s.languages) |io| s.askServer(io, .{ .id = q.id, .kind = q.kind, .pane = q.pane, .offset = q.offset, .arg = q.arg.slice() }), + // A file's server started as a host starts it, and waited for. + .lsp_open => |o| if (s.languages) |io| { + pardes.host_io.Lsp.open(io, pardesOf(s).gpa, pardesOf(s), &s.opener, o.pane); + if (s.opener.future) |*f| f.await(io); + s.opener.future = null; + }, .watch => |w| { if (s.watch_fd < 0) s.watch_fd = pardes.file_watch.init(true); if (s.watch_fd >= 0) _ = pardes.file_watch.applyEffect(pardesOf(s), std.Io.Threaded.global_single_threaded.io(), s.watch_fd, &s.watches, w.pane.index(), w.on, w.mode); diff --git a/test/tty.zig b/test/tty.zig index 97b64b7c..cbb4e446 100644 --- a/test/tty.zig +++ b/test/tty.zig @@ -128,9 +128,12 @@ pub const Tty = struct { _ = setenv("PARDES_NOTIME", "1", 1); _ = setenv("PARDES_TEST_CLOCK", "1", 1); // Hermetic language clients: `.rs` speaks to the mock, every other - // spec is off, so a stray `.c` never spawns this machine's clangd. + // spec but zls is off, so a stray `.c` never spawns this machine's + // clangd, and no server starts at a file's open (lsp_client.open): + // the `lsp` cases' zls is started by their first query. _ = setenv("PARDES_LSP_RS", try arena.dupeSentinel(u8, lspmock, 0), 1); for ([_][*:0]const u8{ "PARDES_LSP_C", "PARDES_LSP_GO", "PARDES_LSP_TS", "PARDES_LSP_PY" }) |v| _ = setenv(v, "", 1); + _ = setenv("PARDES_LSP_OPEN", "off", 1); const dump = try std.fmt.allocPrintSentinel(arena, "{s}/dump.zon", .{base}, 0); _ = setenv("PARDES_DUMP", dump, 1); if (replay) { -- cgit v1.3