diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-04 23:07:25 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-04 23:07:26 -0300 |
| commit | 398270fb7e121cbaab9e264a39bc83b5d32c40c7 (patch) | |
| tree | 3b1be9a8d97874ede9e62ecb4d0ac42ff3aa1329 /src/Query.zig | |
| parent | cdbb06a5de858a721bdbfa127ea839f791b0dc24 (diff) | |
| download | pardes-398270fb7e121cbaab9e264a39bc83b5d32c40c7.tar.gz pardes-398270fb7e121cbaab9e264a39bc83b5d32c40c7.zip | |
locations: one appendRow copies a row's path and colours onto a list being built, for appendMetadata, hunks' Out.row and Query's writeRow, which each copied, appended and freed on failure by hand
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/Query.zig')
| -rw-r--r-- | src/Query.zig | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/src/Query.zig b/src/Query.zig index 5fdfff2a..87c9d3bd 100644 --- a/src/Query.zig +++ b/src/Query.zig @@ -676,27 +676,20 @@ fn noteRows(p: *Pardes, id: usize, note: []const u8) void { setRows(p, rp, &out, &rows); } -/// One row: its text and its metadata, the path copied. +/// One row: its text and its metadata, the path and colours copied. fn writeRow(p: *Pardes, out: *std.ArrayList(u8), rows: *std.ArrayList(locations.Row), text: []const u8, meta: locations.Row) !void { try out.appendSlice(p.gpa, text); try out.append(p.gpa, '\n'); - var m = meta; - m.path = try p.gpa.dupe(u8, meta.path); - errdefer p.gpa.free(m.path); // Coloured whole (zeros where nothing coloured it): the pane's syntax // pass then parses no fragment of it, per refill. const code = text[@min(meta.code_start, text.len)..]; - m.colors = if (meta.colors.len >= code.len) try p.gpa.dupe(u8, meta.colors[0..code.len]) else blk: { - const c = try p.gpa.alloc(u8, code.len); - @memset(c, 0); - @memcpy(c[0..meta.colors.len], meta.colors); - break :blk c; - }; - rows.append(p.gpa, m) catch |err| { - p.gpa.free(m.path); - p.gpa.free(m.colors); - return err; - }; + var m = meta; + if (meta.colors.len >= code.len) m.colors = meta.colors[0..code.len] else { + m.colors = try p.scratch.allocator().alloc(u8, code.len); + @memset(m.colors, 0); + @memcpy(m.colors[0..meta.colors.len], meta.colors); + } + try locations.appendRow(p.gpa, rows, m); } /// The rows made into the pane: line 1 as it is (the user's), then `out`, |
