summaryrefslogtreecommitdiff
path: root/core/Query.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Query.zig')
-rw-r--r--core/Query.zig9
1 files changed, 5 insertions, 4 deletions
diff --git a/core/Query.zig b/core/Query.zig
index 2b2abebb..fff6065c 100644
--- a/core/Query.zig
+++ b/core/Query.zig
@@ -1269,7 +1269,7 @@ fn countGrepCurrent(q: *Query) void {
/// picker (Pick.zig: the same fields): a Grep's lines (`path:line:col-end
/// code`, relative to the pane's directory) kept as found, a listing's
/// names added to what Find scores.
-pub fn take(p: *Pardes, q: anytype, kind: Stream.Kind, rows: []const u8) void {
+pub fn take(p: *Pardes, q: anytype, kind: Stream.Kind, rows: []const u8, under: []const u8) void {
var lines = std.mem.splitScalar(u8, rows, '\n');
while (lines.next()) |ln| {
if (ln.len == 0) continue;
@@ -1286,13 +1286,14 @@ pub fn take(p: *Pardes, q: anytype, kind: Stream.Kind, rows: []const u8) void {
const name = if (ln[0] == '"') look.unquoted(&namebuf, t.path) else t.path;
const found: Found = .{
.path = std.math.cast(u32, q.found_bytes.items.len) orelse return,
- .path_len = std.math.cast(u16, name.len) orelse continue,
+ .path_len = std.math.cast(u16, under.len + name.len) orelse continue,
.line = std.math.cast(u32, t.at.line) orelse continue,
.col = std.math.cast(u32, t.at.col -| 1) orelse continue,
.end = std.math.cast(u32, if (t.at.end_col > 0) t.at.end_col else t.at.col) orelse continue,
- .code = std.math.cast(u32, q.found_bytes.items.len + name.len) orelse return,
+ .code = std.math.cast(u32, q.found_bytes.items.len + under.len + name.len) orelse return,
.code_len = std.math.cast(u32, code.len) orelse continue,
};
+ q.found_bytes.appendSlice(p.gpa, under) catch return;
q.found_bytes.appendSlice(p.gpa, name) catch return;
q.found_bytes.appendSlice(p.gpa, code) catch return;
q.found.append(p.gpa, found) catch return;
@@ -2811,7 +2812,7 @@ test "Grep: a row whose numbers a Found cannot hold (a column past u32) is passe
defer p.deinit();
var q: Query = .{ .owner = 0 };
defer q.deinit(p.gpa);
- take(p, &q, .grep, "a:5000000000:b:3:1-4 hit\nok.txt:2:3-5 hit\nb:7:4294967297 hit\n");
+ take(p, &q, .grep, "a:5000000000:b:3:1-4 hit\nok.txt:2:3-5 hit\nb:7:4294967297 hit\n", "");
// Taken or passed over, each: never cast (main: Query.zig:1267).
try std.testing.expect(q.found.items.len <= 3);
}