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/File.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/File.zig')
| -rw-r--r-- | core/File.zig | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/core/File.zig b/core/File.zig index 0f9178ac..49d22fdc 100644 --- a/core/File.zig +++ b/core/File.zig @@ -60,35 +60,39 @@ pub const History = struct { } }; -/// Owned syntax results: a text's declarations at a revision. +/// Owned syntax results: a text's declarations and symbols at a revision. pub const ContextCache = struct { /// Its revision is dumped and digested: a worker's parse is an input, /// which a client joined since never saw, and a step reads what it - /// left (Query.ownerDecls). The declarations are made again from the - /// text at a load (`reload`), with the allocator that made them. - pub const replica = .{ .local = .{"allocator"}, .derived = .{"declarations"} }; + /// left (Query.ownerDecls, the Symbols source). The declarations and + /// symbols are made again from the text at a load (`reload`), with the + /// allocator that made them. + pub const replica = .{ .local = .{"allocator"}, .derived = .{ "declarations", "symbols" } }; allocator: ?std.mem.Allocator = null, declarations: []syntax.ContextDeclaration = &.{}, + symbols: []syntax.Symbol = &.{}, revision: ?u32 = null, pub fn deinit(self: *ContextCache) void { - if (self.allocator) |gpa| gpa.free(self.declarations); + if (self.allocator) |gpa| { + gpa.free(self.declarations); + gpa.free(self.symbols); + } self.* = .{}; } - /// A loaded text's (its revision the dump's): its declarations parsed - /// again where they are of the text it has. + /// A loaded text's (its revision the dump's): its context parsed + /// again where it is of the text it has. pub fn reload(self: *ContextCache, gpa: std.mem.Allocator, path: []const u8, content: []const u8, revision: u32) void { const at = self.revision orelse return; if (at != revision) return; - const declarations = syntax.contextDeclarations(gpa, path, content) catch return; - self.replace(gpa, declarations, at); + self.replace(gpa, syntax.context(gpa, path, content) catch return, at); } - /// Takes ownership of declarations allocated by gpa. - pub fn replace(self: *ContextCache, gpa: std.mem.Allocator, declarations: []syntax.ContextDeclaration, revision: u32) void { + /// Takes ownership of a context allocated by gpa. + pub fn replace(self: *ContextCache, gpa: std.mem.Allocator, made: syntax.Context, revision: u32) void { self.deinit(); - self.* = .{ .allocator = gpa, .declarations = declarations, .revision = revision }; + self.* = .{ .allocator = gpa, .declarations = made.declarations, .symbols = made.symbols, .revision = revision }; } }; @@ -2490,8 +2494,7 @@ pub fn changed(p: *Pardes, id: u8, bytes: []const u8) void { pub fn refreshContext(p: *Pardes, pane: *Pane, f: *State) void { if (!f.tree_context or !supportsContext(pane) or f.context.revision == f.revision) return; // The file's declarations, in its lines (the layer's are none of it). - const declarations = syntax.contextDeclarations(p.tree_sitter_gpa, f.path, fileText(f, p.scratch.allocator()) catch return) catch return; - f.context.replace(p.tree_sitter_gpa, declarations, f.revision); + f.context.replace(p.tree_sitter_gpa, syntax.context(p.tree_sitter_gpa, f.path, fileText(f, p.scratch.allocator()) catch return) catch return, f.revision); } pub fn refreshHighlights(p: *Pardes) void { @@ -3615,12 +3618,13 @@ test "context cache frees each allocation with its original allocator" { defer std.testing.expect(second.deinit() == .ok) catch @panic("second allocator leaked"); var cache: ContextCache = .{}; defer cache.deinit(); - cache.replace(first.allocator(), try first.allocator().alloc(syntax.ContextDeclaration, 1), 1); - cache.replace(second.allocator(), try second.allocator().alloc(syntax.ContextDeclaration, 2), 2); + cache.replace(first.allocator(), .{ .declarations = try first.allocator().alloc(syntax.ContextDeclaration, 1), .symbols = try first.allocator().alloc(syntax.Symbol, 1) }, 1); + cache.replace(second.allocator(), .{ .declarations = try second.allocator().alloc(syntax.ContextDeclaration, 2), .symbols = try second.allocator().alloc(syntax.Symbol, 2) }, 2); try std.testing.expectEqual(@as(?u32, 2), cache.revision); cache.deinit(); try std.testing.expect(cache.allocator == null); try std.testing.expectEqual(@as(usize, 0), cache.declarations.len); + try std.testing.expectEqual(@as(usize, 0), cache.symbols.len); } /// The inks of row `row`'s first `n` text cells of pane `id` as `s` draws them. |
