From 55492ffa53d7df11a38c6639f8fde6cdc87800c7 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 23:43:45 -0300 Subject: Find, Grep: their output traits, Output's sort of a Find's whole filenames above its walk notes, and fs.WalkNotes go, as both search on the disk engine (Stream.zig, which keeps the walk's depth as max_walk_depth) and nothing makes a .cmd = .Find or .Grep pane; the tests that filled one fill a .search or query pane (ctl.zig's is now "workspace symbols, Symbols and Diagnostics share their directory's one +Search"), and the Find sort test keeps its half on next location ("next location uses numeric columns") Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/Output.zig | 25 ++++--------------------- src/Stream.zig | 4 +++- src/builtins.zig | 2 -- src/fs.zig | 36 ------------------------------------ src/ninep/ctl.zig | 4 ++-- 5 files changed, 9 insertions(+), 62 deletions(-) (limited to 'src') diff --git a/src/Output.zig b/src/Output.zig index 7c8b7f59..cee15dcd 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -241,8 +241,6 @@ test "plain output does not opt into location decoration" { try std.testing.expectEqualDeep(RowDecoration{}, prose); const errors = rowDecoration(.{ .from = .errors }, "src/a.rs:3:5-7 error: prose"); try std.testing.expectEqualDeep(RowDecoration{}, errors); - try std.testing.expect(!traits(.{ .cmd = .Find }).locations); - try std.testing.expect(traits(.{ .cmd = .Grep }).locations); try std.testing.expect(traits(.{ .query = .completion }).locations); } @@ -299,7 +297,6 @@ pub fn traits(o: Origin) Traits { pub fn usesLocationsConfig(from: Origin) bool { const tr = traits(from); return tr.steps and !tr.commands and from != .pdf_links and - !std.meta.eql(from, Origin{ .cmd = .Find }) and !std.meta.eql(from, Origin{ .query = .completion }) and !std.meta.eql(from, Origin{ .query = .callstack }); } @@ -353,10 +350,7 @@ pub fn isResultRow(file: *const File.State, row: usize) bool { fn sortResults(arena: std.mem.Allocator, from: Origin, content: []u8, anchor: ?usize) !?usize { switch (from) { .search => {}, - .cmd => |cmd| switch (cmd) { - .Find, .Grep => {}, - else => return anchor, - }, + .cmd => return anchor, .query => |kind| switch (kind) { .definition, .declaration, @@ -379,16 +373,6 @@ fn sortResults(arena: std.mem.Allocator, from: Origin, content: []u8, anchor: ?u .errors, .pdf_links, .unsaved, .dir, .preview => return anchor, } if (content.len == 0) return anchor; - const path_only = std.meta.eql(from, Origin{ .cmd = .Find }); - // A walk's notes (fs.WalkNotes) stay under the hits: only the rows - // above the first are sorted. - if (path_only) { - var off: usize = 0; - var it = std.mem.splitScalar(u8, content, '\n'); - while (it.next()) |line| : (off += line.len + 1) if (@import("fs.zig").WalkNotes.isNote(line)) { - return if (off == 0) anchor else sortResults(arena, from, content[0..off], anchor); - }; - } const trailing_newline = content[content.len - 1] == '\n'; const body = content[0 .. content.len - @intFromBool(trailing_newline)]; var lines = std.mem.splitScalar(u8, body, '\n'); @@ -396,8 +380,8 @@ fn sortResults(arena: std.mem.Allocator, from: Origin, content: []u8, anchor: ?u var sorted = true; var count: usize = 0; while (lines.next()) |line| { - const current: Location = if (path_only) .{ .path = line, .at = .{}, .end = line.len } else location(line); - if (!path_only and current.at.line == 0) return anchor; + const current = location(line); + if (current.at.line == 0) return anchor; if (previous) |last| if (last.order(current) == .gt) { sorted = false; }; @@ -424,10 +408,9 @@ fn sortResults(arena: std.mem.Allocator, from: Origin, content: []u8, anchor: ?u lines = std.mem.splitScalar(u8, copy, '\n'); for (rows, 0..) |*row, original| { const text = lines.next().?; - const target: Location = if (path_only) .{ .path = text, .at = .{}, .end = text.len } else location(text); row.* = .{ .text = text, - .target = target, + .target = location(text), .original = original, }; } diff --git a/src/Stream.zig b/src/Stream.zig index 8e51b797..1e6abbc5 100644 --- a/src/Stream.zig +++ b/src/Stream.zig @@ -44,6 +44,8 @@ const batch_ns = 16 * std.time.ns_per_ms; const batch_bytes = 256 * 1024; /// A bigger file is not searched. const max_file_bytes = 16 << 20; +/// The walk goes no deeper than this many directories below its root. +const max_walk_depth = 16; /// What a worker sends: rows as fs.zig wrote them (`path:line:col-end /// text`, a listing's `path`), relative to the search's directory. Owned by @@ -883,7 +885,7 @@ const Worker = struct { const path = if (prefix.len == 0) e.name else try std.fmt.allocPrint(a, "{s}/{s}", .{ prefix, e.name }); switch (e.kind) { .directory => { - if (depth + 1 >= filesystem.WalkNotes.max_depth or e.name[0] == '.') continue; + if (depth + 1 >= max_walk_depth or e.name[0] == '.') continue; if (for (filesystem.find_skip) |skip| { if (std.mem.eql(u8, e.name, skip)) break true; } else false) continue; diff --git a/src/builtins.zig b/src/builtins.zig index 5d752353..3686eb88 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -1701,7 +1701,6 @@ pub const Find = struct { pub const takes_arg = true; // A script's Find names what to find (bare, it is a key's prompt). pub const requires_arg = true; - pub const output: OutputTraits = .{ .name = config.search_buffer, .steps = true }; pub fn run(c: Ctx) void { search(c, .find, e_search_miss_find); } @@ -1712,7 +1711,6 @@ pub const Find = struct { pub const Grep = struct { pub const takes_arg = true; pub const requires_arg = true; - pub const output: OutputTraits = .{ .name = config.search_buffer, .steps = true, .locations = true }; pub fn run(c: Ctx) void { search(c, .grep, e_search_miss_grep); } diff --git a/src/fs.zig b/src/fs.zig index 2c54f3df..67ce09a5 100644 --- a/src/fs.zig +++ b/src/fs.zig @@ -1104,42 +1104,6 @@ pub const platform_has_fs = !pardes.isolated and switch (pardes.platform) { const find_max_hits = 512; -/// What a Find or Grep walk passed over, said under its hits: directories -/// it might not open, and caps it stopped at. -pub const WalkNotes = struct { - skipped: usize = 0, - hits_cut: bool = false, - /// A pane search's matching lines it stopped at, its rows filling - /// look.search_text_output_bytes; 0 if none. - rows_cut: usize = 0, - /// The cap on entries walked it stopped at, 0 if none. - walk_cut: usize = 0, - - pub const max_hits = find_max_hits; - pub const max_files = grep_max_files; - pub const max_depth = find_max_depth; - - /// The lines that say it, each ending in a newline, into `out`. - pub fn write(n: WalkNotes, out: []u8) usize { - var w = std.Io.Writer.fixed(out); - if (n.hits_cut) w.print("cut at {d} hits\n", .{max_hits}) catch {}; - if (n.rows_cut > 0) w.print("cut at {d} lines\n", .{n.rows_cut}) catch {}; - if (n.walk_cut > 0) w.print("walk cut at {d} entries\n", .{n.walk_cut}) catch {}; - if (n.skipped > 0) w.print("{d} director{s} skipped: permission denied\n", .{ n.skipped, if (n.skipped == 1) "y" else "ies" }) catch {}; - return w.buffered().len; - } - - /// Whether `line` is one of those, not a hit. - pub fn isNote(line: []const u8) bool { - if (std.mem.startsWith(u8, line, "cut at ") or std.mem.startsWith(u8, line, "walk cut at ")) return true; - const digits = for (line, 0..) |c, i| { - if (!std.ascii.isDigit(c)) break i; - } else line.len; - if (digits == 0) return false; - const rest = line[digits..]; - return std.mem.startsWith(u8, rest, " director") or std.mem.startsWith(u8, rest, " file"); - } -}; const find_max_depth = 16; pub const find_skip = [_][]const u8{ diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 05e13edc..33d7acc5 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -2306,12 +2306,12 @@ test "a PDF's body reads its page's text layer, and takes no write" { try testing.expectEqual(E.INVAL, wr(p, body, "more\n").errno()); } -test "Grep, Symbols and Diagnostics share their directory's one +Search" { +test "workspace symbols, Symbols and Diagnostics share their directory's one +Search" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); const id = p.active; const Output = pardes.panes.Output; - try Output.fillResults(p, id, "/tmp", .{ .cmd = .Grep }, "x", try p.gpa.dupe(u8, "a.txt:1:1 x\n"), null); + try Output.fillResults(p, id, "/tmp", .{ .query = .workspace_symbols }, "x", try p.gpa.dupe(u8, "a.txt:1:1 x\n"), null); try Output.fillResults(p, id, "/tmp", .{ .query = .document_symbols }, "", try p.gpa.dupe(u8, "a.txt:2:1 fn f\n"), null); try Output.fillResults(p, id, "/tmp", .{ .query = .diagnostics }, "", try p.gpa.dupe(u8, "a.txt:3:1 error\n"), null); var searches: usize = 0; -- cgit v1.3