summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-22 10:29:02 -0300
committerGabriel Schneider <[email protected]>2026-11-22 10:29:02 -0300
commit6544f73a6b50e5ba68564beea7784593bb54348e (patch)
tree4180d5b74cc4c02208b6122618e5b39609b27fc6
parent58180ae7574b5050331797f0ead1a1cec753b2ed (diff)
parent06d61f097346704452cccd3181da87bb93649bd8 (diff)
downloadpardes-6544f73a6b50e5ba68564beea7784593bb54348e.tar.gz
pardes-6544f73a6b50e5ba68564beea7784593bb54348e.zip
integration: the source view's changes to their last slice on the installed tree: main (`stpnsymm`: pardes-merge55, installed 2026-11-22) and pardes-layers-6 (`rtzmwzsk` on `owsluptw`, on pardes-layers-5: `Churn [window]`: for each declaration the count of the changes in the window that touched it, a cell after the line number and a strip by the scroll thumb from grey to red on a log scale, jj and the parse on the worker; the chords `SPC t c` and `SPC t u`; the manual's chapter "Changes on the source view" and the cheatsheet's rows); no conflict; core-test 915/1079 (164 skipped), shell-test 1121/1124; its gate: .scratch/sketch/reorg/merge56, the numbers in PARDES.md (2026-11-22)
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
-rw-r--r--core/Core.zig1
-rw-r--r--core/File.zig15
-rw-r--r--core/Stream.zig2
-rw-r--r--core/body_layer.zig2
-rw-r--r--core/builtins.zig6
-rw-r--r--core/config.zig3
-rw-r--r--core/draw.zig2
-rw-r--r--core/jj.zig537
-rw-r--r--core/root.zig1
-rw-r--r--core/surface.zig6
-rw-r--r--dev/gui/gui.zig12
-rw-r--r--docs/typ/builtins-gui.json3
-rw-r--r--docs/typ/builtins-tui.json3
-rw-r--r--docs/typ/cheatsheet.typ3
-rw-r--r--docs/typ/guide.typ69
15 files changed, 584 insertions, 81 deletions
diff --git a/core/Core.zig b/core/Core.zig
index 72e92212..ae9ba52f 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -883,6 +883,7 @@ pub fn deinit(p: *Pardes) void {
for (&p.surface.tag_layers) |*layer| gpa.free(layer.cells);
p.surface.placements.deinit(gpa);
p.surface.lanes.deinit(gpa);
+ p.surface.heat.deinit(gpa);
gpa.destroy(p);
}
diff --git a/core/File.zig b/core/File.zig
index 347f4809..c4fc8a38 100644
--- a/core/File.zig
+++ b/core/File.zig
@@ -373,7 +373,7 @@ pub fn gutterWidth(pane: *const Pane) u16 {
var lines = if (file.line_starts.len > 0) file.line_starts.len else lineCount(file.content);
var digits: u16 = 1;
while (lines >= 10) : (lines /= 10) digits += 1;
- return @max(config.PREFIX_W, digits + 1) + laneCells(pane);
+ return @max(config.PREFIX_W, digits + 1) + laneCells(pane) + pane.layers.heat;
}
/// The cells the changes' lanes take after the line number in this view
@@ -758,7 +758,7 @@ fn edit(p: *Pardes, f: *State, off: usize, len: usize, bytes_in: []const u8, who
};
reportEdit(p, f, off, len, bytes);
// A pinned change's per-line values ride with the lines (jj.zig).
- if (p.changes.answers.items.len > 0) jj.edited(p, f, off, len, bytes);
+ if (p.changes.answers.items.len | p.changes.heats.items.len > 0) jj.edited(p, f, off, len, bytes);
if (f.mini) |*mini| mini.deinit(p.gpa);
f.mini = null;
if (f.line_starts.len > 0) shiftIndex(p.gpa, f, off, len, bytes);
@@ -1779,7 +1779,7 @@ fn geometryKey(pane: *const Pane, f: *const State) u64 {
if (f.output) |o| pardes.walk.digest(Output.Origin, &o.from) else 0, std.hash.Wyhash.hash(0, f.path), f.tree_context, f.context.revision orelse 0,
f.context.declarations.len, f.line_starts.len, t.revision orelse 0, t.list.items.len,
pane.view.wrap, pane.view.layered, pane.view.body_h, pane.view.tagline_h,
- pane.view.rect_h, laneCells(pane),
+ pane.view.rect_h, laneCells(pane) + @as(u16, pane.layers.heat),
};
// One hash of them laid out as words: every reader of the map asks for
// this key, a hundred times a frame.
@@ -1797,8 +1797,8 @@ fn geometryKey(pane: *const Pane, f: *const State) u64 {
fn fillBody(comptime ghosted: bool, tab: u16, dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_wrap: bool) usize {
if (record_wrap) pane.wrap_n = 0;
const prefix_width = gutterWidth(pane);
- // Where a number ends: a blank, then the lanes (laneCells), after it.
- const number_end = prefix_width -| laneCells(pane) -| 1;
+ // Where a number ends: a blank, then the heat lane and the lanes after it.
+ const number_end = prefix_width -| laneCells(pane) -| pane.layers.heat -| 1;
const total = nlines(pane.gpa, f);
// The slot after the text's last newline, found once: every numbered
// row below asks whether it is that one.
@@ -1949,9 +1949,12 @@ pub const Layers = struct {
/// frontend, in a window two, which its strips of pixels fill one and
/// a half of (Surface.Lane), in a terminal three, a glyph each.
lanes: u8 = 0,
+ /// Whether this view shows the pane's churn (`Churn`, jj.Heat), as the
+ /// cells its lane takes: one after the number, before the lanes.
+ heat: u8 = 0,
pub fn digest(l: *const Layers, h: *pardes.walk.Hasher) void {
- h.update(&.{ @intFromBool(l.ink), l.lanes });
+ h.update(&.{ @intFromBool(l.ink), l.lanes, l.heat });
}
};
diff --git a/core/Stream.zig b/core/Stream.zig
index 1d061b52..7956e4f2 100644
--- a/core/Stream.zig
+++ b/core/Stream.zig
@@ -735,6 +735,8 @@ fn receiveParse(p: *Pardes, b: *const Batch, serial: u32, revision: u32) void {
} else |_| {}
};
p.needs_frame = true;
+ // A `Churn` waiting on these declarations (jj.zig).
+ @import("jj.zig").parsed(p, serial);
if (s.parse_next) |next| {
s.parse_next = null;
if (p.paneBySerial(next.serial)) |id| parseFor(p, id);
diff --git a/core/body_layer.zig b/core/body_layer.zig
index 817176bb..974df93a 100644
--- a/core/body_layer.zig
+++ b/core/body_layer.zig
@@ -341,7 +341,7 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane
drawGutter(p, s, pane, r, tx, tw, body_h, active);
// Never inlined: in renderBody's own frame it cost every body a
// frame (a terminal's output about 33,000 instructions a pump).
- if (pane.layers.lanes > 0) @call(.never_inline, @import("jj.zig").paint, .{ p, s, pane, r, tx, tw, body_h });
+ if (pane.layers.lanes | pane.layers.heat > 0) @call(.never_inline, @import("jj.zig").paint, .{ p, s, pane, r, tx, tw, body_h });
panes.Query.paintMark(p, s, pane, r, body_h);
if (pane.colorAlgo() != .none)
panes.File.recolorSyntax(p, s, pane, f, r, tx, tw, body_h);
diff --git a/core/builtins.zig b/core/builtins.zig
index 7485af81..e6d22c17 100644
--- a/core/builtins.zig
+++ b/core/builtins.zig
@@ -1086,6 +1086,12 @@ pub const Changes = struct {
pub const run = @import("jj.zig").changesWord;
};
+/// Count, for each declaration of a file's pane, the changes in `window` (jj) that touched it, and show it in this view: a heat lane after the line number and a strip by the scroll thumb, the line numbers' grey to the theme's red on a log scale; `window` a revset or a span of time (`3d`, `2w`, `6m`, `1y`); bare, shown here or not (none counted yet: the file's whole history).
+pub const Churn = struct {
+ pub const takes_arg = true;
+ pub const run = @import("jj.zig").churnWord;
+};
+
/// Stack a diff's hunks as a diff viewer shows them, each under its place and the declarations around it, in a +Diff; on a +Diff, show the diff itself as text. `Diff <file>` stacks that diff's, `Diff <revision>` git show's.
/// The diff viewer's one registration: its word and traits here, all else
/// its own (hunks.zig).
diff --git a/core/config.zig b/core/config.zig
index 1f5819c9..aae832f4 100644
--- a/core/config.zig
+++ b/core/config.zig
@@ -77,7 +77,8 @@ pub const leader_path = paths: {
.Filter = null,
.Diff = null,
.At = null,
- .Changes = null,
+ .Changes = "tc",
+ .Churn = "tu",
.Mode = null,
.Togglettymode = null,
.Collapse = null,
diff --git a/core/draw.zig b/core/draw.zig
index ed317650..419b3a84 100644
--- a/core/draw.zig
+++ b/core/draw.zig
@@ -86,6 +86,7 @@ pub fn place(p: *Pardes, s: *Surface) void {
s.nregions = 0;
s.nrail_ticks = 0;
s.lanes.clearRetainingCapacity();
+ s.heat.clearRetainingCapacity();
// The facts filled in the walk the frame's places take anyway.
viewFacts(p, &p.facts);
s.facts = &p.facts;
@@ -511,6 +512,7 @@ fn renderPane(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r:
}
try body_layer.joinBody(p, s, arena, pane, r, id, active, rail.*);
+ if (pane.layers.heat > 0) @import("jj.zig").railHeat(p, s, pane, id, rail.rect);
// A terminal panned to its cursor in a view shorter than it: an arrow
// in the gutter's first body row says rows are above (views.zig).
if (pane.pan > 0) s.set(r.x, p.bodyTop(pane, r), "↑", .{ .fg = .{ .rgb = chrome.box } });
diff --git a/core/jj.zig b/core/jj.zig
index dd54dfc5..64a27ead 100644
--- a/core/jj.zig
+++ b/core/jj.zig
@@ -17,6 +17,7 @@ const Output = pardes.panes.Output;
const look = @import("look.zig");
const layout = @import("layout.zig");
const diff = @import("diff.zig");
+const syntax = @import("syntax.zig");
/// What jj answered: why not, in its own words (its first line, without
/// `Error: `), or the file's bytes. The caller's, in the allocator the site
@@ -253,15 +254,60 @@ pub fn answered(p: *Pardes, serial: u32) ?*Changes {
return null;
}
+/// What jj answered for pane `serial`'s `Churn` (`Pardes.changes`), counted.
+pub fn churned(p: *Pardes, serial: u32) ?*Heat {
+ for (p.changes.heats.items) |*h| if (h.serial == serial) return h;
+ return null;
+}
+
/// Pane `serial`'s answers let go (the pane's end).
pub fn forget(p: *Pardes, serial: u32) void {
for (p.changes.answers.items, 0..) |*c, i| if (c.serial == serial) {
c.deinit(p.gpa);
_ = p.changes.answers.swapRemove(i);
+ break;
+ };
+ forgetHeat(p, serial);
+}
+
+fn forgetHeat(p: *Pardes, serial: u32) void {
+ for (p.changes.heats.items, 0..) |*h, i| if (h.serial == serial) {
+ h.deinit(p.gpa);
+ _ = p.changes.heats.swapRemove(i);
return;
};
}
+/// A pane's `Churn [window]` (PARDES.md "Changes on the source view":
+/// churn per declaration): for each line, how many of the window's changes
+/// touched the declaration it is in (tree-sitter's innermost, as
+/// TreeContext finds them; 0 outside any), counted in every process from
+/// jj's raw answer (`heatOf`), replicated state as `Changes` is, riding
+/// with the lines through edits.
+pub const Heat = struct {
+ pub const replica = .{ .len = .{.{ "revset", "revset_len" }} };
+ serial: u32,
+ /// The window as jj was asked it.
+ revset: [Changes.revset_max]u8 = undefined,
+ revset_len: u8 = 0,
+ lines: []u16 = &.{},
+ /// The file's hottest declaration's count, the gradient's top.
+ hottest: u16 = 0,
+ /// jj's raw answer until it is counted (`parsed`): its log, then its
+ /// text of the revision from `pending_was` on.
+ pending: []u8 = &.{},
+ pending_was: u32 = 0,
+
+ pub fn deinit(h: *Heat, gpa: std.mem.Allocator) void {
+ gpa.free(h.lines);
+ gpa.free(h.pending);
+ }
+
+ pub fn window(h: *const Heat) []const u8 {
+ return h.revset[0..h.revset_len];
+ }
+};
+
/// A pinned change, as `jj log` says it.
pub const Pin = struct {
pub const replica = .{ .len = .{ .{ "author", "author_len" }, .{ "title", "title_len" } } };
@@ -378,7 +424,57 @@ pub fn changesWord(c: pardes.builtins.Ctx) void {
else
return p.reportFailure(c.id, "Changes: only a file's pane takes it");
pane.layers.lanes = cells;
- ask(p, c.id, pane.serial, shown.path, shown.rev, revset);
+ ask(p, .changes, c.id, pane.serial, shown.path, shown.rev, revset);
+}
+
+/// The `Churn` word (builtins.zig registers it): in a file's pane (or a
+/// revision's), how many changes in `window` touched each declaration,
+/// shown in this view as a heat lane after the line number and a strip by
+/// the scroll thumb. The window: a revset, or a span of time back from now
+/// (`3d`, `2w`, `6m`, `1y`: what the file's history has in it); bare, shown
+/// here or not, and with none counted yet the file's whole history (`::`
+/// the revision shown).
+pub fn churnWord(c: pardes.builtins.Ctx) void {
+ const p = c.p;
+ const pane = c.pane;
+ const f = if (pane.file) |*file| file else return p.reportFailure(c.id, "Churn: only a file's pane takes it");
+ const arg = std.mem.trim(u8, c.arg orelse "", " \t\r\n");
+ if (arg.len == 0 and pane.layers.heat > 0) {
+ pane.layers.heat = 0;
+ return;
+ }
+ if (arg.len == 0 and churned(p, pane.serial) != null) {
+ pane.layers.heat = 1;
+ return;
+ }
+ const shown: struct { path: []const u8, rev: []const u8 } = if (of(f)) |r|
+ .{ .path = r.path, .rev = r.rev }
+ else if (f.output == null and pardes.filesystem.localPath(f.path) != null)
+ .{ .path = f.path, .rev = "@" }
+ else
+ return p.reportFailure(c.id, "Churn: only a file's pane takes it");
+ var buf: [Changes.revset_max]u8 = undefined;
+ const window = spanOf(&buf, shown.rev, arg) orelse arg;
+ if (window.len > Changes.revset_max) return p.reportFailure(c.id, "Churn: a window that long");
+ pane.layers.heat = 1;
+ ask(p, .churn, c.id, pane.serial, shown.path, shown.rev, window);
+}
+
+/// `arg` as a revset: bare, every change of the revision's history; a span
+/// of time (a count and `h`, `d`, `w`, `m` or `y`), its changes since then
+/// (jj's `author_date`); null for a revset.
+fn spanOf(buf: []u8, rev: []const u8, arg: []const u8) ?[]const u8 {
+ if (arg.len == 0) return std.fmt.bufPrint(buf, "::({s})", .{rev}) catch null;
+ const n = std.fmt.parseInt(u16, arg[0 .. arg.len - 1], 10) catch return null;
+ const unit: []const u8 = switch (arg[arg.len - 1]) {
+ 'h' => "hours",
+ 'd' => "days",
+ 'w' => "weeks",
+ 'm' => "months",
+ 'y' => "years",
+ else => return null,
+ };
+ return std.fmt.bufPrint(buf, "::({s}) & author_date(after:\"{d} {s} ago\")", .{ rev, n, unit }) catch null;
}
// ---- jj off the loop (Stream.zig's model) ----
@@ -392,6 +488,7 @@ pub fn changesWord(c: pardes.builtins.Ctx) void {
/// run a site of the step's tape.
pub const Ask = struct {
gpa: std.mem.Allocator,
+ kind: Kind = .changes,
/// What its answer is made with: the shell's, which frees a batch.
out: std.mem.Allocator,
gen: u32,
@@ -400,11 +497,15 @@ pub const Ask = struct {
rev: []u8,
revset: []u8,
- fn make(gpa: std.mem.Allocator, gen: u32, serial: u32, path: []const u8, rev: []const u8, revset: []const u8) error{OutOfMemory}!*Ask {
+ /// `Changes`' (with who wrote each line), or `Churn`'s (with jj's text
+ /// of the revision, which the counts are lined up with).
+ pub const Kind = enum(u8) { changes, churn };
+
+ fn make(gpa: std.mem.Allocator, kind: Kind, gen: u32, serial: u32, path: []const u8, rev: []const u8, revset: []const u8) error{OutOfMemory}!*Ask {
const a = try gpa.create(Ask);
errdefer gpa.destroy(a);
const owned = try std.mem.concat(gpa, u8, &.{ path, rev, revset });
- a.* = .{ .gpa = gpa, .out = gpa, .gen = gen, .serial = serial, .path = owned[0..path.len], .rev = owned[path.len..][0..rev.len], .revset = owned[path.len + rev.len ..] };
+ a.* = .{ .gpa = gpa, .kind = kind, .out = gpa, .gen = gen, .serial = serial, .path = owned[0..path.len], .rev = owned[path.len..][0..rev.len], .revset = owned[path.len + rev.len ..] };
return a;
}
@@ -421,6 +522,7 @@ pub const Ask = struct {
/// `Changes` is asked, then one update while nothing is asked of jj.
pub const Session = struct {
answers: std.ArrayList(Changes) = .empty,
+ heats: std.ArrayList(Heat) = .empty,
task: ?Task = null,
next: ?*Ask = null,
count: u32 = 0,
@@ -430,6 +532,7 @@ pub const Session = struct {
const bits: u64 = c.count | @as(u64, @intFromBool(c.task != null)) << 32 | @as(u64, @intFromBool(c.next != null)) << 33;
h.update(std.mem.asBytes(&bits));
pardes.walk.hash(std.ArrayList(Changes), &c.answers, h);
+ pardes.walk.hash(std.ArrayList(Heat), &c.heats, h);
if (c.task) |*t| pardes.walk.hash(Task, t, h);
if (c.next) |n| pardes.walk.hash(Ask, n, h);
}
@@ -448,6 +551,8 @@ pub const Session = struct {
}
for (c.answers.items) |*a| a.deinit(gpa);
c.answers.deinit(gpa);
+ for (c.heats.items) |*h| h.deinit(gpa);
+ c.heats.deinit(gpa);
}
};
@@ -470,10 +575,10 @@ fn liveGen(c: *const Session) u32 {
/// Ask jj of `revset` for pane `serial` (said at pane `id` while it runs):
/// what the pane shows stays until the answer lands.
-fn ask(p: *Pardes, id: usize, serial: u32, path: []const u8, rev: []const u8, revset: []const u8) void {
+fn ask(p: *Pardes, kind: Ask.Kind, id: usize, serial: u32, path: []const u8, rev: []const u8, revset: []const u8) void {
p.changes.count +%= 1;
- const a = Ask.make(p.gpa, liveGen(&p.changes), serial, path, rev, revset) catch return p.reportFailure(id, "Changes: out of memory");
- p.setStatus(.at(id), "Changes: jj\u{2026}");
+ const a = Ask.make(p.gpa, kind, liveGen(&p.changes), serial, path, rev, revset) catch return p.reportFailure(id, "Changes: out of memory");
+ p.setStatus(.at(id), if (kind == .churn) "Churn: jj\u{2026}" else "Changes: jj\u{2026}");
if (p.changes.task != null) {
if (p.changes.next) |old| old.deinit();
p.changes.next = a;
@@ -550,6 +655,14 @@ fn answer(p: ?*Pardes, gpa: std.mem.Allocator, a: *const Ask) pardes.Stream.Batc
if (if (entryOf(l)) |e| e.pinned else false) break true;
} else false;
if (!any) return .{ .gen = a.gen, .rows = logged, .end = .done };
+ // Churn: jj's text of the revision, to line the counts up with the pane's.
+ if (a.kind == .churn) return switch (runJj(p, gpa, dirOf(a.path), &.{ "file", "show", "-r", a.rev, "--", set })) {
+ .refused => |why| {
+ gpa.free(logged);
+ return failed(gpa, a, why);
+ },
+ .bytes => |shown| .{ .gen = a.gen, .rows = logged, .styles = shown, .end = .done },
+ };
// Who wrote each line: a path, not a fileset (annotate takes one file
// as it is named).
const annotate_args = [_][]const u8{ "file", "annotate", "-r", a.rev, "-T", "commit.change_id().short(8) ++ \"\\t\" ++ content", "--", std.Io.Dir.path.basename(a.path) };
@@ -575,17 +688,19 @@ fn runJj(p: ?*Pardes, gpa: std.mem.Allocator, dir: []const u8, args: []const []c
}
/// A `Changes` answer (`Event.search` with a `Changes` generation),
-/// borrowed: the last asked's is parsed and pinned on its pane (the ask
-/// names it); an earlier one's, or a gone pane's, dropped. Then the one
-/// asked meanwhile goes.
+/// borrowed: the last asked of its kind is parsed and pinned (or counted,
+/// a `Churn`'s) on its pane (the ask names it); an earlier one's, or a gone
+/// pane's, dropped. Then the one asked meanwhile goes.
pub fn receive(p: *Pardes, b: *const pardes.Stream.Batch) void {
var revset: [Changes.revset_max]u8 = undefined;
var revset_len: usize = 0;
var serial: u32 = 0;
+ var kind: Ask.Kind = .changes;
if (p.changes.task) |t| if (t.ask.gen == b.gen) {
p.changes.task = null;
if (t.future) |f| pardes.Stream.join(f, t.io.?, .wait);
serial = t.ask.serial;
+ kind = t.ask.kind;
revset_len = t.ask.revset.len;
@memcpy(revset[0..revset_len], t.ask.revset);
t.ask.deinit();
@@ -594,9 +709,14 @@ pub fn receive(p: *Pardes, b: *const pardes.Stream.Batch) void {
p.changes.next = null;
go(p, next);
};
- if (b.gen != liveGen(&p.changes) or revset_len == 0) return;
+ if (revset_len == 0) return;
+ // A later one of its kind asked meanwhile: only that one is shown.
+ if (p.changes.next) |n| if (n.kind == kind) return;
const id = p.paneBySerial(serial) orelse return;
- pinAnswer(p, id, b, revset[0..revset_len]);
+ switch (kind) {
+ .changes => pinAnswer(p, id, b, revset[0..revset_len]),
+ .churn => heatAnswer(p, id, b, revset[0..revset_len]),
+ }
}
/// A splice of `f`'s text, before its bytes go in (File.edit, the one
@@ -619,6 +739,18 @@ pub fn edited(p: *Pardes, f: *const File.State, off: usize, len: usize, bytes: [
showGhosts(p, p.panes[id].?);
};
}
+ i = p.changes.heats.items.len;
+ while (i > 0) {
+ i -= 1;
+ const h = &p.changes.heats.items[i];
+ const id = p.paneBySerial(h.serial) orelse continue;
+ const shown = if (p.panes[id].?.file) |*shown| shown else continue;
+ if (shown.content.ptr != f.content.ptr) continue;
+ _ = spliceValues(u16, p.gpa, &h.lines, 0, f.content, off, len, bytes) catch {
+ h.deinit(p.gpa);
+ _ = p.changes.heats.swapRemove(i);
+ };
+ }
}
/// `c`'s values spliced as `text`'s lines are by the splice of `len` bytes
@@ -628,20 +760,10 @@ pub fn edited(p: *Pardes, f: *const File.State, off: usize, len: usize, bytes: [
/// before it. Else the line it starts in keeps its value, and the lines
/// taken and put come after it.
fn splice(gpa: std.mem.Allocator, c: *Changes, text: []const u8, off: usize, len: usize, bytes: []const u8) error{OutOfMemory}!void {
- const taken = std.mem.count(u8, text[off..][0..len], "\n");
- const put = std.mem.count(u8, bytes, "\n");
- if (taken == 0 and put == 0) return;
- const line_start = if (std.mem.lastIndexOfScalar(u8, text[0..off], '\n')) |nl| nl + 1 else 0;
- const in_lead = std.mem.trimStart(u8, text[line_start..off], " \t").len == 0;
- const from = std.mem.count(u8, text[0..line_start], "\n") + @intFromBool(!in_lead);
- if (from > c.lines.len) return;
- const take = @min(taken, c.lines.len - from);
- const next = try gpa.alloc(Line, c.lines.len - take + put);
- @memcpy(next[0..from], c.lines[0..from]);
- @memset(next[from..][0..put], .{ .pin = .none });
- @memcpy(next[from + put ..], c.lines[from + take ..]);
- gpa.free(c.lines);
- c.lines = next;
+ const cut = try spliceValues(Line, gpa, &c.lines, .{ .pin = .none }, text, off, len, bytes) orelse return;
+ const from = cut.from;
+ const take = cut.take;
+ const put = cut.put;
// A ghost row stands before the line it stood before; one before a
// line taken out, before the line after what took its place.
for (c.ghosts) |*g| {
@@ -650,6 +772,26 @@ fn splice(gpa: std.mem.Allocator, c: *Changes, text: []const u8, off: usize, len
}
}
+/// A value a line, `values`, spliced as `splice` says, a line put in
+/// `none`; null when no line is taken or put.
+fn spliceValues(comptime T: type, gpa: std.mem.Allocator, values: *[]T, none: T, text: []const u8, off: usize, len: usize, bytes: []const u8) error{OutOfMemory}!?struct { from: usize, take: usize, put: usize } {
+ const taken = std.mem.count(u8, text[off..][0..len], "\n");
+ const put = std.mem.count(u8, bytes, "\n");
+ if (taken == 0 and put == 0) return null;
+ const line_start = if (std.mem.lastIndexOfScalar(u8, text[0..off], '\n')) |nl| nl + 1 else 0;
+ const in_lead = std.mem.trimStart(u8, text[line_start..off], " \t").len == 0;
+ const from = std.mem.count(u8, text[0..line_start], "\n") + @intFromBool(!in_lead);
+ if (from > values.len) return null;
+ const take = @min(taken, values.len - from);
+ const next = try gpa.alloc(T, values.len - take + put);
+ @memcpy(next[0..from], values.*[0..from]);
+ @memset(next[from..][0..put], none);
+ @memcpy(next[from + put ..], values.*[from + take ..]);
+ gpa.free(values.*);
+ values.* = next;
+ return .{ .from = from, .take = take, .put = put };
+}
+
/// jj's answer `b` for `revset` parsed and pinned on pane `id`, or its
/// refusal said there.
fn pinAnswer(p: *Pardes, id: usize, b: *const pardes.Stream.Batch, revset: []const u8) void {
@@ -689,6 +831,118 @@ fn pinAnswer(p: *Pardes, id: usize, b: *const pardes.Stream.Batch, revset: []con
}
}
+/// jj's answer `b` for a `Churn` of `window` on pane `id`, kept raw
+/// until the text's declarations are there (a worker's parse,
+/// Stream.parseFor: a big file's parse is seconds in a Debug build, never
+/// the loop's), then counted (`count`); or its refusal said there.
+fn heatAnswer(p: *Pardes, id: usize, b: *const pardes.Stream.Batch, window: []const u8) void {
+ const pane = p.panes[id].?;
+ var line: pardes.Kind.Buf(512) = .{};
+ if (pane.file == null) return;
+ if (b.end == .failed) {
+ if (churned(p, pane.serial) == null) pane.layers.heat = 0;
+ return p.reportFailure(id, line.print("Churn: {s}", .{b.rows[0..@min(b.rows.len, 480)]}));
+ }
+ var heat: Heat = .{ .serial = pane.serial, .revset_len = @intCast(window.len) };
+ @memcpy(heat.revset[0..window.len], window);
+ heat.pending = std.mem.concat(p.gpa, u8, &.{ b.rows, b.styles }) catch return p.reportFailure(id, "Churn: out of memory");
+ heat.pending_was = @intCast(b.rows.len);
+ if (churned(p, pane.serial)) |kept| {
+ kept.deinit(p.gpa);
+ kept.* = heat;
+ } else p.changes.heats.append(p.gpa, heat) catch {
+ heat.deinit(p.gpa);
+ pane.layers.heat = 0;
+ return p.reportFailure(id, "Churn: out of memory");
+ };
+ parsed(p, pane.serial);
+}
+
+/// A parse of pane `serial`'s text landed (Stream.receiveParse), or jj's
+/// answer did: a `Churn` waiting on it counted when the declarations are of
+/// the text as it is, else a parse of it asked.
+pub fn parsed(p: *Pardes, serial: u32) void {
+ const h = churned(p, serial) orelse return;
+ if (h.pending.len == 0) return;
+ const id = p.paneBySerial(serial) orelse return;
+ const pane = p.panes[id].?;
+ const f = if (pane.file) |*file| file else return;
+ var line: pardes.Kind.Buf(512) = .{};
+ if (!syntax.supportsPath(f.path)) {
+ // No grammar for it (a revision's pane too: its name ends `@rev`).
+ p.reportFailure(id, line.print("Churn: no declarations to count in {s}", .{std.Io.Dir.path.basename(f.path)}));
+ pane.layers.heat = 0;
+ return forgetHeat(p, serial);
+ }
+ if (f.context.revision != f.revision) return pardes.Stream.parseFor(p, id);
+ const lines = heatOf(p.gpa, p.scratch.allocator(), h.pending[0..h.pending_was], h.pending[h.pending_was..], f.content, f.context.declarations, &h.hottest) catch |err| return p.reportFailure(id, line.print("Churn: {s}", .{@errorName(err)}));
+ p.gpa.free(h.pending);
+ h.pending = &.{};
+ h.lines = lines;
+ if (h.hottest > 0) return p.setStatus(.at(id), "");
+ p.reportFailure(id, line.print("Churn: no change of `{s}` touches a declaration of {s}", .{ h.window(), std.Io.Dir.path.basename(File.langPath(f)) }));
+ pane.layers.heat = 0;
+ forgetHeat(p, serial);
+}
+
+/// For each line of `text` (`decls` its declarations), how many of the window's
+/// changes in `logged` (jj's log, `p` the window's, `c` a later change
+/// that only carries places) touched the declaration it is in: tree-
+/// sitter's innermost, a line in none 0. A change's hunk touches the lines
+/// it wrote, carried into the revision jj showed (`was`) through the later
+/// changes' hunks, then into `text` (`Moved`); a hunk that only took lines
+/// away, the line above where they stood. Each change counts once a
+/// declaration. `hottest`: the largest count.
+fn heatOf(gpa: std.mem.Allocator, arena: std.mem.Allocator, logged: []const u8, was: []const u8, text: []const u8, decls: []const syntax.ContextDeclaration, hottest: *u16) error{OutOfMemory}![]u16 {
+ var hunks: std.ArrayList(Hunk) = .empty;
+ var removed: std.ArrayList(u8) = .empty;
+ var windowed: std.ArrayList(bool) = .empty;
+ var starts: std.ArrayList(usize) = .empty;
+ var it = std.mem.splitScalar(u8, logged, '\n');
+ while (it.next()) |l| if (entryOf(l)) |e| {
+ if (windowed.items.len == Hunk.carrier) break;
+ try windowed.append(arena, e.pinned);
+ try starts.append(arena, it.index orelse logged.len);
+ };
+ try starts.append(arena, logged.len);
+ for (starts.items[0 .. starts.items.len - 1], starts.items[1..], 0..) |from, to, i|
+ try hunksOf(arena, arena, Hunk.carrier, @intCast(i), logged[from..to], text, &.{}, &hunks, &removed, undefined, undefined);
+ const n = lineCount(text);
+ const moved: Moved = .of(was, text);
+ // Each line's innermost declaration (outermost first, so an inner one
+ // writes over its container's lines).
+ const none = std.math.maxInt(u32);
+ const inner = try arena.alloc(u32, n);
+ @memset(inner, none);
+ for (decls, 0..) |d, k| {
+ if (d.start_line >= n) continue;
+ @memset(inner[d.start_line..@min(n, d.end_line + 1)], @intCast(k));
+ }
+ const counts = try arena.alloc(u16, decls.len);
+ @memset(counts, 0);
+ // The last change each declaration was counted for.
+ const seen = try arena.alloc(u32, decls.len);
+ @memset(seen, none);
+ for (hunks.items) |h| {
+ if (!windowed.items[h.step] or n == 0) continue;
+ const a = carried(hunks.items, h.step, h.new_start -| 1 + @intFromBool(h.new_len == 0), moved) orelse continue;
+ const b = carried(hunks.items, h.step, h.new_start -| 1 + h.new_len, moved) orelse continue;
+ const lo = @min(if (h.new_len == 0) a -| 1 else a, n - 1);
+ for (inner[lo..@max(lo + 1, @min(b, n))]) |k| {
+ if (k == none or seen[k] == h.step) continue;
+ seen[k] = h.step;
+ counts[k] +|= 1;
+ }
+ }
+ const out = try gpa.alloc(u16, n);
+ hottest.* = 0;
+ for (out, inner) |*o, k| {
+ o.* = if (k == none) 0 else counts[k];
+ hottest.* = @max(hottest.*, o.*);
+ }
+ return out;
+}
+
/// The pane's ghost rows as its geometry reads them (`Pane.ghosts`): the
/// session's answers' (one set a pane), its geometry made again when they
/// change (each step while a view shows them, and as an answer lands).
@@ -808,21 +1062,10 @@ pub fn provenance(gpa: std.mem.Allocator, arena: std.mem.Allocator, annotated: [
if (!std.mem.endsWith(u8, annotated, "\n") and was.items.len > 0) was.items.len -= 1;
const out = try gpa.alloc(Line, lineCount(text));
@memset(out, .{ .pin = .none });
- const was_n: u32 = @intCast(owners.items.len);
- if (std.mem.eql(u8, was.items, text)) {
- for (out[0..@min(out.len, owners.items.len)], owners.items[0..@min(out.len, owners.items.len)]) |*l, pin| l.pin = pin;
- moved.* = .{ .head = was_n, .tail = 0, .was = was_n, .now = was_n };
- return out;
- }
- const span = File.spanOf(was.items, text);
- const head = @min(std.mem.count(u8, was.items[0..span.head], "\n"), out.len, owners.items.len);
- for (out[0..head], owners.items[0..head]) |*l, pin| l.pin = pin;
- var tail = @min(tailLines(was.items, span.tail), out.len - head, owners.items.len - head);
- // The line the two ends meet inside (an insertion before it shares its
- // indent with the line above) is the same line when its bytes are.
- if (head + tail < @min(out.len, owners.items.len) and std.mem.eql(u8, lineFromEnd(was.items, tail), lineFromEnd(text, tail))) tail += 1;
+ moved.* = .of(was.items, text);
+ for (out[0..@min(moved.head, owners.items.len)], owners.items[0..@min(moved.head, owners.items.len)]) |*l, pin| l.pin = pin;
+ const tail = @min(moved.tail, owners.items.len);
for (out[out.len - tail ..], owners.items[owners.items.len - tail ..]) |*l, pin| l.pin = pin;
- moved.* = .{ .head = @intCast(head), .tail = @intCast(tail), .was = was_n, .now = @intCast(out.len) };
return out;
}
@@ -837,6 +1080,21 @@ pub const Moved = struct {
was: u32,
now: u32,
+ /// `was` (jj's text) lined up with `text` by what they agree on at
+ /// either end (`File.spanOf`, the editor's differ).
+ pub fn of(was: []const u8, text: []const u8) Moved {
+ const was_n: u32 = @intCast(lineCount(was));
+ const now: u32 = @intCast(lineCount(text));
+ if (std.mem.eql(u8, was, text)) return .{ .head = was_n, .tail = 0, .was = was_n, .now = was_n };
+ const span = File.spanOf(was, text);
+ const head = @min(std.mem.count(u8, was[0..span.head], "\n"), now, was_n);
+ var tail = @min(tailLines(was, span.tail), now - head, was_n - head);
+ // The line the two ends meet inside (an insertion before it shares its
+ // indent with the line above) is the same line when its bytes are.
+ if (head + tail < @min(now, was_n) and std.mem.eql(u8, lineFromEnd(was, tail), lineFromEnd(text, tail))) tail += 1;
+ return .{ .head = @intCast(head), .tail = @intCast(tail), .was = was_n, .now = now };
+ }
+
/// The text's place of jj's place `at` (before its line `at`), or null
/// inside lines rewritten since: no place there tells the truth.
fn place(m: Moved, at: u32) ?u32 {
@@ -914,7 +1172,6 @@ fn hunksOf(gpa: std.mem.Allocator, arena: std.mem.Allocator, k: u16, step: u16,
else => return,
};
};
- const syntax = @import("syntax.zig");
var said = std.mem.splitScalar(u8, patch.text, '\n');
var run_from = taken.items.len;
var plus_from = added.items.len;
@@ -1017,13 +1274,13 @@ fn ghostsOf(gpa: std.mem.Allocator, arena: std.mem.Allocator, pins: []const Pin,
ti += h.old_len;
// A changed line's old text right above the line; a line taken
// away whole above the next changed one's, or after the run.
- var at = carried(hunks, h.pin, if (h.new_len > 0) h.new_start - 1 + h.new_len else h.new_start, moved);
+ var at = carried(hunks, h.step, if (h.new_len > 0) h.new_start - 1 + h.new_len else h.new_start, moved);
var ats: [max_run]?u32 = undefined;
if (run.len > max_run) continue;
var k = run.len;
while (k > 0) {
k -= 1;
- if (run[k].paired) at = run[k].shown orelse carried(hunks, h.pin, run[k].new -| 1, moved);
+ if (run[k].paired) at = run[k].shown orelse carried(hunks, h.step, run[k].new -| 1, moved);
ats[k] = at;
}
var from: usize = h.removed;
@@ -1055,11 +1312,13 @@ fn ghostsOf(gpa: std.mem.Allocator, arena: std.mem.Allocator, pins: []const Pin,
}
var first: u32 = 0;
var end: u32 = 0;
+ var step: u16 = 0;
for (hunks) |h| if (h.pin == k) {
if (first == 0) first = h.new_start;
end = if (h.new_len > 0) h.new_start - 1 + h.new_len else h.new_start;
+ step = h.step;
};
- const place = at orelse carried(hunks, @intCast(k), end, moved) orelse continue;
+ const place = at orelse carried(hunks, step, end, moved) orelse continue;
// After its own ghost rows at its place.
for (made.items) |m| if (m.g.pin == k and m.g.at == place) {
rank = m.rank | 1;
@@ -1081,15 +1340,12 @@ fn ghostsOf(gpa: std.mem.Allocator, arena: std.mem.Allocator, pins: []const Pin,
return out;
}
-/// Where the place after line `after` of pin `k`'s revision is in the
-/// text: moved by each later change's hunks before it (a pin's, or one
+/// Where the place after line `after` of step `from`'s revision (its
+/// change's place in jj's answer, `Hunk.step`) is in the text: moved by each later change's hunks before it (a pin's, or one
/// between the pins the revset does not pin), or, inside a run of lines a
/// later one took away, after what it wrote there; then from jj's lines
/// to the text's (`moved`).
-fn carried(hunks: []const Hunk, k: u16, after: u32, moved: Moved) ?u32 {
- const from = for (hunks) |h| {
- if (h.pin == k) break h.step;
- } else 0;
+fn carried(hunks: []const Hunk, from: u16, after: u32, moved: Moved) ?u32 {
var pos: i64 = after;
var i: usize = 0;
while (i < hunks.len) {
@@ -1290,7 +1546,7 @@ fn nest(lines: []Line, npins: usize) void {
/// orange go). Distinct colours, never one between two.
pub fn laneColours(th: *const pardes.Theme, buf: *[8][3]u8) []const [3]u8 {
const pal = th.palette;
- const grounds = [2][3]u8{ if (pal) |c| c[1] else .{ 0xcf, 0x22, 0x2e }, if (pal) |c| c[2] else .{ 0x2e, 0xa0, 0x43 } };
+ const grounds = [2][3]u8{ themeRed(th), if (pal) |c| c[2] else .{ 0x2e, 0xa0, 0x43 } };
const accents: [6][3]u8 = if (pal) |c| .{ c[3], c[4], c[5], c[6], th.num, th.kw } else .{ th.kw, th.num, th.str, th.box, th.column_box orelse th.box, th.comment };
var sorted: [6][3]u8 = undefined;
var n: usize = 0;
@@ -1347,6 +1603,64 @@ fn hueApart(a: [3]u8, b: [3]u8) f32 {
/// (`Ghost`) its lanes and its cells (`inkGhost`). Not yet: a changed
/// line's words.
pub fn paint(p: *Pardes, s: *pardes.Surface, pane: *Pane, r: pardes.Rect, tx: u16, tw: u16, body_h: u16) void {
+ if (pane.layers.heat > 0) paintHeat(p, s, pane, r, tx, body_h);
+ if (pane.layers.lanes > 0) paintLanes(p, s, pane, r, tx, tw, body_h);
+}
+
+/// The theme's red: what a change took away; churn's top.
+pub fn themeRed(th: *const pardes.Theme) [3]u8 {
+ return if (th.palette) |c| c[1] else .{ 0xcf, 0x22, 0x2e };
+}
+
+/// A count's colour on churn's gradient: smooth from the line numbers'
+/// grey to the theme's red, on a log scale of the count against the
+/// hottest; null for none.
+fn heatColour(th: *const pardes.Theme, count: u16, hottest: u16) ?[3]u8 {
+ if (count == 0 or hottest == 0) return null;
+ const t = @log(@as(f32, @floatFromInt(count)) + 1) / @log(@as(f32, @floatFromInt(hottest)) + 1);
+ return pardes.colors.mixOklab(th.lineno, themeRed(th), t);
+}
+
+/// The heat lane: a cell after the line number (before the changes'
+/// lanes, which stay next to the text they mark), a half block in its
+/// line's colour; none on a ghost row or a line in no declaration.
+fn paintHeat(p: *Pardes, s: *pardes.Surface, pane: *Pane, r: pardes.Rect, tx: u16, body_h: u16) void {
+ const heat = churned(p, pane.serial) orelse return;
+ const x = tx + File.gutterWidth(pane) - File.laneCells(pane) - 1;
+ const body_y = p.bodyTop(pane, r);
+ const scroll = pane.scroll();
+ var vr: u16 = pane.context_rows;
+ while (vr < body_h) : (vr += 1) {
+ const row: i32 = if (pane.wrap_n == 0) scroll + @as(i32, vr) else if (vr < pane.wrap_n) pane.wrap_line[vr] else break;
+ if (vr < pane.wrap_n and pane.wrap_col[vr] < 0) continue;
+ if (row < 0 or row >= heat.lines.len) continue;
+ const rgb = heatColour(p.theme(), heat.lines[@intCast(row)], heat.hottest) orelse continue;
+ var style = s.at(x, body_y + vr).style;
+ style.fg = .{ .rgb = rgb };
+ s.set(x, body_y + vr, "\u{258c}", style);
+ }
+}
+
+/// Churn's strip by the scroll thumb (draw.zig, while a view shows it): a
+/// rail row each, the hottest line of the lines that row stands for; in a
+/// terminal the rail's second cell's ground, for a pixel shell a list
+/// (Surface.heat).
+pub fn railHeat(p: *Pardes, s: *pardes.Surface, pane: *Pane, id: usize, rail: pardes.Rect) void {
+ const heat = churned(p, pane.serial) orelse return;
+ const total = heat.lines.len;
+ if (rail.h == 0 or total == 0) return;
+ for (0..rail.h) |row| {
+ const lo = row * total / rail.h;
+ const hi = @max(lo + 1, (row + 1) * total / rail.h);
+ const rgb = heatColour(p.theme(), std.mem.max(u16, heat.lines[lo..@min(hi, total)]), heat.hottest) orelse continue;
+ if (p.view().frontend.windowed)
+ s.heat.append(p.gpa, .{ .owner = @intCast(id), .row = @intCast(row), .rgb = rgb }) catch {}
+ else
+ s.fill(rail.x + 1, rail.y + @as(u16, @intCast(row)), 1, 1, .{ .bg = .{ .rgb = rgb } });
+ }
+}
+
+fn paintLanes(p: *Pardes, s: *pardes.Surface, pane: *Pane, r: pardes.Rect, tx: u16, tw: u16, body_h: u16) void {
const ch = answered(p, pane.serial) orelse return;
if (ch.lines.len == 0) return;
var buf: [8][3]u8 = undefined;
@@ -1702,7 +2016,7 @@ const WorkerJj = struct {
/// answer the session's input, as its loop hands it, and the client's.
fn land(w: *WorkerJj) !void {
var waited: u32 = 0;
- while (w.a.core.changes.task != null or w.a.core.changes.next != null) : (waited += 1) {
+ while (w.a.core.changes.task != null or w.a.core.changes.next != null or w.a.core.stream.parse != null) : (waited += 1) {
if (waited == 5000) return error.Timeout;
var batch: Inbox.Batch = .{};
w.shell.q.takeInto(&batch);
@@ -2238,6 +2552,127 @@ test "the lanes ride with the text: a line typed in a nested block is nobody's,
try testing.expectEqual(pardes.tape.digestOf(a.core), pardes.tape.digestOf(r.core()));
}
+/// Two functions four changes wrote: `fn` both, `f2` and `f3` rewrote
+/// f's line, `g2` g's: f three changes, g two.
+const Churned = struct {
+ const fn_text = "fn f() void {\n a();\n}\n\nfn g() void {\n b();\n}\n";
+ const f2_text = "fn f() void {\n a2();\n}\n\nfn g() void {\n b();\n}\n";
+ const f3_text = "fn f() void {\n a3();\n}\n\nfn g() void {\n b();\n}\n";
+ const g2_text = "fn f() void {\n a3();\n}\n\nfn g() void {\n b2();\n}\n";
+
+ fn repo() !?Repo {
+ return Repo.with(testing.allocator, &.{ .{ fn_text, "fn" }, .{ f2_text, "f2" }, .{ f3_text, "f3" }, .{ g2_text, "g2" } }, null);
+ }
+};
+
+test "Churn counts the changes that touched each declaration and draws them after the line number and by the scroll thumb, grey to red on a log scale; bare again, off" {
+ const gpa = testing.allocator;
+ var repo = try Churned.repo() orelse return error.SkipZigTest;
+ defer repo.deinit(gpa);
+ for ([_]bool{ false, true }) |windowed| {
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 24, .windowed = windowed });
+ defer p.deinit();
+ var line: [4200]u8 = undefined;
+ p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}", .{repo.file}) });
+ const id = p.view().active;
+ const pane = p.panes[id].?;
+ const before = File.gutterWidth(pane);
+ p.update(.{ .command = "Churn" });
+ const heat = churned(p, pane.serial).?;
+ try testing.expectEqualSlices(u16, &.{ 3, 3, 3, 0, 2, 2, 2 }, heat.lines);
+ try testing.expectEqual(@as(u16, 3), heat.hottest);
+ try testing.expectEqual(before + 1, File.gutterWidth(pane));
+ // Drawn: a cell after the number, f's the theme's red, g's along
+ // the way from the numbers' grey at ln 3 / ln 4, none between.
+ p.sync();
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ const s = try p.render(arena.allocator());
+ const body = s.region(.body, id).?.rect;
+ const x = body.x + File.gutterWidth(pane) - 1;
+ const red = themeRed(p.theme());
+ const warm = pardes.colors.mixOklab(p.theme().lineno, red, @log(3.0) / @log(4.0));
+ for (0..7) |row| {
+ const cell = s.at(x, body.y + @as(u16, @intCast(row)));
+ if (row == 3) {
+ try testing.expectEqualStrings(" ", cell.grapheme());
+ continue;
+ }
+ try testing.expectEqualStrings("\u{258c}", cell.grapheme());
+ try testing.expectEqual(pardes.Color{ .rgb = if (row < 3) red else warm }, cell.style.fg);
+ }
+ // By the scroll thumb: the rail's first row holds f's lines.
+ const rail = s.region(.rail, id).?.rect;
+ if (windowed) {
+ const strip = for (s.heat.items) |h| {
+ if (h.owner == id and h.row == 0) break h;
+ } else return error.TestExpectedEqual;
+ try testing.expectEqual(red, strip.rgb);
+ } else try testing.expectEqual(pardes.Color{ .rgb = red }, s.at(rail.x + 1, rail.y).style.bg);
+ // Bare again: hidden, the gutter as it was; again: shown, jj not asked.
+ p.update(.{ .command = "Churn" });
+ try testing.expectEqual(before, File.gutterWidth(pane));
+ p.update(.{ .command = "Churn" });
+ try testing.expectEqual(before + 1, File.gutterWidth(pane));
+ try testing.expectEqual(heat, churned(p, pane.serial).?);
+ }
+}
+
+test "Churn's window: a revset, or a span of time back from now; jj's refusal said" {
+ const gpa = testing.allocator;
+ var repo = try Churned.repo() orelse return error.SkipZigTest;
+ defer repo.deinit(gpa);
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 24, .windowed = false });
+ defer p.deinit();
+ var line: [4200]u8 = undefined;
+ p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}", .{repo.file}) });
+ const id = p.view().active;
+ const pane = p.panes[id].?;
+ // f3 and g2 alone: one each.
+ p.update(.{ .command = "Churn @--::@" });
+ try testing.expectEqualSlices(u16, &.{ 1, 1, 1, 0, 1, 1, 1 }, churned(p, pane.serial).?.lines);
+ // The last week: all four, just made.
+ p.update(.{ .command = "Churn 1w" });
+ try testing.expectEqualSlices(u16, &.{ 3, 3, 3, 0, 2, 2, 2 }, churned(p, pane.serial).?.lines);
+ try testing.expectEqualStrings("::(@) & author_date(after:\"1 weeks ago\")", churned(p, pane.serial).?.window());
+ p.update(.{ .command = "Churn nosuch" });
+ try testing.expect(std.mem.indexOf(u8, told(p, id), "Churn: Revision `nosuch` doesn't exist") != null);
+}
+
+test "Churn on a worker: jj's answer kept raw, counted when the worker's parse of the text lands; the client equal" {
+ var repo = try Churned.repo() orelse return error.SkipZigTest;
+ defer repo.deinit(testing.allocator);
+ var w = try WorkerJj.init(&repo, "");
+ defer w.deinit();
+ try w.word("Churn");
+ try w.land();
+ try testing.expectEqualSlices(u16, &.{ 3, 3, 3, 0, 2, 2, 2 }, churned(w.a.core, w.serial).?.lines);
+ try testing.expectEqualSlices(u16, churned(w.a.core, w.serial).?.lines, churned(w.r.core(), w.serial).?.lines);
+}
+
+test "Churn's counts ride with the text, and a client replays them equal" {
+ var repo = try Churned.repo() orelse return error.SkipZigTest;
+ defer repo.deinit(testing.allocator);
+ const R = pardes.replica;
+ const a = try R.Authority.init(testing.allocator, .{ .cols = 80, .rows = 24 }, .{}, false);
+ defer a.deinit();
+ const r = try R.Replica.init(testing.allocator, 1, try a.unit(0, 0), false);
+ defer r.deinit();
+ var line: [4200]u8 = undefined;
+ r.confirm(try a.local(.{ .command = try std.fmt.bufPrint(&line, "Look {s}", .{repo.file}) }));
+ r.confirm(try a.local(.{ .command = "Churn" }));
+ r.settle();
+ const serial = a.core.panes[a.core.view().active].?.serial;
+ // `a3();` deleted: its value goes with it.
+ r.confirm(try a.local(.{ .command = "Look a.zig:2" }));
+ for (";xd") |k| r.confirm(try a.local(.{ .key = .{ .cp = k, .text = &[_]u8{k} } }));
+ r.settle();
+ try testing.expectEqualSlices(u16, &.{ 3, 3, 0, 2, 2, 2 }, churned(a.core, serial).?.lines);
+ try testing.expect(r.diverged == null);
+ try testing.expectEqualSlices(u16, churned(a.core, serial).?.lines, churned(r.core(), serial).?.lines);
+ try testing.expectEqual(pardes.tape.digestOf(a.core), pardes.tape.digestOf(r.core()));
+}
+
test "a B3 click on path@rev:line in running text opens the file at that revision there" {
const gpa = testing.allocator;
var repo = try Repo.init(gpa) orelse return error.SkipZigTest;
diff --git a/core/root.zig b/core/root.zig
index e29e70d8..f2c97d35 100644
--- a/core/root.zig
+++ b/core/root.zig
@@ -55,6 +55,7 @@ pub const Facts = @import("surface.zig").Facts;
pub const Region = @import("surface.zig").Region;
pub const Chrome = @import("surface.zig").Chrome;
pub const RailTick = @import("surface.zig").RailTick;
+pub const RailHeat = @import("surface.zig").Heat;
pub const Lane = @import("surface.zig").Lane;
pub const MAX_REGIONS = @import("surface.zig").MAX_REGIONS;
/// What comes in (Event.zig).
diff --git a/core/surface.zig b/core/surface.zig
index 653abd82..3ab9a933 100644
--- a/core/surface.zig
+++ b/core/surface.zig
@@ -151,6 +151,9 @@ pub const max_rail_ticks = 4096;
/// it as a strip in gutter cell `x`, at its `level`'s place (sample A of
/// the ruled design: each a third of a cell wide, half that of air between).
pub const Lane = struct { x: u16, y: u16, level: u8, rgb: [3]u8 };
+/// Churn's strip on a rail (jj.railHeat): a pixel shell draws its row of
+/// pane `owner`'s rail, beside the track, in `rgb`.
+pub const Heat = struct { owner: u8, row: u16, rgb: [3]u8 };
pub const rail_tick_scale = 1024;
pub const Chrome = struct {
@@ -266,6 +269,9 @@ pub const Surface = struct {
/// makes many a temporary Surface, and a safe build fills an array's
/// `undefined` in each).
lanes: std.ArrayList(Lane) = .empty,
+ /// Churn's strips by the scroll thumbs, for a pixel shell (in a
+ /// terminal the rail's cells), as `lanes`.
+ heat: std.ArrayList(Heat) = .empty,
chrome: Chrome = .{},
cells: []Cell = &.{},
/// bar: draw an insert-style thin cursor instead of the block
diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig
index bdbd7880..5d1dc03a 100644
--- a/dev/gui/gui.zig
+++ b/dev/gui/gui.zig
@@ -4893,7 +4893,7 @@ fn buildDecor(g: *Gui, gpa: std.mem.Allocator, surface: *const pardes.Surface, g
else => {},
} else false;
if (grid_bottom < win_h and tag_last) try addDecor(g, gpa, 0, grid_bottom, win_w, win_h, chrome.tag_bg, 1, win_w, win_h);
- try paneDecor(g, gpa, regions, surface.rail_ticks[0..surface.nrail_ticks], chrome, layout, surface.cols, surface.rows, win_w, win_h);
+ try paneDecor(g, gpa, regions, surface.rail_ticks[0..surface.nrail_ticks], surface.heat.items, chrome, layout, surface.cols, surface.rows, win_w, win_h);
// The changes' lanes (jj.paint): a strip a level in the gutter's
// lane cells, each a third of a cell wide with half that of air
// before it, so three take one and a half cells (the ruled
@@ -4936,7 +4936,7 @@ fn buildDecor(g: *Gui, gpa: std.mem.Allocator, surface: *const pardes.Surface, g
/// Each pane's rule between its tag and body, and its scroll rail: a page
/// coloured gutter with a thin track and its thumb, running down through the
/// pixels past the last whole row.
-fn paneDecor(g: *Gui, gpa: std.mem.Allocator, regions: []const pardes.Region, ticks: []const pardes.RailTick, chrome: *const pardes.Chrome, layout: CellLayout, cols: u16, rows: u16, win_w: f32, win_h: f32) !void {
+fn paneDecor(g: *Gui, gpa: std.mem.Allocator, regions: []const pardes.Region, ticks: []const pardes.RailTick, heat: []const pardes.RailHeat, chrome: *const pardes.Chrome, layout: CellLayout, cols: u16, rows: u16, win_w: f32, win_h: f32) !void {
const page = chrome.page orelse bg_default;
for (regions) |rail| {
if (rail.kind != .rail or rail.rect.h == 0) continue;
@@ -5015,6 +5015,14 @@ fn paneDecor(g: *Gui, gpa: std.mem.Allocator, regions: []const pardes.Region, ti
const ty = y0 + std.math.clamp(at * track_px, 0, track_px - h);
try addDecor(g, gpa, column[0], ty, column[1], ty + h, if (tick.current) chrome.match_current else chrome.match_tick, 1, win_w, win_h);
};
+ // Churn's strip (jj.railHeat): beside the track, at the rail's
+ // right edge, a rail row each.
+ const strip_x1 = x0 + @as(f32, @floatFromInt(config.GUTTER)) * layout.w - dp(1);
+ const strip_x0 = @max(column[1], strip_x1 - dp(2));
+ for (heat) |h| if (h.owner == rail.owner and h.row < rail.rect.h) {
+ const hy = y0 + @as(f32, @floatFromInt(h.row)) * layout.h;
+ try addDecor(g, gpa, strip_x0, hy, strip_x1, hy + layout.h, h.rgb, 1, win_w, win_h);
+ };
}
}
diff --git a/docs/typ/builtins-gui.json b/docs/typ/builtins-gui.json
index ad1f98df..aeaf6953 100644
--- a/docs/typ/builtins-gui.json
+++ b/docs/typ/builtins-gui.json
@@ -10,7 +10,8 @@
{"name": "Callstack", "leader": "SPC l b", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Show outermost callers first, with signatures and call sites (gc)."},
{"name": "CallstackDepth", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": null, "doc": "Caller levels collected by Callstack, 1 through 64; default 8. Bare, it says the current limit."},
{"name": "Changelog", "leader": "SPC h c", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "This build's version and what changed to reach it, printed into an output buffer the same way Config prints the live settings."},
- {"name": "Changes", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Pin the changes `revset` names (jj) on a file's pane and show them in this view: a lane each after the line number, a line one added whole green, what the file no longer has drawn where it stood (ghost rows: a line taken away whole red, each change's description after its last line); bare, shown here or not (none pinned yet: `@`)."},
+ {"name": "Changes", "leader": "SPC t c", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Pin the changes `revset` names (jj) on a file's pane and show them in this view: a lane each after the line number, a line one added whole green, what the file no longer has drawn where it stood (ghost rows: a line taken away whole red, each change's description after its last line); bare, shown here or not (none pinned yet: `@`)."},
+ {"name": "Churn", "leader": "SPC t u", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Count, for each declaration of a file's pane, the changes in `window` (jj) that touched it, and show it in this view: a heat lane after the line number and a strip by the scroll thumb, the line numbers' grey to the theme's red on a log scale; `window` a revset or a span of time (`3d`, `2w`, `6m`, `1y`); bare, shown here or not (none counted yet: the file's whole history)."},
{"name": "ClipPaste", "leader": "SPC p", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Paste the system clipboard after the selection."},
{"name": "ClipPasteBefore", "leader": "SPC P", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Paste the system clipboard before the selection."},
{"name": "ClipReplace", "leader": "SPC R", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Replace the selection with the system clipboard."},
diff --git a/docs/typ/builtins-tui.json b/docs/typ/builtins-tui.json
index 3ec4ea07..2263df44 100644
--- a/docs/typ/builtins-tui.json
+++ b/docs/typ/builtins-tui.json
@@ -10,7 +10,8 @@
{"name": "Callstack", "leader": "SPC l b", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Show outermost callers first, with signatures and call sites (gc)."},
{"name": "CallstackDepth", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": null, "doc": "Caller levels collected by Callstack, 1 through 64; default 8. Bare, it says the current limit."},
{"name": "Changelog", "leader": "SPC h c", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "This build's version and what changed to reach it, printed into an output buffer the same way Config prints the live settings."},
- {"name": "Changes", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Pin the changes `revset` names (jj) on a file's pane and show them in this view: a lane each after the line number, a line one added whole green, what the file no longer has drawn where it stood (ghost rows: a line taken away whole red, each change's description after its last line); bare, shown here or not (none pinned yet: `@`)."},
+ {"name": "Changes", "leader": "SPC t c", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Pin the changes `revset` names (jj) on a file's pane and show them in this view: a lane each after the line number, a line one added whole green, what the file no longer has drawn where it stood (ghost rows: a line taken away whole red, each change's description after its last line); bare, shown here or not (none pinned yet: `@`)."},
+ {"name": "Churn", "leader": "SPC t u", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Count, for each declaration of a file's pane, the changes in `window` (jj) that touched it, and show it in this view: a heat lane after the line number and a strip by the scroll thumb, the line numbers' grey to the theme's red on a log scale; `window` a revset or a span of time (`3d`, `2w`, `6m`, `1y`); bare, shown here or not (none counted yet: the file's whole history)."},
{"name": "ClipPaste", "leader": "SPC p", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Paste the system clipboard after the selection."},
{"name": "ClipPasteBefore", "leader": "SPC P", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Paste the system clipboard before the selection."},
{"name": "ClipReplace", "leader": "SPC R", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Replace the selection with the system clipboard."},
diff --git a/docs/typ/cheatsheet.typ b/docs/typ/cheatsheet.typ
index 2df92b00..d65ca6d9 100644
--- a/docs/typ/cheatsheet.typ
+++ b/docs/typ/cheatsheet.typ
@@ -101,6 +101,8 @@ Helix-style: motions *select*, then an edit acts on the selection. Mode box: bla
key("SPC t t"), word("Themes"),
key("SPC t n"), word("NextColor"),
key("SPC t w"), word("Wrap"),
+ key("SPC t c"), word("Changes"),
+ key("SPC t u"), word("Churn"),
key("SPC c n"), word("Newcol"),
key("SPC s d"), word("Dump"),
key("SPC s r"), word("Restore"),
@@ -117,6 +119,7 @@ Helix-style: motions *select*, then an edit acts on the selection. Mode box: bla
== Reviewing diffs
`git diff` output is a diff: #btn("B3") on a file line, an `@@` or a line's `+`/`-` jumps there. #doc("tags", section: "reviewing-diffs")
+#word("Changes") `revset` on a file's pane: a lane a change, ghost rows for what it took away, #keys("] g", "[ g") from change to change; #word("Churn") `3m`: each declaration's changes, grey to red; `a.zig@main:12` is a file at a revision. #doc("guide", section: "changes")
== Finding things
- A query pane under the pane: line 1 the query, its first word the source: `/pat`, `Find name` (fuzzy), `Grep text` (literal), `Recent`, `Panes`, `Symbols`, `All`. #keys("Ctrl-n", "Ctrl-p") step, #key("Enter") lands and keeps the rows, #key("Esc") puts things back. #word("Help"), #word("Tutor").
diff --git a/docs/typ/guide.typ b/docs/typ/guide.typ
index 0d55c6a6..e73eabaf 100644
--- a/docs/typ/guide.typ
+++ b/docs/typ/guide.typ
@@ -295,24 +295,57 @@ the revision has not) is said in jj's words. jj reads the working copy as
it last saw it (`@`): pardes never snapshots it.
#word("Syntax") (#key("SPC t h")) turns a text's syntax colours off in
this view, and on again.
-#word("Changes") with a revset pins its changes on a file's pane (or a
-revision's) and shows them in this view (one set a pane: another view's
-revset replaces it there too); bare, they are hidden in this view or shown
-again, and with none pinned yet it is `@`, the change against its parent. Each change that touched the file gets a lane after the
-line number, from its first line to its last, in the theme's accents in
-hue order, oldest first; a change that rewrote lines inside another's
-steps a lane to the right on those rows; a line one added whole is green
-across the line. What the file no longer has is drawn where it stood, a
-ghost row with no number: a line a change took away whole, red across;
-each change's description (`id title author age`) after its last line, in
-its lane's colour. The cursor steps over ghost rows, search and selection
-do not see them, and a Look on one opens its line in the revision it came
-from. `]g` and `[g` go to the next and the previous change. jj answers
-once, when the word is run: the lanes and the ghost rows ride with the
-lines through edits made since. A line a change changed is not green across: its
-old text stands right above it as a ghost row, the words that went red,
-and on the line the words that came are green (the patch view's
-alignment says which lines are one line changed).
+
+= Changes on the source view <changes>
+
+jj's changes drawn on a file's own pane, as layers each view wears or
+not: the text stays the text (the patch view, `+Diff`, is unchanged).
+Nothing is shown, and nothing asked of jj, until a word is run.
+
+#pairs(
+ [#word("Changes") `revset` (#key("SPC t c"))], [pins the revset's changes that touched the file on its pane (or a revision's) and shows them in this view; one set a pane (another view's revset replaces it there too). Bare: hidden in this view or shown again; with none pinned yet, `@`, the change against its parent],
+ [#word("Churn") `window` (#key("SPC t u"))], [counts, for each declaration, the window's changes that touched it, and shows them in this view; the window a revset, or a span of time back from now (`3d`, `2w`, `6m`, `1y`). Bare: hidden or shown again; with none counted yet, the file's whole history],
+ [#keys("] g", "[ g")], [the next and the previous change's first line],
+ [`path@rev`, `path@rev:line`], [the file at a revision (#doc("guide", section: "revision")): a #word("Look") anywhere opens it],
+)
+
+*Lanes.* Each pinned change gets a lane after the line number, from its
+first line to its last, in the theme's accents in hue order (a colour too
+close to the one before it skipped), oldest first; a change that rewrote
+lines inside another's steps a lane to the right on those rows. A line
+one added whole is green across the line.
+
+*Ghost rows.* What the file no longer has is drawn where it stood, a row
+of its own with no number: a line a change took away whole, red across;
+a line a change changed, its old text right above it with the words that
+went red, and on the line the words that came green (the patch view's
+alignment says which lines are one line changed); each change's
+description, `id title author age` (`3w`, `4m`), after its last line, in
+its lane's colour, at one place after that change's own ghost rows. A
+ghost row is not text: the cursor steps over it, search, selection and
+the line numbers do not see it, and a #btn("B3") on one opens its line in
+the revision it came from (`path@id-:line`; a description, `path@id`). It
+moves the rows below down in this view alone. It is one row, cut where
+the pane ends (never wrapped); in a narrow pane a description's title is
+cut, its author and age kept. A hunk that took away more than 1,024
+lines shows none of them.
+
+*Churn.* A cell after the line number, from the line numbers' grey to the
+theme's red on a log scale of the count against the file's hottest
+declaration, the declaration a line is in being the innermost
+tree-sitter finds (a line in none has none); beside the scroll thumb a
+strip, each of its rows the hottest of the lines it stands for. With
+#word("Changes") on too, the churn's cell comes first and the lanes stay
+next to the text they mark. A file's history is followed by its name:
+what it had under another name before a move is not counted.
+
+jj answers once, when the word is run, on a worker (the editor goes on);
+its answer is lined up with the pane's text as it is then (lines typed
+before jj's last snapshot or while it ran), and the lanes, ghost rows and
+counts ride with the lines through the edits made since. A place inside
+lines rewritten since jj's snapshot has no ghost row. A change between
+two pinned ones that the revset does not pin still moves the older ones'
+ghost rows to where they stand.
= Call hierarchy <callstack>