diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-09 02:04:25 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-09 02:14:10 -0300 |
| commit | c78d362fa20393621ac198861f891439f9d832e9 (patch) | |
| tree | 7ba6d82f7dca1926abf7a985cf3830c69d21c90c /src/Query.zig | |
| parent | 69b993d585cfb14c607f46aba500b141b85516ff (diff) | |
| download | pardes-c78d362fa20393621ac198861f891439f9d832e9.tar.gz pardes-c78d362fa20393621ac198861f891439f9d832e9.zip | |
locality: caller-led moves: MAX_JUMPS into Jump.zig (Core's unused alias goes), RasterPolicy and rasterPolicy beside Kind.viewOf, Names.relative beside Query.startSource, fs.find_skip beside Stream's max_walk_depth, File.drawGutter and drawWrapMarkers beside body_layer.renderBody; each unit's only users are in its new file
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.zig | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/Query.zig b/src/Query.zig index 1bb5792a..77119ca9 100644 --- a/src/Query.zig +++ b/src/Query.zig @@ -542,6 +542,12 @@ fn searchable(tp: *const Pane) bool { return true; } +fn relative(path: []const u8, dir: []const u8) []const u8 { + const d = std.mem.trimEnd(u8, dir, "/"); + if (d.len > 0 and path.len > d.len + 1 and std.mem.startsWith(u8, path, d) and path[d.len] == '/') return path[d.len + 1 ..]; + return path; +} + /// A source begun: its candidates gathered (names), its walk started. fn startSource(p: *Pardes, id: usize, q: *Query, source: Source, owner_id: ?usize) void { const rp = p.panes[id].?; @@ -563,7 +569,7 @@ fn startSource(p: *Pardes, id: usize, q: *Query, source: Source, owner_id: ?usiz var lines = std.mem.splitScalar(u8, pardes.tape.authority(recentRows, .{ p, &out }), '\n'); while (lines.next()) |ln| { if (ln.len == 0) continue; - const rel = Names.relative(ln, dir); + const rel = relative(ln, dir); const path_end = std.mem.indexOfAny(u8, rel, ": ") orelse rel.len; q.names.add(gpa, rel, 0, path_end, Names.baseOf(rel[0..path_end]), 0) catch break; } @@ -574,7 +580,7 @@ fn startSource(p: *Pardes, id: usize, q: *Query, source: Source, owner_id: ?usiz if (other == rp or other.query != null) continue; var buf: [4096 + 32]u8 = undefined; const what: []const u8 = if (other.file) |f| f.path else if (other.command) |c| c else other.cwdSlice(); - const row = std.fmt.bufPrint(&buf, config.pane_addr ++ "{d} {s}", .{ other.serial, Names.relative(what, dir) }) catch continue; + const row = std.fmt.bufPrint(&buf, config.pane_addr ++ "{d} {s}", .{ other.serial, relative(what, dir) }) catch continue; const key_at = std.mem.indexOfScalar(u8, row, ' ').? + 1; const ln = row[0 .. std.mem.indexOfAny(u8, row, "\r\n") orelse row.len]; q.names.add(gpa, ln, key_at, ln.len -| key_at, Names.baseOf(ln[@min(key_at, ln.len)..]), other.serial) catch break; @@ -585,7 +591,7 @@ fn startSource(p: *Pardes, id: usize, q: *Query, source: Source, owner_id: ?usiz // session's, which a replica has from the authority. for (pardes.tape.authority(Store.closedNames, .{p})) |c| { var buf: [4096 + 48]u8 = undefined; - const row = std.fmt.bufPrint(&buf, config.pane_addr ++ "{d} {s}" ++ closed_word, .{ c.serial, Names.relative(c.name, dir) }) catch continue; + const row = std.fmt.bufPrint(&buf, config.pane_addr ++ "{d} {s}" ++ closed_word, .{ c.serial, relative(c.name, dir) }) catch continue; const key_at = std.mem.indexOfScalar(u8, row, ' ').? + 1; const key_len = row.len - closed_word.len - key_at; q.names.add(gpa, row, key_at, key_len, Names.baseOf(row[key_at..][0..key_len]), c.serial) catch break; @@ -871,7 +877,7 @@ fn addressOf(arena: std.mem.Allocator, tp: *const Pane) []const u8 { /// relative one that climbs. pub fn lookPath(buf: []u8, path: []const u8, dir: []const u8) []const u8 { // a relative pane's (a test's): its directory's prefix off, as ever - if (path.len == 0 or path[0] != '/' or dir.len == 0 or dir[0] != '/') return Names.relative(path, dir); + if (path.len == 0 or path[0] != '/' or dir.len == 0 or dir[0] != '/') return relative(path, dir); const d = std.mem.trimEnd(u8, dir, "/"); // the last slash both share, ending a whole component of `dir` var k: usize = 0; @@ -1055,7 +1061,7 @@ fn makeAllRows(p: *Pardes, id: usize) !void { q.total += set.hits.items.len; q.more = q.more or !set.complete(); 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 name = if (tp.file) |f| relative(f.path, std.Io.Dir.path.dirname(rp.file.?.path) orelse "") else ""; 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 }); |
