diff options
Diffstat (limited to 'core/Query.zig')
| -rw-r--r-- | core/Query.zig | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/core/Query.zig b/core/Query.zig index 7bc30c9d..a35f5797 100644 --- a/core/Query.zig +++ b/core/Query.zig @@ -486,7 +486,12 @@ fn makeNameRows(p: *Pardes, id: usize) !void { var meta: locations.Row = .{ .kind = .match, .path = &.{}, .at = .{}, .location_end = 0, .code_start = 0, .mark_occurrence = false }; var pathbuf: [4096 + 32]u8 = undefined; switch (q.source) { - .find => meta.path = @constCast(std.fmt.bufPrint(&pathbuf, "{s}/{s}", .{ std.mem.trimEnd(u8, dir, "/"), row }) catch row), + .find => { + // A name the worker quoted (look.quoted) opens as it is named. + var namebuf: [4096]u8 = undefined; + const name = if (row.len > 1 and row[0] == '"' and row[row.len - 1] == '"') look.unquoted(&namebuf, row[1 .. row.len - 1]) else row; + meta.path = @constCast(std.fmt.bufPrint(&pathbuf, "{s}/{s}", .{ std.mem.trimEnd(u8, dir, "/"), name }) catch row); + }, .recent => { const t = look.parsePathLine(row); meta.path = @constCast(if (t.path.len > 0 and t.path[0] == '/') t.path else std.fmt.bufPrint(&pathbuf, "{s}/{s}", .{ std.mem.trimEnd(u8, dir, "/"), t.path }) catch t.path); @@ -1030,7 +1035,8 @@ fn writePlacesRows(p: *Pardes, q: *Query, out: *std.ArrayList(u8), rows: *std.Ar const index = try File.lineIndex(p.gpa, f); const path = addressOf(p.scratch.allocator(), tp); var relbuf: [4096]u8 = undefined; - const rel = lookPath(&relbuf, path, dir); + var namebuf: [8192]u8 = undefined; + const rel = std.fmt.bufPrint(&namebuf, "{f}", .{look.quoted(lookPath(&relbuf, path, dir))}) catch lookPath(&relbuf, path, dir); const width = addressWidth(rel, index.len); var sh: Shades = .{}; defer sh.done(p); @@ -1192,10 +1198,11 @@ fn makeGrepRows(p: *Pardes, id: usize, full: bool) !void { defer sh.done(p); var width: usize = 0; var relbuf: [4096]u8 = undefined; + var namebuf: [8192]u8 = undefined; for (q.found.items[lo..hi], lo..) |fd, i| { const name = q.found_bytes.items[fd.path..][0..fd.path_len]; const path = std.fmt.bufPrint(&pathbuf, "{s}/{s}", .{ std.mem.trimEnd(u8, dir, "/"), name }) catch continue; - const rel = lookPath(&relbuf, path, dir); + const rel = std.fmt.bufPrint(&namebuf, "{f}", .{look.quoted(lookPath(&relbuf, path, dir))}) catch lookPath(&relbuf, path, dir); if (!std.mem.eql(u8, name, last_path)) { last_path = name; try q.items.append(p.gpa, .{ .kind = .header }); @@ -1257,19 +1264,21 @@ pub fn take(p: *Pardes, q: *Query, kind: Stream.Kind, rows: []const u8) void { const t = look.parsePathLine(ln); if (t.at.line == 0 or t.path.len == 0) continue; const code = if (t.end < ln.len) ln[t.end + 1 ..] else ""; - // A row is a line's text, a file's name in it unescaped (one - // named `a:5000000000:b` reads as `a` at line 5000000000): one - // whose numbers a Found cannot hold is passed over. + // The worker writes a name that needs it quoted (look.quoted: + // a newline in it was a row of its own); one whose numbers a + // Found cannot hold is passed over. + var namebuf: [4096]u8 = undefined; + 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, t.path.len) orelse continue, + .path_len = std.math.cast(u16, 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 + t.path.len) orelse return, + .code = std.math.cast(u32, q.found_bytes.items.len + name.len) orelse return, .code_len = std.math.cast(u32, code.len) orelse continue, }; - q.found_bytes.appendSlice(p.gpa, t.path) 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; }, @@ -1355,13 +1364,14 @@ fn makeListRows(p: *Pardes, id: usize, pat: []const u8) !void { defer sh.done(p); var width: usize = 0; var relbuf: [4096]u8 = undefined; + var namebuf: [8192]u8 = undefined; for (sorted.items, 0..) |ln, li| { if (ln.len == 0) continue; if (pat.len > 0 and std.ascii.findIgnoreCase(ln, pat) == null) continue; const t = look.parsePathLine(ln); if (t.at.line == 0) continue; const path = if (t.path.len > 0 and t.path[0] == '/') t.path else std.fmt.bufPrint(&pathbuf, "{s}/{s}", .{ std.mem.trimEnd(u8, dir, "/"), t.path }) catch continue; - const rel = lookPath(&relbuf, path, dir); + const rel = std.fmt.bufPrint(&namebuf, "{f}", .{look.quoted(lookPath(&relbuf, path, dir))}) catch lookPath(&relbuf, path, dir); if (!std.mem.eql(u8, t.path, last_path)) { last_path = t.path; try q.items.append(p.gpa, .{ .kind = .header }); |
