From 148e48dd9b8cd7e66aa1521daa49a64852b1650e Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 02:28:09 -0300 Subject: syntax, Query, Pick, Names, Band, Stream, File, colors: the Symbols picker grouped by kind, a kind mark on each row (UX DESIGN N, binding; the user: "The lsp symbols should be more organized: types first then functions then fields and the rest (and some indicator to tell the kind)", "For the symbols picker"): the rows are the file's own parse's, as before, now from a symbol walk of their own (syntax.zig `SymbolWalk`, in the same walk of the tree as the sticky headers' declarations, which keep theirs: contextFromTree), by one kind table a grammar (`symbol_rules`: Zig, C, C++, Rust, Go, Python, JavaScript, Java, C#, Kotlin, Scala, Ruby, PHP, bash, Haskell, OCaml, Erlang, Elixir, Clojure, Fortran, Ada, Pascal, PowerShell; JSON, CSS, HTML, Markdown and Typst have no declarations to list), each node's kind as given or found where its grammar cannot say it (Zig's `const S = struct`, `error{...}`, `@This()`, `@Type(...)` a type and `@import(...)` a module, JavaScript's `const f = () => ...` a function, C's declaration a function where a declarator is one's and a const where `const` says so, a Python class's or Kotlin's binding a field in a type); fields and consts are listed now (the sticky headers' declarations had neither), a function's consts and vars never (its locals), each named in the types, functions and modules it is in (`Counts.lines`, `torque.Parser.Parse`; an anonymous struct's members in its owner's, a Rust `impl S`'s in `S`, no row of its own); a row is `t Counts = struct`: its kind's mark (t type, f function, m field, c const, v var, n module, ยท other), its qualified name, two blanks and what its name's line says after the name (its body's `{`, a trailing `,` or `;` dropped), its line the dim meta at the right end (Band's); the mark in the keyword's ink (colors.Roles.kind, the theme's keyword pushed to 4.5:1 on every tag ground and the selection, as the key ink is), the qualifier and the words after the name dim; with the field empty the rows are types, functions, fields, then the rest (consts, vars, modules, other as one group), each in the text's order; typed, they stay grouped and are scored within each group (Names: `Cand.group`, `before` orders by it, then by `better`), the cursor starts on the best match wherever its group puts it (Names.bestRow, Pick.toBest: after a key, when the parse lands, and following the best while the rest are scored), and the count says where it is; the name alone is matched (`u8` in a signature matches nothing); no header rows: every row is a symbol, ordinary text, and C-q keeps them in a +Search with the mark a word; the query pane's `Symbols` rows the same (Query.gather), its current the best; the parse's answer carries the symbols beside the declarations (Stream.Batch.symbols, an input every replica takes), ContextCache keeps both for the revision (derived, made again at a load), and every producer makes both (the worker, a sticky header's refresh, a load), so a text at a revision has the same symbols everywhere; syntax.zig's tests ran in no test program (core-test's filter `syntax context nested` matched nothing on the base): core/root.zig imports it now, and its 34 pass; RUN (TEST FIRST): syntax.zig "syntax symbols: a Zig file's types, functions, fields and the rest ...", "... C, C++, Rust, Go, Python and JavaScript by their kind tables ...", "... every kind table names nodes of its grammar ..." (23 tables), Pick.zig "Symbols (UX DESIGN N): a Zig file's rows types, functions, fields, then the rest ... the mark in the keyword's ink, the qualifier and the rest dim", "Symbols (UX DESIGN N3): typed, the rows stay grouped ... the cursor starts on the best match ...; the name alone is matched, never the signature", "Symbols (UX DESIGN N): a C++ file's rows ...", "Symbols: every row is ordinary text ..."; on the base the rows were ` 2 pub const Counts = struct {` in the text's order, no mark, no field, the cursor on the first row; core-test -Dtest-filter=ymbols 18/18, core-test 1135/1308 (173 skipped); the stack's suites, the dump fuzz, the soak and the pictures are on the change after this one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/Query.zig | 49 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 10 deletions(-) (limited to 'core/Query.zig') 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)"; -- cgit v1.3