diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-18 23:49:29 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-19 01:35:13 -0300 |
| commit | 1ca3e68f38385952fa5a2ccc3dac883ba0be71e8 (patch) | |
| tree | bffbbf9e5e5b2b929d79bd81ea805c5288896623 /core/hunks.zig | |
| parent | e567aadc19f58b1e36098388483294321f3502dd (diff) | |
| download | pardes-1ca3e68f38385952fa5a2ccc3dac883ba0be71e8.tar.gz pardes-1ca3e68f38385952fa5a2ccc3dac883ba0be71e8.zip | |
core: nothing of a core is a process global, the three that were (pardes-probes P3, the reorganisation's 12c): config.tab_now goes, a tab's width is the core's settings.tab handed to every width function as `tab` (File.graphemeDisplayWidth and the 73 functions above it, test helpers among them, that had no core to read it from gained the parameter; an Editor, a Surface and the hunks' Ctx carry it; render sets Surface.tab; graphemeDisplayWidth asks its one printable ASCII byte before the tab, the two disjoint: with the tab first, as before, the parameter cost 0.2-1.7% instructions an operation in pardes-perf, with ASCII first the measured cells use 2-16% fewer than the base), so a rollback can no longer leave a stale width and replica.zig's hand-made put-back in toConfirmed goes; Addon.distrusted/ndistrusted become Addon.Distrusted, the client's own list, which its frontend owns across its joins and hands each core as Options.distrusted (in no tape, dump or digest: Options' replica .local); Kind.draw_tokens becomes each slot's `draws` (local: a draw is a frame's, so each process's count differs and no digest may hold it; the copy saves it with the slot); the two turn reads in a step stay, being shown unable to reach a client's state (the report); the soak's Proc keeps only the client's list (its tab_now and the global swaps go, forced); test/perf.zig follows three signatures, so unit-test's perf check now says BaselineHarnessMismatch until the baselines are recorded again; tui core-test 824/966 (142 skipped), shell-test 1001/1004, pane-test 183/184, behaviour-test 274/274 and --replay 274/274, process-test 2 of 144 failed (lspcomplete, lspcompletemoved), replicas --clients 5 diverged 0 unequal 0 deltas wrong 0 quiet differ 0 at 30/80/207 ms, gui unit-test 1598/1602, lib-test, daemon.py plain, --far, --games, --window-clients pass
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/hunks.zig')
| -rw-r--r-- | core/hunks.zig | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/core/hunks.zig b/core/hunks.zig index 186ba928..d3a8f5a7 100644 --- a/core/hunks.zig +++ b/core/hunks.zig @@ -37,6 +37,8 @@ pub const Ctx = struct { /// A declaration above a hunk gets its `path:line` row too /// (LocationsConfig's tslocations). tslocations: bool, + /// A tab's width in cells (the core's `settings.tab`). + tab: u16, }; /// A file's text, and its path as `dir` and the path named resolve. @@ -346,7 +348,7 @@ fn flush(ctx: *const Ctx, out: *Out, hunk: *Hunk, memo: *SourceMemo, dir: []cons while (i < lines.len and lines[i].kind == .removed) i += 1; const plus_start = i; while (i < lines.len and lines[i].kind == .added) i += 1; - try inferEdits(arena, lines[minus_start..plus_start], lines[plus_start..i]); + try inferEdits(ctx.tab, arena, lines[minus_start..plus_start], lines[plus_start..i]); } // Each line behind its marker, `+`, `-` or a blank, as the diff @@ -390,7 +392,7 @@ const pair_scratch_bytes = 8 << 20; /// Pair each removed line with the first added line after the last one /// paired that is near enough to it, in order, and emphasise in both the /// tokens one has and the other has not. -fn inferEdits(arena: std.mem.Allocator, minus: []HunkLine, plus: []HunkLine) !void { +fn inferEdits(tab: u16, arena: std.mem.Allocator, minus: []HunkLine, plus: []HunkLine) !void { if (minus.len == 0 or plus.len == 0 or minus.len > max_run or plus.len > max_run) return; const plus_tokens = try arena.alloc([]const []const u8, plus.len); for (plus, plus_tokens) |line, *tokens| tokens.* = try tokenize(arena, line.code); @@ -408,7 +410,7 @@ fn inferEdits(arena: std.mem.Allocator, minus: []HunkLine, plus: []HunkLine) !vo scratch.reset(); const pair = scratch.allocator(); var alignment = Alignment.init(pair, m_tokens, p_tokens) catch continue; - const marks = annotate(pair, &alignment, m.code, plus[j].code) catch continue; + const marks = annotate(tab, pair, &alignment, m.code, plus[j].code) catch continue; if (marks.distance > max_line_distance) continue; for (marks.minus) |r| for (m.styles[r[0]..r[1]]) |*b| { b.* |= syntax.ground_emph; @@ -534,7 +536,7 @@ const Marks = struct { /// what each deleted and inserted, and a run of blanks between two changes /// with them; the distance is the changed width over the whole width (a /// kept section counting on both lines). -fn annotate(arena: std.mem.Allocator, a: *const Alignment, minus_line: []const u8, plus_line: []const u8) !Marks { +fn annotate(tab: u16, arena: std.mem.Allocator, a: *const Alignment, minus_line: []const u8, plus_line: []const u8) !Marks { var minus: std.ArrayList([2]usize) = .empty; var plus: std.ArrayList([2]usize) = .empty; var x_off: usize = 0; @@ -560,7 +562,7 @@ fn annotate(arena: std.mem.Allocator, a: *const Alignment, minus_line: []const u switch (op) { .deletion => { const r = Take.section(a.x, &x_off, &m_byte, n, minus_line); - const w = trimmedWidth(minus_line[r[0]..r[1]]); + const w = trimmedWidth(tab, minus_line[r[0]..r[1]]); numer += w; denom += w; try minus.append(arena, r); @@ -569,7 +571,7 @@ fn annotate(arena: std.mem.Allocator, a: *const Alignment, minus_line: []const u .noop => { const r = Take.section(a.x, &x_off, &m_byte, n, minus_line); const section = minus_line[r[0]..r[1]]; - denom += 2 * trimmedWidth(section); + denom += 2 * trimmedWidth(tab, section); const is_space = std.mem.trim(u8, section, " \t").len == 0; const coalesce = is_space and ((minus_prev == .deletion and plus_prev == .insertion and @@ -583,7 +585,7 @@ fn annotate(arena: std.mem.Allocator, a: *const Alignment, minus_line: []const u }, .insertion => { const r = Take.section(a.y, &y_off, &p_byte, n, plus_line); - const w = trimmedWidth(plus_line[r[0]..r[1]]); + const w = trimmedWidth(tab, plus_line[r[0]..r[1]]); numer += w; denom += w; try plus.append(arena, r); @@ -595,8 +597,8 @@ fn annotate(arena: std.mem.Allocator, a: *const Alignment, minus_line: []const u return .{ .minus = minus.items, .plus = plus.items, .distance = distance }; } -fn trimmedWidth(section: []const u8) usize { - return @import("File.zig").displayWidth(std.mem.trim(u8, section, " \t")); +fn trimmedWidth(tab: u16, section: []const u8) usize { + return @import("File.zig").displayWidth(tab, std.mem.trim(u8, section, " \t")); } // ---- the +Diff in the editor ---- @@ -734,6 +736,7 @@ pub fn openDiff(p: *Pardes, id: usize, path: []const u8, content: []const u8) !u .declarations = Read.declarations, .host = p, .tslocations = p.locations_config.tslocations, + .tab = p.settings.tab, }; const root = sourceRoot(&ctx, dir, content); const result = try format(&ctx, root, content); @@ -793,7 +796,7 @@ const TestCtx = struct { fn init(t: *TestCtx) void { t.arena_state = .init(testing.allocator); - t.ctx = .{ .gpa = testing.allocator, .arena = t.arena_state.allocator(), .source = source, .declarations = declarations, .host = t, .tslocations = true }; + t.ctx = .{ .gpa = testing.allocator, .arena = t.arena_state.allocator(), .source = source, .declarations = declarations, .host = t, .tslocations = true, .tab = @import("config.zig").tab_width }; syntax.start(testing.allocator); } @@ -819,7 +822,7 @@ fn emphasised(line: HunkLine) ![]const u8 { return out.toOwnedSlice(testing.allocator); } -fn expectEmphasis(minus: []const u8, plus: []const u8, want_minus: []const u8, want_plus: []const u8) !void { +fn expectEmphasis(tab: u16, minus: []const u8, plus: []const u8, want_minus: []const u8, want_plus: []const u8) !void { var arena_state: std.heap.ArenaAllocator = .init(testing.allocator); defer arena_state.deinit(); const arena = arena_state.allocator(); @@ -827,7 +830,7 @@ fn expectEmphasis(minus: []const u8, plus: []const u8, want_minus: []const u8, w var p = [_]HunkLine{.{ .kind = .added, .code = plus, .styles = try arena.alloc(u8, plus.len), .old = 2, .new = 1 }}; @memset(m[0].styles, 0); @memset(p[0].styles, 0); - try inferEdits(arena, &m, &p); + try inferEdits(tab, arena, &m, &p); const got_minus = try emphasised(m[0]); defer testing.allocator.free(got_minus); const got_plus = try emphasised(p[0]); @@ -837,16 +840,16 @@ fn expectEmphasis(minus: []const u8, plus: []const u8, want_minus: []const u8, w } test "delta's emphasis: the word a line changed, in both lines" { - try expectEmphasis(" let x = foo(1);", " let x = bar(1);", "............foo....", "............bar...."); - try expectEmphasis("a b c", "a x c", "..b..", "..x.."); + try expectEmphasis(@import("config.zig").tab_width, " let x = foo(1);", " let x = bar(1);", "............foo....", "............bar...."); + try expectEmphasis(@import("config.zig").tab_width, "a b c", "a x c", "..b..", "..x.."); } test "delta's emphasis: lines too far apart are no change of one another" { - try expectEmphasis("completely different text", "nothing alike here at all", ".........................", "........................."); + try expectEmphasis(@import("config.zig").tab_width, "completely different text", "nothing alike here at all", ".........................", "........................."); } test "delta's emphasis: a word added keeps the rest plain" { - try expectEmphasis("fn run(a: u32)", "fn run(a: u32, b: u32)", "..............", "............., b: u32."); + try expectEmphasis(@import("config.zig").tab_width, "fn run(a: u32)", "fn run(a: u32, b: u32)", "..............", "............., b: u32."); } test "delta's alignment: kitten to sitting, as align.rs has it" { |
