summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Query.zig65
-rw-r--r--core/Stream.zig29
-rw-r--r--core/replica.zig64
-rw-r--r--core/root.zig4
4 files changed, 119 insertions, 43 deletions
diff --git a/core/Query.zig b/core/Query.zig
index ebb44155..f0e9ee1a 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| {
diff --git a/core/Stream.zig b/core/Stream.zig
index 1f4a7405..78f6ef41 100644
--- a/core/Stream.zig
+++ b/core/Stream.zig
@@ -245,10 +245,10 @@ ahead_seen: struct { serial: u32 = 0, scroll: usize = 0, dir: i2 = 1 } = .{},
/// the next asked when it lands (Query.recolor); a worker per file if a
/// Grep of hundreds of files colours too slowly.
rows_paint: ?TextTask = null,
-/// The files (a hash of path and revision) asked since the last Grep
-/// began: each asked once, so a file whose colours never fit its rows
-/// (changed on disk since) is not painted again and again. ponytail: a
-/// ring of 256; the oldest forgotten.
+/// The files (a hash of the path) asked since the last Grep began: each
+/// asked once, so a file whose colours never fit its rows (changed on
+/// disk since, an edit) is not painted again and again. ponytail: a ring
+/// of 256; the oldest forgotten.
rows_asked: [256]u64 = @splat(0),
rows_asked_at: u8 = 0,
/// Rows asked for their colours while a 9P write was served: asked again
@@ -352,17 +352,13 @@ pub fn askAhead(p: *Pardes) void {
/// from disk there. Kept in the locations cache when it lands, where the
/// rows find them (Query.Shades). Not without workers (the rows stay
/// plain), nor for a file bigger than `max_rows_paint_bytes`, nor twice for
-/// one revision of a file.
+/// a file between two Greps. Asked after every file's rows, whatever
+/// colours they have here: those are this process's own (what its frames
+/// painted of the text, what its locations cache kept: in no digest), and
+/// what a step asks of a worker must not hang on them.
pub fn paintRows(p: *Pardes, path: []const u8) void {
const s = &p.stream;
if (s.rows_paint != null or !p.tape.has(p, .search)) return;
- // Asked while a 9P write is served (a script's Grep): not now, as no
- // paint is (the write would wait for it to settle); the next step asks.
- if (p.fs.serving) {
- s.rows_later = true;
- return;
- }
- if (!syntax.readyApart(path)) return;
var content: ?[]const u8 = null;
var revision: u32 = 0;
for (p.panes) |slot| if (slot) |pane| if (pane.file) |f| if (f.output == null and std.mem.eql(u8, f.path, path)) {
@@ -371,8 +367,15 @@ pub fn paintRows(p: *Pardes, path: []const u8) void {
break;
};
if (content) |c| if (c.len > max_rows_paint_bytes) return;
- const key = std.hash.Wyhash.hash(revision, path) | 1;
+ const key = std.hash.Wyhash.hash(0, path) | 1;
if (std.mem.indexOfScalar(u64, &s.rows_asked, key) != null) return;
+ if (!syntax.readyApart(path)) return;
+ // Asked while a 9P write is served (a script's Grep): not now, as no
+ // paint is (the write would wait for it to settle); the next step asks.
+ if (p.fs.serving) {
+ s.rows_later = true;
+ return;
+ }
const job = TextJob.make(p.gpa, 0, revision, 0, path, content orelse "") orelse return;
s.rows_asked[s.rows_asked_at] = key;
s.rows_asked_at +%= 1;
diff --git a/core/replica.zig b/core/replica.zig
index 24d1ad21..e05cf79e 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -5560,6 +5560,70 @@ test "a client joined from a dump makes a `/` query's rows as the session does,
}
}
+// A query row's colours come from what this process has (its frames'
+// paint of the owner, File.highlights; a worker's paint kept in the
+// locations cache): out of the rows' digest. Whether a step asks a
+// worker to paint the rows' file (Stream.paintRows, an effect on the
+// tape) must not come from them: a session whose host paints on workers
+// (search), that has drawn its owner, and a client that has not.
+test "a client joined from a dump asks a worker for a `/` query's colours as the session does, though only the session has drawn its owner" {
+ const Paints = struct {
+ fn search(_: ?*anyopaque, _: u32) void {}
+ const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .search = search };
+ };
+ const gpa = std.testing.allocator;
+ // A view as tall as the text: the frame paints every line of it.
+ const a = try Authority.init(gpa, .{ .cols = 80, .rows = 500, .file = "build.zig" }, .{ .vtable = &Paints.vtable }, false);
+ defer a.deinit();
+ {
+ const was = Stepping.begin(&a.t, null);
+ defer was.end();
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ _ = try a.core.render(arena.allocator());
+ }
+ _ = try a.openView(2);
+ const joiner = try joinedNow(a, 3, 1);
+ defer joiner.deinit();
+ var buf: [256]u8 = undefined;
+ for ("/co", 1..) |c, seq| {
+ const u = try gpa.dupe(u8, try a.take(try inputOf(&buf, 1, @intCast(seq), .{ .key = .{ .cp = c, .text = &.{c} } })));
+ defer gpa.free(u);
+ joiner.confirm(u);
+ try agrees(a, joiner);
+ }
+}
+
+// The same for the colours a worker painted earlier, kept in the session's
+// locations cache (a Grep since has asked again of every file): a dump
+// carries no cache, so a client joined since has none.
+test "a client joined from a dump asks a worker for a `/` query's colours as the session does, though only the session has them from an earlier paint" {
+ const Paints = struct {
+ fn search(_: ?*anyopaque, _: u32) void {}
+ const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .search = search };
+ };
+ const gpa = std.testing.allocator;
+ const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "build.zig" }, .{ .vtable = &Paints.vtable }, false);
+ defer a.deinit();
+ {
+ const p = a.core;
+ const f = &p.panes[0].?.file.?;
+ const colors = try pardes.syntax.highlightFileRange(gpa, f.path, f.content, 0, f.content.len);
+ defer gpa.free(colors);
+ try p.locations_cache.put(p.tree_sitter_gpa, f.path, f.content, colors);
+ }
+ _ = try a.openView(2);
+ const joiner = try joinedNow(a, 3, 1);
+ defer joiner.deinit();
+ var buf: [256]u8 = undefined;
+ for ("/co", 1..) |c, seq| {
+ const u = try gpa.dupe(u8, try a.take(try inputOf(&buf, 1, @intCast(seq), .{ .key = .{ .cp = c, .text = &.{c} } })));
+ defer gpa.free(u);
+ joiner.confirm(u);
+ try agrees(a, joiner);
+ }
+}
+
test "a step that reads a terminal's rows as the core keeps them sends a new client the ones it holds as holes" {
if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
const gpa = std.testing.allocator;
diff --git a/core/root.zig b/core/root.zig
index 5300ce93..b5109b0e 100644
--- a/core/root.zig
+++ b/core/root.zig
@@ -737,7 +737,7 @@ const kept_out = [_]struct { []const u8, []const u8, []const u8 }{
.{ "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; a terminal is in no digest (Term.zig)" },
- .{ "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)" },
+ .{ "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", "retired_panes", "panes torn down this step, freed at its end" },
.{ "Core.zig", "distrusted frames tape", "Options: the client's own list, its runner's statistics, its tape" },
.{ "Event.zig", "native_image_patches", "what this process's shell can take" },
@@ -746,7 +746,7 @@ const kept_out = [_]struct { []const u8, []const u8, []const u8 }{
.{ "panes.zig views.zig", "notices", "made again from the step's state at the top of update and presented, and at sync (Messages.collectNotices); a frame's are its own" },
.{ "panes.zig views.zig", "pan", "written by steps only (sync, a view unparked) from the pane and its terminal" },
.{ "File.zig", "cap line_starts line_cap", "the text's line index, of its bytes" },
- .{ "File.zig", "highlights highlight_start syntax_dirty", "how a text looks, painted by frames: read by frames, and by a query's rows for colours only (out of their digest)" },
+ .{ "File.zig", "highlights highlight_start syntax_dirty", "how a text looks, painted by frames: read by frames, and by a query's rows for colours only (out of their digest; what a step asks a worker to paint is never decided by them, Stream.paintRows)" },
.{ "File.zig", "allocator", "ContextCache's: what its declarations were made with, the parse's or a load's (a machine's handle, no state)" },
.{ "File.zig", "declarations", "ContextCache's: the text's at its revision (dumped, digested), parsed again from the text at a load" },
.{ "File.zig", "node_tree node_tree_revision node_tree_edits node_history", "the parse of the text at its revision, made by the first key that walks it" },