summaryrefslogtreecommitdiff
path: root/src/Query.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 14:39:47 -0300
committerGabriel Schneider <[email protected]>2026-11-06 14:56:36 -0300
commite8e7ed956f3914a3790e980df0862b26c30bd611 (patch)
tree53d3247c594717f79745ad20c5dd23bf16ed59ea /src/Query.zig
parenta821fe82d8de3d407ebe104358b97719bd983727 (diff)
downloadpardes-e8e7ed956f3914a3790e980df0862b26c30bd611.tar.gz
pardes-e8e7ed956f3914a3790e980df0862b26c30bd611.zip
idioms #20, the bound in the type or the cut handled: of the 166 `catch unreachable` the pass kept, 64 stay where a reader checks the bound without arithmetic (an integer's digits, a declared field's size, and now the daemon's pid lists and the clock's two-digit fields written in their types), 69 texts print through Kind.Buf at their old size, 31 handle the failure once (a print into ename cut at its 320, paneText's line cut where its buffer fills, a log record or mouse report dropped rather than cut short, the question's letters that fit), Newcol's and pane/new's refusals are comptime strings, and dropUnsaved's too-long scratch name is null, not an empty sentinel
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/Query.zig')
-rw-r--r--src/Query.zig24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/Query.zig b/src/Query.zig
index abcf147e..1bb5792a 100644
--- a/src/Query.zig
+++ b/src/Query.zig
@@ -936,8 +936,8 @@ fn writePlacesRows(p: *Pardes, q: *Query, out: *std.ArrayList(u8), rows: *std.Ar
const head_le = if (decls[di].start_line + 1 < index.len) index[decls[di].start_line + 1] - 1 else f.content.len;
const head = std.mem.trim(u8, f.content[head_ls..head_le], " \t\r");
// Its address too, `rel:line`, in the column the hits' are.
- var hb: [8192]u8 = undefined;
- const address = std.fmt.bufPrint(&hb, "{s}:{d}", .{ rel[0..@min(rel.len, 4096)], decls[di].start_line + 1 }) catch unreachable; // 4096 and a line fit 8192
+ var hb: [4096 + 4096]u8 = undefined;
+ const address = std.fmt.bufPrint(&hb, "{s}:{d}", .{ rel[0..@min(rel.len, 4096)], decls[di].start_line + 1 }) catch unreachable; // rel cut at the first 4096, a colon and a usize in the second
const gutter = @max(width, address.len) + 2;
const shown = head[0..@min(head.len, hb.len -| gutter)];
@memset(hb[address.len..gutter], ' ');
@@ -974,8 +974,8 @@ fn makeTextRows(p: *Pardes, id: usize, oid: usize, full: bool) !void {
const from = if (full) 0 else at -| 2;
if (set.started and set.from == rp.serial) {
if (from > 0) {
- var hb: [64]u8 = undefined;
- try noteRow(p, q, &out, &rows, std.fmt.bufPrint(&hb, " ... {d} places before these", .{from}) catch unreachable); // a usize fits
+ var hb: pardes.Kind.Buf(64) = .{};
+ try noteRow(p, q, &out, &rows, hb.print(" ... {d} places before these", .{from}));
}
try writePlacesRows(p, q, &out, &rows, owner, std.Io.Dir.path.dirname(rp.file.?.path) orelse "/", from, &budget);
}
@@ -1054,9 +1054,9 @@ fn makeAllRows(p: *Pardes, id: usize) !void {
}
q.total += set.hits.items.len;
q.more = q.more or !set.complete();
- var hb: [600]u8 = undefined;
+ var hb: pardes.Kind.Buf(600) = .{};
const name = if (tp.file) |f| Names.relative(f.path, std.Io.Dir.path.dirname(rp.file.?.path) orelse "") else "";
- const head = std.fmt.bufPrint(&hb, config.pane_addr ++ "{d} {s} ({d})", .{ tp.serial, name[0..@min(name.len, 500)], set.hits.items.len }) catch unreachable; // 500 and 44 fit 600
+ const head = hb.print(config.pane_addr ++ "{d} {s} ({d})", .{ tp.serial, name[0..@min(name.len, 500)], set.hits.items.len });
try q.items.append(p.gpa, .{ .kind = .header, .serial = tp.serial });
try writeRow(p, &out, &rows, head, .{ .kind = .context, .declaration = true, .path = @constCast(addressOf(p.scratch.allocator(), tp)), .at = .{}, .location_end = 0, .code_start = 0 });
try writePlacesRows(p, q, &out, &rows, tp, std.Io.Dir.path.dirname(rp.file.?.path) orelse "/", 0, &budget);
@@ -1174,8 +1174,8 @@ fn makeGrepRows(p: *Pardes, id: usize, full: bool) !void {
const lo = if (full) 0 else at -| 2;
const hi = if (full) q.found.items.len else @min(q.found.items.len, lo + live_rows);
if (lo > 0) {
- var hb: [64]u8 = undefined;
- try noteRow(p, q, &out, &rows, std.fmt.bufPrint(&hb, " ... {d} lines before these", .{lo}) catch unreachable); // a usize fits
+ var hb: pardes.Kind.Buf(64) = .{};
+ try noteRow(p, q, &out, &rows, hb.print(" ... {d} lines before these", .{lo}));
}
var current: ?usize = null;
var sh: Shades = .{};
@@ -1203,8 +1203,8 @@ fn makeGrepRows(p: *Pardes, id: usize, full: bool) !void {
try writeHitRow(p, &out, &rows, &sh, width, rel, path, fd.line, code, fd.col, fd.end, &.{});
}
if (hi < q.found.items.len) {
- var hb: [64]u8 = undefined;
- try noteRow(p, q, &out, &rows, std.fmt.bufPrint(&hb, " ... {d} lines after these", .{q.found.items.len - hi}) catch unreachable); // a usize fits
+ var hb: pardes.Kind.Buf(64) = .{};
+ try noteRow(p, q, &out, &rows, hb.print(" ... {d} lines after these", .{q.found.items.len - hi}));
}
if (p.stream.target == rp.serial and p.stream.state == .capped) try noteRow(p, q, &out, &rows, " ... stopped at 2000 lines: More in the tag goes on");
try skippedRow(p, q, rp, &out, &rows);
@@ -1222,8 +1222,8 @@ fn makeGrepRows(p: *Pardes, id: usize, full: bool) !void {
fn skippedRow(p: *Pardes, q: *Query, rp: *Pane, out: *std.ArrayList(u8), rows: *std.ArrayList(locations.Row)) !void {
const n = p.stream.skipped;
if (p.stream.target != rp.serial or n == 0) return;
- var hb: [96]u8 = undefined;
- try noteRow(p, q, out, rows, std.fmt.bufPrint(&hb, " {d} director{s} skipped: permission denied", .{ n, if (n == 1) "y" else "ies" }) catch unreachable); // a usize and 40 fit 96
+ var hb: pardes.Kind.Buf(96) = .{};
+ try noteRow(p, q, out, rows, hb.print(" {d} director{s} skipped: permission denied", .{ n, if (n == 1) "y" else "ies" }));
}
/// `k` for a Grep: the current row's line among all the lines sent.