summaryrefslogtreecommitdiff
path: root/core/Query.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Query.zig')
-rw-r--r--core/Query.zig49
1 files changed, 39 insertions, 10 deletions
diff --git a/core/Query.zig b/core/Query.zig
index 2b2abebb..743e9540 100644
--- a/core/Query.zig
+++ b/core/Query.zig
@@ -530,8 +530,9 @@ fn makeNameRows(p: *Pardes, id: usize) !void {
f.pager_spans = spans.toOwnedSlice(p.gpa) catch &.{};
q.total = q.names.hits.items.len;
q.more = q.names.busy() or p.stream.busyFor(rp.serial);
- // The best is current until a step or a click moves it.
- q.current = if (shown > 0) 0 else null;
+ // The best is current until a step or a click moves it: in a grouped
+ // list (Symbols) wherever its group puts it.
+ q.current = if (shown > 0) @min(q.names.bestRow(), shown - 1) else null;
countCurrent(q);
showCurrent(p.settings.tab, rp);
if (q.current == null) blankPreview(p, id) else showTarget(p, id);
@@ -771,23 +772,51 @@ pub fn gather(p: *Pardes, names: *Names, source: Source, dir: []const u8, self:
const oid = owner_id orelse return;
const owner = p.panes[oid].?;
const f = if (owner.file) |*file| file else return;
- const decls = ownerDecls(f) orelse {
+ if (f.context.revision != f.revision) {
// Parsed on the worker; listed when it is done (declsArrived).
Stream.parseFor(p, oid);
return;
- };
- for (decls) |d| {
- const header = f.content[d.start_byte..@min(d.header_end_byte, f.content.len)];
- 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;
- names.add(gpa, row, 8, row.len - 8, 0, @intCast(d.start_line + 1)) catch break;
}
+ // The file's text, which was parsed (the `Changes` layer's lines
+ // are none of it).
+ const text = File.fileText(f, p.scratch.allocator()) catch return;
+ const symbols = f.context.symbols;
+ // A row a symbol, ` 12 m Counts.lines : usize = 0`: its
+ // line, its mark, its name qualified by the ones it is in, then
+ // what its first line says after the name; types, functions,
+ // fields, then the rest, each in the text's order (UX DESIGN N).
+ // The name alone is matched.
+ for (0..4) |group| for (symbols) |sym| {
+ if (sym.kind.group() != group or sym.kind == .scope or sym.end > text.len) continue;
+ var buf: [512]u8 = undefined;
+ var row: std.Io.Writer = .fixed(&buf);
+ row.print("{d: >6} {s} ", .{ sym.line + 1, sym.kind.mark() }) catch continue;
+ const key_at = row.end;
+ qualify(&row, symbols, text, sym.parent, 4) catch continue;
+ row.writeAll(text[sym.name_start..sym.name_end]) catch continue;
+ const key_len = row.end - key_at;
+ const rest = text[sym.name_end..@max(sym.name_end, sym.end)];
+ var detail = std.mem.trim(u8, rest[0 .. std.mem.indexOfScalar(u8, rest, '\n') orelse rest.len], " \t\r");
+ detail = std.mem.trimEnd(u8, std.mem.trimEnd(u8, detail, "{,;"), " \t");
+ if (detail.len > 0) row.print(" {s}", .{detail[0..@min(detail.len, buf.len - row.end -| 2)]}) catch {};
+ names.add(gpa, row.buffered(), key_at, key_len, 0, sym.line + 1) catch break;
+ names.cands.items[names.cands.items.len - 1].group = @intCast(group);
+ };
},
else => {},
}
}
+/// The names of the symbols `parent` (an index + 1) is in, outermost
+/// first, each with its `.`: `Outer.Inner.` (the `depth` innermost).
+fn qualify(w: *std.Io.Writer, symbols: []const syntax.Symbol, text: []const u8, parent: u32, depth: u8) std.Io.Writer.Error!void {
+ if (parent == 0 or parent > symbols.len or depth == 0) return;
+ const up = symbols[parent - 1];
+ if (up.name_end > text.len) return;
+ try qualify(w, symbols, text, up.parent, depth - 1);
+ try w.print("{s}.", .{text[up.name_start..up.name_end]});
+}
+
/// What a Panes row of a closed pane ends with.
const closed_word = " (closed)";