diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-26 02:28:09 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-26 02:49:36 -0300 |
| commit | 148e48dd9b8cd7e66aa1521daa49a64852b1650e (patch) | |
| tree | edf3c1ca188018164a0713917ca0e336cecd14cd /core/Names.zig | |
| parent | 1ce3bcb6178b720058518a12e45f25769be7d39c (diff) | |
| download | pardes-148e48dd9b8cd7e66aa1521daa49a64852b1650e.tar.gz pardes-148e48dd9b8cd7e66aa1521daa49a64852b1650e.zip | |
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
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core/Names.zig')
| -rw-r--r-- | core/Names.zig | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/core/Names.zig b/core/Names.zig index d063bd17..415064ad 100644 --- a/core/Names.zig +++ b/core/Names.zig @@ -50,6 +50,9 @@ pub const Cand = struct { /// What the row is of: a line of the owner (Symbols, 1-based), a /// pane's serial (Panes); 0 for a path. ref: u32 = 0, + /// Its group: the hits stay in their groups' order, scored within + /// each (a Symbols row's kind, UX DESIGN N3); 0 for every other source. + group: u8 = 0, }; pub const Hit = struct { cand: u32, score: i32 }; @@ -187,9 +190,17 @@ pub fn reachTo(n: *Names, rows: usize) void { n.gen +%= 1; } -/// Hit `a` goes before `b`: the higher score, then the shorter key, then -/// the candidate added first. +/// Hit `a` goes before `b`: the lower group, then `better`. fn before(cands: []const Cand, a: Hit, b: Hit) bool { + const ga = cands[a.cand].group; + const gb = cands[b.cand].group; + if (ga != gb) return ga < gb; + return better(cands, a, b); +} + +/// Hit `a` matched better than `b`: the higher score, then the shorter +/// key, then the candidate added first. +fn better(cands: []const Cand, a: Hit, b: Hit) bool { if (a.score != b.score) return a.score > b.score; const la = cands[a.cand].key_len; const lb = cands[b.cand].key_len; @@ -230,6 +241,22 @@ fn sink(heap: []Hit, cands: []const Cand, from: usize) void { } } +/// The row of the hit the query matched best, wherever its group puts it: +/// where a list's cursor starts (UX DESIGN N3); 0 for an empty query, +/// whose rows are the source's order. Its rows up to it are sorted once +/// `reachTo` has gone past it. +pub fn bestRow(n: *const Names) usize { + const hits = n.hits.items; + if (hits.len == 0 or std.mem.trim(u8, n.queryText(), " ").len == 0) return 0; + var top = hits[0]; + for (hits[1..]) |h| if (better(n.cands.items, h, top)) { + top = h; + }; + var at: usize = 0; + for (hits) |h| at += @intFromBool(before(n.cands.items, h, top)); + return at; +} + /// The row of hit `i` and, in `marks`, the bytes of it the query matched. pub fn row(n: *const Names, i: usize, marks: []u16, nmarks: *usize) []const u8 { const c = n.cands.items[n.hits.items[i].cand]; |
