diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-21 01:00:47 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-21 01:08:24 -0300 |
| commit | 76565c605defb03ab6aa8300b93f306054a67efd (patch) | |
| tree | 706cc64e23ae33ec6be1d6b9164750ba42da712b /core/Query.zig | |
| parent | 6d937cd125ca04a2edb92b2d014014ee6c2eb45d (diff) | |
| parent | dac87eaa1d57acfc5b2dd8427e7fbacfe065e613 (diff) | |
| download | pardes-76565c605defb03ab6aa8300b93f306054a67efd.tar.gz pardes-76565c605defb03ab6aa8300b93f306054a67efd.zip | |
integration: the terminals' side line on the landed main: pardes-term-join-4 (terminals by the pty's bytes: a client's emulator fed the session's bytes, reload at a join, the lag bound; the query rows' paint decided on replicated state; views.park's leak; a view kept for its client's rejoin; C and Alt-C on a long text walking on from the row last tried: 306 G instructions to 194 M; the soak's witness and watchdog) and main (pardes-new-upgrade); seven conflicts: the wire's version (the side line's 24 is 26 here: 24 is the bye's close byte, 25 the 9P state), Peers' join (the view typed, the lag limit a field's default), a peer's end (the view's index; cut joins again), the client's and the soak's bye (the struct, again or lagged), daemon.py's WIRE; three more the compiler found (a test's view typed: its index where a u8 is asked)
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/Query.zig')
| -rw-r--r-- | core/Query.zig | 65 |
1 files changed, 37 insertions, 28 deletions
diff --git a/core/Query.zig b/core/Query.zig index 3a5aa5f8..e2f59028 100644 --- a/core/Query.zig +++ b/core/Query.zig @@ -888,6 +888,7 @@ fn writeHitRow(p: *Pardes, out: *std.ArrayList(u8), rows: *std.ArrayList(locatio if (gutter + code.len > buf.len) return; @memset(buf[address.len..gutter], ' '); @memcpy(buf[gutter..][0..code.len], code); + sh.file(p, path); try writeRow(p, out, rows, buf[0 .. gutter + code.len], .{ .kind = .match, .source_column = lead, @@ -895,16 +896,16 @@ fn writeHitRow(p: *Pardes, out: *std.ArrayList(u8), rows: *std.ArrayList(locatio .at = .{ .line = line_no, .col = col + 1, .end_line = line_no, .end_col = @max(col + 1, end) }, .location_end = address.len, .code_start = gutter, - .colors = @constCast(if (shade.len >= lead + code.len) shade[lead..][0..code.len] else sh.of(p, path, line_no, code, lead)), + .colors = @constCast(if (shade.len >= lead + code.len) shade[lead..][0..code.len] else sh.of(line_no, code, lead)), }); } /// Rows' syntax colours from their file's whole (as Callstack's rows are), /// kept in the locations cache once a worker has painted it /// (Stream.paintRows): the line found going down the file a row at a time, -/// so a refill walks each file once. A file not painted, or whose line no -/// longer reads as the row does, is asked for (once a refill) and its rows -/// are plain till it lands (`recolor`). +/// so a refill walks each file once. Every file is asked for once its rows +/// are made (`file`, `done`; Stream.paintRows asks each once a Grep), and +/// a row it does not colour is plain till it lands (`recolor`). const Shades = struct { path: []const u8 = "", source: []const u8 = "", @@ -912,50 +913,54 @@ const Shades = struct { /// The line (1-based) that starts at `at` in `source`. line: usize = 1, at: usize = 0, - asked: bool = false, - /// The colours of `code`, which is line `line_no` of `path` from byte - /// `column` on, or none. - fn of(sh: *Shades, p: *Pardes, path: []const u8, line_no: usize, code: []const u8, column: usize) []const u8 { - if (path.len == 0 or line_no == 0 or code.len == 0) return &.{}; - if (!std.mem.eql(u8, path, sh.path)) { - // its own copy: a caller's path is often a buffer it reuses - sh.* = .{ .path = p.scratch.allocator().dupe(u8, path) catch return &.{} }; - if (p.locations_cache.peek(path)) |e| { - sh.source = e.source; - sh.colors = e.colors; - } + /// The rows of `path` follow (a caller's buffer: copied): the file + /// before them done. Called for every row, whatever colours it has, so + /// that every process asks paintRows at the same rows. + fn file(sh: *Shades, p: *Pardes, path: []const u8) void { + if (std.mem.eql(u8, path, sh.path)) return; + sh.done(p); + sh.* = .{ .path = p.scratch.allocator().dupe(u8, path) catch "" }; + if (p.locations_cache.peek(path)) |e| { + sh.source = e.source; + sh.colors = e.colors; } - if (sh.colors.len == 0 or sh.colors.len != sh.source.len) return sh.ask(p); + } + + /// The file's rows are made: its colours asked of a worker. + fn done(sh: *Shades, p: *Pardes) void { + if (sh.path.len > 0) Stream.paintRows(p, sh.path); + } + + /// The colours of `code`, which is line `line_no` of the file `file` + /// named from byte `column` on, or none. + fn of(sh: *Shades, line_no: usize, code: []const u8, column: usize) []const u8 { + if (sh.path.len == 0 or line_no == 0 or code.len == 0) return &.{}; + if (sh.colors.len == 0 or sh.colors.len != sh.source.len) return &.{}; if (line_no < sh.line) { sh.line = 1; sh.at = 0; } while (sh.line < line_no) : (sh.line += 1) { - sh.at = (std.mem.indexOfScalarPos(u8, sh.source, sh.at, '\n') orelse return sh.ask(p)) + 1; + sh.at = (std.mem.indexOfScalarPos(u8, sh.source, sh.at, '\n') orelse return &.{}) + 1; } const line = sh.source[sh.at .. std.mem.indexOfScalarPos(u8, sh.source, sh.at, '\n') orelse sh.source.len]; - if (column + code.len > line.len or !std.mem.eql(u8, line[column..][0..code.len], code)) return sh.ask(p); + if (column + code.len > line.len or !std.mem.eql(u8, line[column..][0..code.len], code)) return &.{}; return sh.colors[sh.at + column ..][0..code.len]; } - - fn ask(sh: *Shades, p: *Pardes) []const u8 { - if (!sh.asked) Stream.paintRows(p, sh.path); - sh.asked = true; - return &.{}; - } }; /// A file's colours arrived (Stream.paintRows): every query pane's hit /// rows still plain, live or frozen, coloured from what is painted now, in -/// place; the first row of a file not painted yet asks for it, so they are -/// painted one after another. +/// place; the next file not asked yet is asked for, so they are painted +/// one after another. pub fn recolor(p: *Pardes) void { for (p.panes) |slot| { const rp = slot orelse continue; if (rp.query == null) continue; const f = &rp.file.?; var sh: Shades = .{}; + defer sh.done(p); var lines = std.mem.splitScalar(u8, f.content, '\n'); // The rows are a blob (File.State): a digest keeps its word for // them and a rollback copy pins them, so they are made again, never @@ -967,9 +972,10 @@ pub fn recolor(p: *Pardes) void { for (f.location_rows, 0..) |row, i| { const text = lines.next() orelse break; if (row.kind != .match or row.location_end == 0 or row.at.line == 0 or row.colors.len == 0) continue; + sh.file(p, row.path); if (std.mem.indexOfNone(u8, row.colors, &.{0}) != null) continue; const code = text[@min(row.code_start, text.len)..]; - const got = sh.of(p, row.path, row.at.line, code[0..@min(code.len, row.colors.len)], row.source_column); + const got = sh.of(row.at.line, code[0..@min(code.len, row.colors.len)], row.source_column); if (got.len == 0) continue; const rows = fresh orelse locations.cloneRows(p.gpa, f.location_rows) catch break; fresh = rows; @@ -1027,6 +1033,7 @@ fn writePlacesRows(p: *Pardes, q: *Query, out: *std.ArrayList(u8), rows: *std.Ar const rel = lookPath(&relbuf, path, dir); const width = addressWidth(rel, index.len); var sh: Shades = .{}; + defer sh.done(p); const decls = ownerDecls(f) orelse &.{}; var decl_now: ?usize = null; var i: usize = @min(from, hits.len); @@ -1182,6 +1189,7 @@ fn makeGrepRows(p: *Pardes, id: usize, full: bool) !void { } var current: ?usize = null; var sh: Shades = .{}; + defer sh.done(p); var width: usize = 0; var relbuf: [4096]u8 = undefined; for (q.found.items[lo..hi], lo..) |fd, i| { @@ -1342,6 +1350,7 @@ fn makeListRows(p: *Pardes, id: usize, pat: []const u8) !void { var pathbuf: [4096 + 8]u8 = undefined; var n: usize = 0; var sh: Shades = .{}; + defer sh.done(p); var width: usize = 0; var relbuf: [4096]u8 = undefined; for (sorted.items, 0..) |ln, li| { |
