diff options
| -rw-r--r-- | src/Output.zig | 25 | ||||
| -rw-r--r-- | src/Stream.zig | 4 | ||||
| -rw-r--r-- | src/builtins.zig | 2 | ||||
| -rw-r--r-- | src/fs.zig | 36 | ||||
| -rw-r--r-- | src/ninep/ctl.zig | 4 | ||||
| -rw-r--r-- | test/locations_bench.zig | 2 | ||||
| -rw-r--r-- | test/output.zig | 14 |
7 files changed, 13 insertions, 74 deletions
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); } @@ -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; diff --git a/test/locations_bench.zig b/test/locations_bench.zig index 54cebb59..ecf2649d 100644 --- a/test/locations_bench.zig +++ b/test/locations_bench.zig @@ -50,7 +50,7 @@ test "locations benchmark cold and warm formatting" { _ = p.scratch.reset(.retain_capacity); const data = try gpa.dupe(u8, input.written()); const t = now(); - try pds.panes.Output.fillResults(p, 0, "/bench", .{ .cmd = .Grep }, "BENCH_MATCH", data, null); + try pds.panes.Output.fillResults(p, 0, "/bench", .{ .query = .references }, "BENCH_MATCH", data, null); const elapsed = now() - t; const modes = [_][]const u8{ "off", "ordinary", "tree_sitter", "both" }; std.debug.print("{s},{s},{d},{d},{s},{d},{d}\n", .{ @tagName(layout), modes[mode], functions, source.written().len, if (rep == 0) "cold" else "warm", rep, elapsed }); diff --git a/test/output.zig b/test/output.zig index f484c3e6..c476af28 100644 --- a/test/output.zig +++ b/test/output.zig @@ -120,7 +120,7 @@ test "output callers opt into location highlighting instead of matching prose co } test "location producers retain rendered location match and diagnostic styles" { - for ([_]panes.Output.Origin{ .search, .{ .cmd = .Grep }, .{ .query = .references }, .{ .query = .diagnostics } }) |origin| { + for ([_]panes.Output.Origin{ .search, .{ .query = .references }, .{ .query = .diagnostics } }) |origin| { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 30 }); defer p.deinit(); p.locations_config.layout = .@"inline"; @@ -156,7 +156,7 @@ test "location producers retain rendered location match and diagnostic styles" { test "location results sort filenames and numeric positions while remapping their anchor" { const before = "z.zig:1:1 z\nb.zig:10:2-3 ten\nb.zig:2:10-12 two-b\nb.zig:2:2-3 two-a\na.zig:99:1 a\nb.zig:2:2-3 duplicate\n"; const after = "a.zig:99:1 a\nb.zig:2:2-3 two-a\nb.zig:2:2-3 duplicate\nb.zig:2:10-12 two-b\nb.zig:10:2-3 ten\nz.zig:1:1 z\n"; - for ([_]panes.Output.Origin{ .search, .{ .cmd = .Grep }, .{ .query = .references }, .{ .query = .diagnostics } }) |origin| { + for ([_]panes.Output.Origin{ .search, .{ .query = .references }, .{ .query = .diagnostics } }) |origin| { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); defer p.deinit(); p.locations_config.layout = .@"inline"; @@ -361,15 +361,7 @@ test "result sorting allocation failures preserve the previous answer and naviga } } -test "Find sorts whole filenames and next location uses numeric columns" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); - defer p.deinit(); - p.locations_config.layout = .@"inline"; - const source = try p.setTestFile(""); - try panes.Output.fillResults(p, 0, "/tmp", .{ .cmd = .Find }, "", try p.gpa.dupe(u8, "x:2\nx:10\n"), 0); - const result = p.panes[source.search_pane.?].?; - try std.testing.expectEqualStrings("x:10\nx:2\n", result.file.?.content); - try std.testing.expectEqual(@as(usize, 1), source.search_row.?); +test "next location uses numeric columns" { const rows = "with space.zig:2:2-3 first\nwith space.zig:2:10-12 next\nwith space.zig:10:1 later"; try std.testing.expectEqual(@as(usize, 1), panes.Output.nextResult(rows, &.{}, "with space.zig", .{ .line = 2, .col = 3 })); try std.testing.expectEqual(@as(usize, 2), panes.Output.nextResult(rows, &.{}, "with space.zig", .{ .line = 2, .col = 10 })); |
