summaryrefslogtreecommitdiff
path: root/core/Query.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Query.zig')
-rw-r--r--core/Query.zig50
1 files changed, 17 insertions, 33 deletions
diff --git a/core/Query.zig b/core/Query.zig
index dacc11a1..704206e6 100644
--- a/core/Query.zig
+++ b/core/Query.zig
@@ -200,16 +200,16 @@ fn freeSaved(gpa: std.mem.Allocator, s: Saved) void {
gpa.free(s.items);
}
-/// The owner's query pane (attached to it, or left where it was by
-/// Unattach): the one a later search from it reuses.
+/// The owner's query pane (docked to it, or left where it was by
+/// Undock): the one a later search from it reuses.
pub fn ofOwner(p: *Pardes, owner_serial: u32) ?usize {
var found: ?usize = null;
for (p.panes, 0..) |slot, i| {
const pane = slot orelse continue;
const q = pane.query orelse continue;
if (q.owner != owner_serial) continue;
- // the attached one first: an unattached one is a kept result
- if (pane.attached_to == owner_serial) return i;
+ // the docked one first: an undocked one is a kept result
+ if (pane.docked_to == owner_serial) return i;
found = found orelse i;
}
return found;
@@ -754,7 +754,7 @@ fn startSource(p: *Pardes, id: usize, q: *Query, source: Source, owner_id: ?usiz
const oid = owner_id orelse return;
const owner = p.panes[oid].?;
const f = if (owner.file) |*file| file else return;
- const decls = ownerDecls(p, f, false) orelse {
+ const decls = ownerDecls(f) orelse {
// Parsed on the worker; listed when it is done (declsArrived).
Stream.parseFor(p, oid);
return;
@@ -782,31 +782,15 @@ fn recentRows(p: *Pardes, out: *std.Io.Writer.Allocating) []const u8 {
return out.written();
}
-/// The owner's declarations, from a parse that already exists: its sticky
-/// headers' (TreeContext) at this revision, or the locations cache's. None
-/// is made here, on the loop, unless `small` and the text is small: a
-/// tree-sitter parse of a 1.2 MB file is seconds in a Debug build.
-/// ponytail: no grouping for a big file until the disk engine's worker
-/// parses it (phase 4).
-fn ownerDecls(p: *Pardes, f: *File.State, small: bool) ?[]const syntax.ContextDeclaration {
+/// The owner's declarations, from its parse at this revision (its context:
+/// sticky headers' (TreeContext), a worker's answer, a dump's load), or
+/// none: never the locations cache's (a Diff's), which a client joined
+/// since has not, nor a parse made here (Stream.parseFor asks one).
+fn ownerDecls(f: *const File.State) ?[]const syntax.ContextDeclaration {
if (f.context.revision) |rev| if (rev == f.revision and f.context.declarations.len > 0) return f.context.declarations;
- const cache = &p.locations_cache;
- for (cache.entries[0..cache.len]) |entry| {
- if (entry.declarations_ready and std.mem.eql(u8, entry.path, f.path) and std.mem.eql(u8, entry.source, f.content)) return entry.analysis.declarations;
- }
- if (!small or f.content.len > small_parse_bytes or !syntax.supportsPath(f.path)) return null;
- var got = p.locations_cache.get(p.tree_sitter_gpa, f.path, f.content, true, false) catch return null;
- if (got.owned) {
- got.deinit(p.tree_sitter_gpa);
- return null;
- }
- return got.analysis.declarations;
+ return null;
}
-/// A text this small is parsed on the loop for its declarations when a
-/// Symbols query asks (about 40 ms in a Debug build).
-const small_parse_bytes = 64 << 10;
-
/// The rows as `note` says, and nothing else: no hits.
fn noteRows(p: *Pardes, id: usize, note: []const u8) void {
const rp = p.panes[id].?;
@@ -1043,7 +1027,7 @@ fn writePlacesRows(p: *Pardes, q: *Query, out: *std.ArrayList(u8), rows: *std.Ar
const rel = lookPath(&relbuf, path, dir);
const width = addressWidth(rel, index.len);
var sh: Shades = .{};
- const decls = ownerDecls(p, f, false) orelse &.{};
+ const decls = ownerDecls(f) orelse &.{};
var decl_now: ?usize = null;
var i: usize = @min(from, hits.len);
// the line of the first, found in the index
@@ -1107,7 +1091,7 @@ fn makeTextRows(p: *Pardes, id: usize, oid: usize, full: bool) !void {
var rows: std.ArrayList(locations.Row) = .empty;
var budget: usize = if (full) max_rows else live_rows;
// Grouped once a parse of the text exists: asked of the worker now.
- if (ownerDecls(p, &owner.file.?, false) == null) Stream.parseFor(p, oid);
+ if (ownerDecls(&owner.file.?) == null) Stream.parseFor(p, oid);
const at = set.current orelse (if (set.seek) |s| Places.firstFrom(set.hits.items, s) else 0);
// While typed, a window of rows from just before the current place, so
// it sits under line 1.
@@ -1754,7 +1738,7 @@ fn promote(p: *Pardes, qid: usize, id: usize) void {
// Its text was read from that file to preview it (displayPreview).
f.on_disk = filesystem.localPath(f.path) != null;
f.syntax_dirty = true;
- pane.attached_to = null;
+ pane.docked_to = null;
if (f.on_disk) p.recent.opened(p.recentGpa(), f.path);
if (filesystem.localPath(f.path) != null) p.emit(.{ .watch = .{ .pane = .at(id), .on = true } });
pardes.ctlfs.events.noteLog(p, .rename, pane);
@@ -1887,7 +1871,7 @@ pub fn cancel(p: *Pardes, id: usize) void {
// A preview made for the query Esc took back has no use: its rows
// go to the text whose rows they were.
if (previewOf(p, id)) |pid| {
- p.panes[pid].?.attached_to = null;
+ p.panes[pid].?.docked_to = null;
p.removePane(pid, owner_id) catch |err| p.reportError(.at(id), "query", err);
q.preview = 0;
}
@@ -2354,7 +2338,7 @@ test "Find: names fuzzy per keystroke, the group born with its +Preview, nothing
try std.testing.expectEqual(pv, p.view().active);
try std.testing.expectEqual(serial, p.panes[pv].?.serial);
try std.testing.expect(p.panes[pv].?.file.?.output == null);
- try std.testing.expect(p.panes[pv].?.attached_to == null);
+ try std.testing.expect(p.panes[pv].?.docked_to == null);
layout.compute(p);
try std.testing.expectEqualDeep(rect, p.view().rects[pv]);
try std.testing.expect(q.frozen);
@@ -2754,6 +2738,6 @@ test "a query row's address reaches every way a look arrives: an empty look writ
// the whole row written to the pane's look: the place
a.body.cur_row = 0;
const tree = @import("ninep/tree.zig");
- try std.testing.expectEqual(tree.Status.ok, @import("ninep/testing.zig").wr(p, tree.Node.of(qp.serial, .look), line).reply.status);
+ try std.testing.expectEqual(tree.Status.ok, @import("ninep/harness.zig").wr(p, tree.Node.of(qp.serial, .look), line).reply.status);
try std.testing.expectEqual(@as(i32, 3), a.body.cur_row);
}