diff options
Diffstat (limited to 'core/Query.zig')
| -rw-r--r-- | core/Query.zig | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/core/Query.zig b/core/Query.zig index feebb6cd..4fbd07e0 100644 --- a/core/Query.zig +++ b/core/Query.zig @@ -713,7 +713,6 @@ fn startSource(p: *Pardes, id: usize, q: *Query, source: Source, owner_id: ?usiz q.found.clearRetainingCapacity(); q.found_bytes.clearRetainingCapacity(); const dir = std.Io.Dir.path.dirname(rp.file.?.path) orelse "/"; - const gpa = p.gpa; switch (source) { // The files under the directory, listed once on the disk engine's // worker (rg --files, else the walk); each keystroke scores them. @@ -721,6 +720,19 @@ fn startSource(p: *Pardes, id: usize, q: *Query, source: Source, owner_id: ?usiz Stream.query(p, rp.serial, .files, "", dir, .now) catch |err| return p.reportError(.at(id), "search", err); if (p.fs.serving) Stream.step(p); }, + .recent, .panes, .symbols => gather(p, &q.names, source, dir, rp, owner_id), + else => {}, + } +} + +/// The names a Recent, Panes or Symbols query scores, into `names`: the +/// files opened lately, the panes but `self` (then the ones this session +/// closed), the declarations of pane `owner_id`'s text (asked of the +/// worker when it has none yet: declsArrived gathers them). Rows relative +/// to `dir`. A query pane's, and a picker's (Pick.zig). +pub fn gather(p: *Pardes, names: *Names, source: Source, dir: []const u8, self: ?*const Pane, owner_id: ?usize) void { + const gpa = p.gpa; + switch (source) { .recent => { var out: std.Io.Writer.Allocating = .init(gpa); defer out.deinit(); @@ -729,19 +741,19 @@ fn startSource(p: *Pardes, id: usize, q: *Query, source: Source, owner_id: ?usiz if (ln.len == 0) continue; 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; + names.add(gpa, rel, 0, path_end, Names.baseOf(rel[0..path_end]), 0) catch break; } }, .panes => { for (p.panes) |slot| { const other = slot orelse continue; - if (other == rp or other.query != null) continue; + if (other == self 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, 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; + names.add(gpa, ln, key_at, ln.len -| key_at, Names.baseOf(ln[@min(key_at, ln.len)..]), other.serial) catch break; } // Then the panes this session closed, the latest first, each // `(closed)` and dimmer (makeNameRows): Enter brings one back @@ -752,7 +764,7 @@ fn startSource(p: *Pardes, id: usize, q: *Query, source: Source, owner_id: ?usiz 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; + names.add(gpa, row, key_at, key_len, Names.baseOf(row[key_at..][0..key_len]), c.serial) catch break; } }, .symbols => { @@ -769,7 +781,7 @@ fn startSource(p: *Pardes, id: usize, q: *Query, source: Source, owner_id: ?usiz const first = std.mem.trim(u8, header[0 .. std.mem.indexOfScalar(u8, header, '\n') orelse header.len], " \t\r"); var buf: [256 + 16]u8 = undefined; const row = std.fmt.bufPrint(&buf, "{d: >6} {s}", .{ d.start_line + 1, first[0..@min(first.len, 240)] }) catch continue; - q.names.add(gpa, row, 8, row.len - 8, 0, @intCast(d.start_line + 1)) catch break; + names.add(gpa, row, 8, row.len - 8, 0, @intCast(d.start_line + 1)) catch break; } }, else => {}, @@ -1253,10 +1265,11 @@ fn countGrepCurrent(q: *Query) void { if (c < q.items.items.len and q.items.items[c].kind == .hit) q.k = q.items.items[c].hit + 1; } -/// The disk engine's rows for query pane `q` (Stream.receive): 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: *Query, kind: Stream.Kind, rows: []const u8) void { +/// The disk engine's rows for query pane `q` (Stream.receive), or for a +/// 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 { var lines = std.mem.splitScalar(u8, rows, '\n'); while (lines.next()) |ln| { if (ln.len == 0) continue; |
