diff options
Diffstat (limited to 'src/Query.zig')
| -rw-r--r-- | src/Query.zig | 57 |
1 files changed, 13 insertions, 44 deletions
diff --git a/src/Query.zig b/src/Query.zig index edc777f6..e34b1054 100644 --- a/src/Query.zig +++ b/src/Query.zig @@ -150,8 +150,6 @@ seen_rev: u32 = 0, /// The body cursor's row as last seen: j or k onto a row makes it current /// (a caret B1 put there is only a caret). seen_row: i32 = 0, -/// The places a `/`'s rows are a window of: [lo, hi) of its owner's hits. -window: struct { lo: usize = 0, hi: usize = 0 } = .{}, /// Ticks the rows waited while the places are still being found: they are /// made every third, the frame's time going to the finding. waited: u8 = 0, @@ -203,11 +201,6 @@ fn freeSaved(gpa: std.mem.Allocator, s: Saved) void { gpa.free(s.items); } -/// The query pane `pane` is, if it is one. -pub fn of(pane: *Pane) ?*Query { - return pane.query; -} - /// The owner's query pane (attached to it, or left where it was by /// SearchPane new): the one a later search from it reuses. pub fn ofOwner(p: *Pardes, owner_serial: u32) ?usize { @@ -436,7 +429,7 @@ fn produce(p: *Pardes, id: usize, tick: bool, keyed: bool) void { q.source = a.source; } // The places this fed are another question's now. - if (asked == null or asked.?.source != .text) clearPlaces(p, q, rp.serial, owner_id, asked); + if (asked == null or asked.?.source != .text) clearPlaces(p, rp.serial, owner_id); } const a = asked orelse return noteRows(p, id, " line 1 asks: /text, Find, Grep, Recent, Panes, Symbols, All, Refs, Def, Impl or Diagnostics, then what to find\n"); // A row stepped onto (j, k): current, and shown. One B1 put the caret @@ -505,7 +498,7 @@ fn produce(p: *Pardes, id: usize, tick: bool, keyed: bool) void { if (changed) q.names.typed(p.gpa, a.pat) else if (q.names.busy()) q.names.rescore(p.gpa); if (q.names.gen == q.made_gen and !changed) return; q.made_gen = q.names.gen; - makeNameRows(p, id, a.pat) catch |err| p.reportError(id, "search", err); + makeNameRows(p, id) catch |err| p.reportError(id, "search", err); }, .grep => { const dir = std.fs.path.dirname(f.path) orelse "/"; @@ -523,7 +516,7 @@ fn produce(p: *Pardes, id: usize, tick: bool, keyed: bool) void { } else if (p.stream.target == rp.serial) { _ = p.stream.stop(); } - feedGrepPlaces(p, q, rp.serial, a.pat); + feedGrepPlaces(p, rp.serial, a.pat); } const searching = p.stream.target == rp.serial and p.stream.state != .done and p.stream.state != .stopped and p.stream.state != .failed and p.stream.state != .idle; const gen: u64 = (@as(u64, q.grep_gen) << 32) | (q.found.items.len << 1) | @intFromBool(searching); @@ -738,7 +731,8 @@ fn setRows(p: *Pardes, rp: *Pane, out: *std.ArrayList(u8), rows: *std.ArrayList( f.location_rows = meta; f.saved_revision = f.revision; } - gpa_free_pager(p, f); + if (f.pager_spans.len > 0) p.gpa.free(f.pager_spans); + f.pager_spans = &.{}; // The cursor stays where it was typing; on a row that went, the last. const last: i32 = @intCast(File.nlines(p.gpa, f) -| 1); rp.body.cur_row = @min(kept_row, last); @@ -747,12 +741,6 @@ fn setRows(p: *Pardes, rp: *Pane, out: *std.ArrayList(u8), rows: *std.ArrayList( rp.query.?.seen_row = rp.body.cur_row; } -fn gpa_free_pager(p: *Pardes, f: *File.State) void { - if (f.pager_spans.len == 0) return; - p.gpa.free(f.pager_spans); - f.pager_spans = &.{}; -} - /// The room a group of rows gives its addresses, so that their code /// starts in one column: the path, a colon, its longest line number, a /// colon, three digits of column (a longer one pushes its code on a cell). @@ -922,9 +910,8 @@ pub fn lookPath(buf: []u8, path: []const u8, dir: []const u8) []const u8 { /// Rows from pane `tp`'s places: one a line with any (two on a line are /// one row: everywhere's bug), the declaration they are in over them when -/// its parse exists, from place `from` on, `budget` rows at most. The -/// place it stopped before. -fn writePlacesRows(p: *Pardes, q: *Query, out: *std.ArrayList(u8), rows: *std.ArrayList(locations.Row), tp: *Pane, dir: []const u8, from: usize, budget: *usize) !usize { +/// its parse exists, from place `from` on, `budget` rows at most. +fn writePlacesRows(p: *Pardes, q: *Query, out: *std.ArrayList(u8), rows: *std.ArrayList(locations.Row), tp: *Pane, dir: []const u8, from: usize, budget: *usize) !void { const f = &tp.file.?; const set = &tp.places; const hits = set.hits.items; @@ -990,7 +977,6 @@ fn writePlacesRows(p: *Pardes, q: *Query, out: *std.ArrayList(u8), rows: *std.Ar try writeHitRow(p, out, rows, &sh, width, rel, path, line + 1, f.content[ls..le], hits[i].start - ls, @min(hits[i].end, le) - ls, shade); i += n; } - return i; } /// The rows of a `/`: while typed, a window of `live_rows` around the @@ -1012,14 +998,12 @@ fn makeTextRows(p: *Pardes, id: usize, oid: usize, full: bool) !void { // While typed, a window of rows from just before the current place, so // it sits under line 1. const from = if (full) 0 else at -| 2; - q.window = .{ .lo = from, .hi = from }; if (set.started and set.from == rp.serial) { if (from > 0) { var hb: [64]u8 = undefined; try noteRow(p, q, &out, &rows, std.fmt.bufPrint(&hb, " ... {d} places before these", .{from}) catch " ..."); } - q.window.hi = try writePlacesRows(p, q, &out, &rows, owner, std.fs.path.dirname(rp.file.?.path) orelse "/", from, &budget); - q.window.lo = @min(from, q.window.hi); + try writePlacesRows(p, q, &out, &rows, owner, std.fs.path.dirname(rp.file.?.path) orelse "/", from, &budget); } if (q.more) try noteRow(p, q, &out, &rows, " ... and more: the count says how many"); setRows(p, rp, &out, &rows); @@ -1101,7 +1085,7 @@ fn makeAllRows(p: *Pardes, id: usize) !void { const head = std.fmt.bufPrint(&hb, config.pane_addr ++ "{d} {s} ({d})", .{ tp.serial, name[0..@min(name.len, 500)], set.hits.items.len }) catch ""; try q.items.append(p.gpa, .{ .kind = .header, .serial = tp.serial }); try writeRow(p, &out, &rows, head, .{ .kind = .context, .declaration = true, .path = @constCast(addressOf(p.scratch.allocator(), tp)), .at = .{}, .location_end = 0, .code_start = 0 }); - _ = try writePlacesRows(p, q, &out, &rows, tp, std.fs.path.dirname(rp.file.?.path) orelse "/", 0, &budget); + try writePlacesRows(p, q, &out, &rows, tp, std.fs.path.dirname(rp.file.?.path) orelse "/", 0, &budget); } if (budget == 0) try noteRow(p, q, &out, &rows, " ... and more: the count says how many"); setRows(p, rp, &out, &rows); @@ -1127,13 +1111,10 @@ fn countCurrent(q: *Query) void { /// The names the query matches, best first, `Names.max_rows` of them: each /// a row as its source has it, the matched bytes tinted. -fn makeNameRows(p: *Pardes, id: usize, pat: []const u8) !void { - _ = pat; +fn makeNameRows(p: *Pardes, id: usize) !void { const rp = p.panes[id].?; const q = rp.query.?; const dir = std.fs.path.dirname(rp.file.?.path) orelse "/"; - const was_current: ?u32 = if (q.current) |c| (if (c < q.items.items.len) q.items.items[c].ref else null) else null; - _ = was_current; q.items.clearRetainingCapacity(); var out: std.ArrayList(u8) = .empty; defer out.deinit(p.gpa); @@ -1201,9 +1182,6 @@ fn makeNameRows(p: *Pardes, id: usize, pat: []const u8) !void { if (q.current == null) blankPreview(p, id) else showTarget(p, id); } -/// A Grep keeps this many lines: the rest wait (the disk engine's `More`). -pub const grep_cap = 2000; - /// A Grep's rows: each file's name over its lines, while typed a window /// of `live_rows` around the current one, `full` (frozen) every one sent. fn makeGrepRows(p: *Pardes, id: usize, full: bool) !void { @@ -1315,8 +1293,7 @@ pub fn take(p: *Pardes, q: *Query, kind: Stream.Kind, rows: []const u8) void { /// A Grep's hits in each open file are that pane's places: its tints, /// ticks and n/N. -fn feedGrepPlaces(p: *Pardes, q: *Query, serial: u32, pat: []const u8) void { - _ = q; +fn feedGrepPlaces(p: *Pardes, serial: u32, pat: []const u8) void { for (p.panes) |slot| { const tp = slot orelse continue; const f = tp.file orelse continue; @@ -1488,9 +1465,7 @@ fn makeListRows(p: *Pardes, id: usize, pat: []const u8) !void { /// The places query `serial` fed in panes other than the owner, cleared /// (a new source or pattern makes its own); the owner's too when the new /// line is no `/`. -fn clearPlaces(p: *Pardes, q: *Query, serial: u32, owner_id: ?usize, asked: anytype) void { - _ = q; - _ = asked; +fn clearPlaces(p: *Pardes, serial: u32, owner_id: ?usize) void { for (p.panes, 0..) |slot, i| { const tp = slot orelse continue; if (tp.places.from != serial) continue; @@ -1926,7 +1901,7 @@ pub fn land(p: *Pardes, id: usize, row: ?usize) void { /// The rows frozen: ordinary text from here, Save works on them; the /// places they fed stay, while the pane lives; every view stays where the -/// search left it; the preview, of no more use, goes. +/// search left it. fn freeze(p: *Pardes, id: usize) void { const rp = p.panes[id] orelse return; const q = rp.query orelse return; @@ -1934,12 +1909,6 @@ fn freeze(p: *Pardes, id: usize) void { if (q.saved) |s| freeSaved(p.gpa, s); q.saved = null; for (p.panes) |slot| if (slot) |tp| if (tp.places.from == rp.serial or tp.serial == q.owner) tp.places.forget(p.gpa); - if (previewOf(p, id)) |pid| { - const pv = p.panes[pid].?; - // A preview showing the current row is promoted by `land`: one - // showing another file goes. - _ = pv; - } } /// Esc on line 1 while typing: every view as the search found it, the |
