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/syntax.zig | 707 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 692 insertions(+), 15 deletions(-) (limited to 'core/syntax.zig') diff --git a/core/syntax.zig b/core/syntax.zig index 5c05300e..5cdc2ff3 100644 --- a/core/syntax.zig +++ b/core/syntax.zig @@ -621,7 +621,7 @@ pub fn analyzeSource(gpa: std.mem.Allocator, path: []const u8, content: []const defer tree.destroy(); var result: SourceAnalysis = .{}; errdefer result.deinit(gpa); - if (want_declarations) result.declarations = try declarationsFromTree(gpa, content, tree, null); + if (want_declarations) result.declarations = (try contextFromTree(gpa, content, tree, null, &.{})).declarations; if (want_colors) { result.colors = try gpa.alloc(u8, content.len); @memset(result.colors, 0); @@ -635,23 +635,52 @@ pub fn contextDeclarations(gpa: std.mem.Allocator, path: []const u8, content: [] return analysis.declarations; } -/// The declarations of `content` (its path's language), on a worker -/// (`parseApart`). `halt` ends the parse and the walk early -/// (error.Canceled): a 1.2 MB file is seconds in a Debug build. -pub fn declarationsApart(gpa: std.mem.Allocator, path: []const u8, content: []const u8, halt: *const std.atomic.Value(bool)) ![]ContextDeclaration { - if (content.len == 0) return &.{}; +/// A text's context, from one parse: its declarations (the sticky +/// headers', Locations') and its symbols (the Symbols picker's, UX DESIGN +/// N), both of the same allocator. +pub const Context = struct { + declarations: []ContextDeclaration = &.{}, + symbols: []Symbol = &.{}, + + pub fn deinit(c: *Context, gpa: std.mem.Allocator) void { + gpa.free(c.declarations); + gpa.free(c.symbols); + c.* = .{}; + } +}; + +/// `content`'s context (its path's language), parsed here: a sticky +/// header's (File.refreshContext), a loaded text's. +pub fn context(gpa: std.mem.Allocator, path: []const u8, content: []const u8) !Context { + if (content.len == 0) return .{}; + const spec = byExt(std.Io.Dir.path.extension(path)) orelse return .{}; + const selected = try ensure(spec); + const tree = selected.parser.parseString(content, null) orelse return .{}; + defer tree.destroy(); + return contextFromTree(gpa, content, tree, null, rulesOf(spec.name)); +} + +/// `content`'s context, on a worker (`parseApart`). `halt` ends the parse +/// and the walk early (error.Canceled): a 1.2 MB file is seconds in a +/// Debug build. +pub fn contextApart(gpa: std.mem.Allocator, path: []const u8, content: []const u8, halt: *const std.atomic.Value(bool)) !Context { + if (content.len == 0) return .{}; const ext = std.Io.Dir.path.extension(path); const spec = specs: for (&specs) |*spec| { for (spec.exts) |choice| if (std.ascii.eqlIgnoreCase(ext, choice)) break :specs spec; - } else return &.{}; + } else return .{}; const tree = try parseApart(langOf(spec), content, halt); defer tree.destroy(); - return declarationsFromTree(gpa, content, tree, halt); + return contextFromTree(gpa, content, tree, halt, rulesOf(spec.name)); } -fn declarationsFromTree(gpa: std.mem.Allocator, content: []const u8, tree: *ts.Tree, halt: ?*const std.atomic.Value(bool)) ![]ContextDeclaration { +/// The declarations and, by `rules` (none: no symbols), the symbols of a +/// parse, in one walk of its nodes. +fn contextFromTree(gpa: std.mem.Allocator, content: []const u8, tree: *ts.Tree, halt: ?*const std.atomic.Value(bool), rules: []const Rule) !Context { var result: std.ArrayList(ContextDeclaration) = .empty; errdefer result.deinit(gpa); + var symbols: SymbolWalk = .{ .gpa = gpa, .rules = rules, .source = content }; + errdefer symbols.out.deinit(gpa); // The cursor retains its ancestor stack: sibling visits do not repeatedly // reconstruct parents in broad syntax trees. Preorder preserves source order. var cursor = tree.rootNode().walk(); @@ -661,14 +690,21 @@ fn declarationsFromTree(gpa: std.mem.Allocator, content: []const u8, tree: *ts.T visited += 1; if (halt) |flag| if (visited % 4096 == 0 and flag.load(.monotonic)) return error.Canceled; const node = cursor.node(); - if (node.isNamed()) if (contextSpan(node, content)) |span| { - if (result.items.len == 0 or result.items[result.items.len - 1].start_line != span.start_line or - result.items[result.items.len - 1].end_line != span.end_line) - try result.append(gpa, span); - }; + if (node.isNamed()) { + if (contextSpan(node, content)) |span| { + if (result.items.len == 0 or result.items[result.items.len - 1].start_line != span.start_line or + result.items[result.items.len - 1].end_line != span.end_line) + try result.append(gpa, span); + } + if (rules.len > 0) try symbols.visit(node); + } if (cursor.gotoFirstChild()) continue; while (!cursor.gotoNextSibling()) { - if (!cursor.gotoParent()) return result.toOwnedSlice(gpa); + if (!cursor.gotoParent()) { + const declarations = try result.toOwnedSlice(gpa); + errdefer gpa.free(declarations); + return .{ .declarations = declarations, .symbols = try symbols.out.toOwnedSlice(gpa) }; + } } } } @@ -761,6 +797,527 @@ fn contextSpan(node: ts.Node, source: []const u8) ?ContextDeclaration { }; } +// ---- symbols: the Symbols picker's (UX DESIGN N) ---- + +/// What a symbol is, in the Symbols picker's order (UX DESIGN N2): types, +/// functions, fields, then the rest (consts, vars, modules, other) as one +/// group. A `scope` is listed nowhere: it names its members (Rust's +/// `impl S`: `S.new`). +pub const SymbolKind = enum(u8) { + type, + function, + field, + constant, + variable, + module, + other, + scope, + + /// Its mark in a row (UX DESIGN N4): one letter, `·` for the other. + pub fn mark(k: SymbolKind) []const u8 { + return switch (k) { + .type => "t", + .function => "f", + .field => "m", + .constant => "c", + .variable => "v", + .module => "n", + .other, .scope => "·", + }; + } + + /// Its group in the picker: 0 types, 1 functions, 2 fields, 3 the rest. + pub fn group(k: SymbolKind) u8 { + return @min(@intFromEnum(k), 3); + } +}; + +/// A declaration the Symbols picker lists: its kind, the line and bytes of +/// its name, and the symbol it is declared in. +pub const Symbol = struct { + kind: SymbolKind, + /// The line its name is on, from 0. + line: u32, + name_start: u32, + name_end: u32, + /// Where what its row says after its name ends (a function's + /// signature): its body's start, else its own end. Its row cuts it at + /// its name's line's end. + end: u32, + /// The symbol it is declared in, by its index + 1 (0: none): its name + /// qualifies this one's (`Counts.lines`). + parent: u32 = 0, +}; + +/// How a node of a grammar is a symbol (UX DESIGN N2: one table a language). +const Rule = struct { + node: []const u8, + kind: SymbolKind, + how: How = .plain, + /// The field naming it; without it, its declarator's name (C's) or the + /// first name under it (`nameOf`). "": none (an anonymous scope). + name: []const u8 = "name", + /// A form's first words and the kinds they declare (`.head`). + heads: []const struct { []const u8, SymbolKind } = &.{}, + /// Not one under a node of this kind (Pascal's declProc heading the + /// defProc that is the symbol). + unless_in: []const u8 = "", +}; + +const How = enum { + /// Its kind as given. + plain, + /// Only with a body (C's `struct s { ... }`; `struct s x;` names the + /// type, declares none); unnamed, a scope (an anonymous struct's fields + /// are its owner's). + body, + /// C's declaration: a function where a declarator on the way to its + /// name is one's; else a const where `const` says so (its kind a var). + declarator, + /// A binding whose value tells: a type, a function, a module (Zig's + /// `const S = struct`, `@import`, JavaScript's arrow function); else a + /// const or a var by its keyword. + value, + /// A binding that is a field in a type (a Python class's attribute, + /// Kotlin's property); else a const or a var by its keyword. Named + /// by a name, never a pattern (`self.x = ...`). + binding, + /// A form whose first word says what it declares (Elixir's `def f`, + /// Clojure's `(defn f ...)`), named by its second. + head, + /// No row: a scope its members are named in, by its own name (Rust's + /// `impl S`) or its owner's (an anonymous struct). + scope, +}; + +const c_rules = [_]Rule{ + .{ .node = "function_definition", .kind = .function }, + .{ .node = "declaration", .kind = .variable, .how = .declarator }, + .{ .node = "field_declaration", .kind = .field, .how = .declarator }, + .{ .node = "struct_specifier", .kind = .type, .how = .body }, + .{ .node = "union_specifier", .kind = .type, .how = .body }, + .{ .node = "enum_specifier", .kind = .type, .how = .body }, + .{ .node = "enumerator", .kind = .field }, + .{ .node = "type_definition", .kind = .type }, + .{ .node = "preproc_def", .kind = .other }, + .{ .node = "preproc_function_def", .kind = .other }, +}; + +/// The kind tables, by grammar (grammar_manifest.zig): a grammar with none +/// (JSON, CSS, HTML, Markdown, Typst) lists no symbols. +const symbol_rules = [_]struct { []const u8, []const Rule }{ + .{ "zig", &.{ + // Named by its FnProto's `function` (symbolOf). + .{ .node = "Decl", .kind = .function, .name = "" }, + .{ .node = "VarDecl", .kind = .variable, .how = .value, .name = "variable_type_function" }, + .{ .node = "ContainerField", .kind = .field }, + .{ .node = "TestDecl", .kind = .other, .name = "" }, + .{ .node = "ContainerDecl", .kind = .type, .how = .scope, .name = "" }, + } }, + .{ "c", &c_rules }, + .{ "cpp", &(c_rules ++ [_]Rule{ + .{ .node = "class_specifier", .kind = .type, .how = .body }, + .{ .node = "namespace_definition", .kind = .module }, + .{ .node = "alias_declaration", .kind = .type }, + }) }, + .{ "rust", &.{ + .{ .node = "function_item", .kind = .function }, + .{ .node = "function_signature_item", .kind = .function }, + .{ .node = "struct_item", .kind = .type }, + .{ .node = "enum_item", .kind = .type }, + .{ .node = "union_item", .kind = .type }, + .{ .node = "trait_item", .kind = .type }, + .{ .node = "type_item", .kind = .type }, + .{ .node = "impl_item", .kind = .type, .how = .scope, .name = "type" }, + .{ .node = "field_declaration", .kind = .field }, + .{ .node = "enum_variant", .kind = .field }, + .{ .node = "const_item", .kind = .constant }, + .{ .node = "static_item", .kind = .variable }, + .{ .node = "mod_item", .kind = .module }, + .{ .node = "macro_definition", .kind = .other }, + } }, + .{ "go", &.{ + .{ .node = "function_declaration", .kind = .function }, + .{ .node = "method_declaration", .kind = .function }, + .{ .node = "method_elem", .kind = .function }, + .{ .node = "type_spec", .kind = .type }, + .{ .node = "type_alias", .kind = .type }, + .{ .node = "field_declaration", .kind = .field }, + .{ .node = "const_spec", .kind = .constant }, + .{ .node = "var_spec", .kind = .variable }, + } }, + .{ "python", &.{ + .{ .node = "class_definition", .kind = .type }, + .{ .node = "function_definition", .kind = .function }, + .{ .node = "assignment", .kind = .variable, .how = .binding, .name = "left" }, + } }, + .{ "javascript", &.{ + .{ .node = "function_declaration", .kind = .function }, + .{ .node = "generator_function_declaration", .kind = .function }, + .{ .node = "class_declaration", .kind = .type }, + .{ .node = "method_definition", .kind = .function }, + .{ .node = "field_definition", .kind = .field, .name = "property" }, + .{ .node = "variable_declarator", .kind = .variable, .how = .value }, + } }, + .{ "java", &.{ + .{ .node = "class_declaration", .kind = .type }, + .{ .node = "interface_declaration", .kind = .type }, + .{ .node = "enum_declaration", .kind = .type }, + .{ .node = "record_declaration", .kind = .type }, + .{ .node = "annotation_type_declaration", .kind = .type }, + .{ .node = "method_declaration", .kind = .function }, + .{ .node = "constructor_declaration", .kind = .function }, + .{ .node = "field_declaration", .kind = .field }, + .{ .node = "enum_constant", .kind = .field }, + .{ .node = "constant_declaration", .kind = .constant }, + } }, + .{ "c_sharp", &.{ + .{ .node = "class_declaration", .kind = .type }, + .{ .node = "struct_declaration", .kind = .type }, + .{ .node = "interface_declaration", .kind = .type }, + .{ .node = "enum_declaration", .kind = .type }, + .{ .node = "record_declaration", .kind = .type }, + .{ .node = "delegate_declaration", .kind = .type }, + .{ .node = "namespace_declaration", .kind = .module }, + .{ .node = "file_scoped_namespace_declaration", .kind = .module }, + .{ .node = "method_declaration", .kind = .function }, + .{ .node = "constructor_declaration", .kind = .function }, + .{ .node = "destructor_declaration", .kind = .function }, + .{ .node = "field_declaration", .kind = .field }, + .{ .node = "property_declaration", .kind = .field }, + .{ .node = "event_field_declaration", .kind = .field }, + .{ .node = "enum_member_declaration", .kind = .field }, + } }, + .{ "kotlin", &.{ + .{ .node = "class_declaration", .kind = .type }, + .{ .node = "object_declaration", .kind = .type }, + .{ .node = "companion_object", .kind = .type, .how = .scope, .name = "" }, + .{ .node = "function_declaration", .kind = .function }, + .{ .node = "property_declaration", .kind = .variable, .how = .binding }, + .{ .node = "type_alias", .kind = .type }, + .{ .node = "enum_entry", .kind = .field }, + } }, + .{ "scala", &.{ + .{ .node = "class_definition", .kind = .type }, + .{ .node = "object_definition", .kind = .type }, + .{ .node = "trait_definition", .kind = .type }, + .{ .node = "enum_definition", .kind = .type }, + .{ .node = "type_definition", .kind = .type }, + .{ .node = "function_definition", .kind = .function }, + .{ .node = "function_declaration", .kind = .function }, + .{ .node = "val_definition", .kind = .constant, .how = .binding, .name = "pattern" }, + .{ .node = "var_definition", .kind = .variable, .how = .binding, .name = "pattern" }, + .{ .node = "simple_enum_case", .kind = .field }, + .{ .node = "full_enum_case", .kind = .field }, + } }, + .{ "ruby", &.{ + .{ .node = "class", .kind = .type }, + .{ .node = "singleton_class", .kind = .type, .how = .scope, .name = "" }, + .{ .node = "module", .kind = .module }, + .{ .node = "method", .kind = .function }, + .{ .node = "singleton_method", .kind = .function }, + } }, + .{ "php", &.{ + .{ .node = "class_declaration", .kind = .type }, + .{ .node = "interface_declaration", .kind = .type }, + .{ .node = "trait_declaration", .kind = .type }, + .{ .node = "enum_declaration", .kind = .type }, + .{ .node = "function_definition", .kind = .function }, + .{ .node = "method_declaration", .kind = .function }, + .{ .node = "property_declaration", .kind = .field }, + .{ .node = "enum_case", .kind = .field }, + .{ .node = "const_declaration", .kind = .constant }, + .{ .node = "namespace_definition", .kind = .module }, + } }, + .{ "bash", &.{ + .{ .node = "function_definition", .kind = .function }, + .{ .node = "variable_assignment", .kind = .variable, .how = .binding }, + } }, + .{ "haskell", &.{ + .{ .node = "data_type", .kind = .type }, + .{ .node = "newtype", .kind = .type }, + .{ .node = "type_synomym", .kind = .type }, + .{ .node = "class", .kind = .type }, + .{ .node = "instance", .kind = .type, .how = .scope }, + .{ .node = "function", .kind = .function }, + .{ .node = "bind", .kind = .constant }, + .{ .node = "data_constructor", .kind = .field }, + } }, + .{ "ocaml", &.{ + .{ .node = "type_binding", .kind = .type }, + .{ .node = "module_binding", .kind = .module }, + .{ .node = "module_type_definition", .kind = .type }, + .{ .node = "class_binding", .kind = .type }, + .{ .node = "method_definition", .kind = .function }, + .{ .node = "let_binding", .kind = .constant, .how = .value, .name = "pattern" }, + .{ .node = "field_declaration", .kind = .field }, + .{ .node = "constructor_declaration", .kind = .field }, + } }, + .{ "erlang", &.{ + .{ .node = "fun_decl", .kind = .function }, + .{ .node = "record_decl", .kind = .type }, + .{ .node = "record_field", .kind = .field }, + .{ .node = "type_alias", .kind = .type }, + .{ .node = "pp_define", .kind = .other }, + .{ .node = "module_attribute", .kind = .module }, + } }, + .{ "elixir", &.{ + .{ .node = "call", .kind = .other, .how = .head, .heads = &.{ + .{ "defmodule", .module }, .{ "defprotocol", .type }, .{ "def", .function }, + .{ "defp", .function }, .{ "defdelegate", .function }, .{ "defguard", .function }, + .{ "defguardp", .function }, .{ "defmacro", .other }, .{ "defmacrop", .other }, + } }, + } }, + .{ "clojure", &.{ + .{ .node = "list_lit", .kind = .other, .how = .head, .heads = &.{ + .{ "ns", .module }, .{ "def", .constant }, .{ "defonce", .constant }, .{ "defn", .function }, + .{ "defn-", .function }, .{ "defmulti", .function }, .{ "defmethod", .function }, .{ "defmacro", .other }, + .{ "defrecord", .type }, .{ "deftype", .type }, .{ "defprotocol", .type }, .{ "definterface", .type }, + .{ "defstruct", .type }, + } }, + } }, + .{ "fortran", &.{ + .{ .node = "module", .kind = .module }, + .{ .node = "program", .kind = .module }, + .{ .node = "subroutine", .kind = .function }, + .{ .node = "function", .kind = .function }, + .{ .node = "derived_type_definition", .kind = .type }, + .{ .node = "variable_declaration", .kind = .variable, .how = .binding }, + } }, + .{ "ada", &.{ + .{ .node = "package_declaration", .kind = .module }, + .{ .node = "package_body", .kind = .module }, + .{ .node = "full_type_declaration", .kind = .type }, + .{ .node = "subprogram_declaration", .kind = .function }, + .{ .node = "subprogram_body", .kind = .function }, + .{ .node = "object_declaration", .kind = .variable, .how = .binding }, + .{ .node = "component_declaration", .kind = .field }, + } }, + .{ "pascal", &.{ + .{ .node = "declType", .kind = .type }, + .{ .node = "declProc", .kind = .function, .unless_in = "defProc" }, + .{ .node = "defProc", .kind = .function }, + .{ .node = "declConst", .kind = .constant }, + .{ .node = "declVar", .kind = .variable, .how = .binding }, + .{ .node = "declField", .kind = .field }, + } }, + .{ "powershell", &.{ + .{ .node = "function_statement", .kind = .function }, + .{ .node = "class_statement", .kind = .type }, + .{ .node = "class_method_definition", .kind = .function }, + .{ .node = "class_property_definition", .kind = .field }, + .{ .node = "enum_statement", .kind = .type }, + .{ .node = "enum_member", .kind = .field }, + } }, +}; + +fn rulesOf(grammar: []const u8) []const Rule { + for (symbol_rules) |entry| if (std.mem.eql(u8, entry[0], grammar)) return entry[1]; + return &.{}; +} + +/// A walk's symbols, node by node in preorder (`contextFromTree`). +const SymbolWalk = struct { + gpa: std.mem.Allocator, + rules: []const Rule, + source: []const u8, + out: std.ArrayList(Symbol) = .empty, + /// The scopes the node is in, the innermost last. + scopes: [max_scopes]Scope = undefined, + depth: u8 = 0, + + /// Where a scope ends, its kind, and the symbol its members are named + /// in (an index + 1, 0 none). + const Scope = struct { end: u32, kind: SymbolKind, symbol: u32 }; + /// Deeper scopes are their parent's. + const max_scopes = 32; + + fn visit(w: *SymbolWalk, node: ts.Node) !void { + while (w.depth > 0 and w.scopes[w.depth - 1].end <= node.startByte()) w.depth -= 1; + const in: Scope = if (w.depth > 0) w.scopes[w.depth - 1] else .{ .end = 0, .kind = .module, .symbol = 0 }; + const kind_name = node.kind(); + const rule = for (w.rules) |r| { + if (std.mem.eql(u8, r.node, kind_name)) break r; + } else return; + const found = symbolOf(rule, node, w.source, in.kind) orelse return; + // A body's consts and vars are its locals, none of them listed. + const local = in.kind != .type and in.kind != .module and in.kind != .scope; + if (local and (found.kind == .constant or found.kind == .variable)) return; + var named = in.symbol; + if (found.name) |name| { + try w.out.append(w.gpa, .{ + .kind = found.kind, + .line = name.startPoint().row, + .name_start = name.startByte(), + .name_end = name.endByte(), + .end = found.end, + .parent = in.symbol, + }); + // A const's or a field's members are not named in it. + if (found.kind == .type or found.kind == .function or found.kind == .module or found.kind == .scope) named = @intCast(w.out.items.len); + } + if (w.depth == max_scopes) return; + w.scopes[w.depth] = .{ .end = node.endByte(), .kind = if (found.kind == .scope) rule.kind else found.kind, .symbol = named }; + w.depth += 1; + } +}; + +/// What node `node` declares by `rule`, in a scope of kind `in`: its kind, +/// its name (null: an anonymous scope) and where its row's words end. +fn symbolOf(rule: Rule, node: ts.Node, source: []const u8, in: SymbolKind) ?struct { kind: SymbolKind, name: ?ts.Node, end: u32 } { + if (rule.unless_in.len > 0) if (node.parent()) |up| if (std.mem.eql(u8, up.kind(), rule.unless_in)) return null; + var kind = rule.kind; + var name: ?ts.Node = null; + var end = if (node.childByFieldName("body")) |body| body.startByte() else node.endByte(); + switch (rule.how) { + .plain => name = nameOf(node, rule.name), + .scope => { + name = nameOf(node, rule.name); + kind = .scope; + }, + .body => { + if (node.childByFieldName("body") == null) return null; + name = nameOf(node, rule.name); + if (name == null) kind = .scope; + }, + .declarator => { + var d = node; + while (d.childByFieldName("declarator")) |next| { + if (std.mem.eql(u8, next.kind(), "function_declarator")) kind = .function; + d = next; + } + name = nameOf(node, rule.name); + if (kind == .variable and constant(source, node.startByte(), name orelse return null)) kind = .constant; + }, + .value => { + name = nameOf(node, rule.name); + kind = valueKind(node, source) orelse kind; + // JavaScript's keyword is its declaration's (`const a = 1, b`). + const from = if (std.mem.eql(u8, rule.node, "variable_declarator")) (node.parent() orelse node).startByte() else node.startByte(); + if (kind == .variable and constant(source, from, name orelse return null)) kind = .constant; + }, + .binding => { + const n = node.childByFieldName(rule.name) orelse nameOf(node, rule.name) orelse return null; + if (!nameLike(n.kind())) return null; + name = n; + if (in == .type) kind = .field else if (kind == .variable and constant(source, node.startByte(), n)) kind = .constant; + }, + .head => { + const elixir = std.mem.eql(u8, rule.node, "call"); + const first = (if (elixir) node.childByFieldName("target") else node.namedChild(0)) orelse return null; + const word = source[first.startByte()..first.endByte()]; + kind = for (rule.heads) |h| { + if (std.mem.eql(u8, h[0], word)) break h[1]; + } else return null; + var second = (if (elixir) childOfKind(node, "arguments") else node.namedChild(1)) orelse return null; + if (elixir) second = second.namedChild(0) orelse return null; + if (second.childByFieldName("target")) |target| second = target; + name = if (nameLike(second.kind())) second else nameOf(second, "name"); + }, + } + // Zig's: a function's name is its prototype's, its body a Block; a + // test's its string. + if (std.mem.eql(u8, rule.node, "Decl")) { + const proto = childOfKind(node, "FnProto") orelse return null; + name = proto.childByFieldName("function"); + if (childOfKind(node, "Block")) |block| end = block.startByte(); + } else if (std.mem.eql(u8, rule.node, "TestDecl")) { + const first = node.namedChild(0) orelse return null; + if (std.mem.eql(u8, first.kind(), "Block")) return null; + name = first; + if (childOfKind(node, "Block")) |block| end = block.startByte(); + } + if (name == null and kind != .scope) return null; + if (name) |n| if (n.endByte() <= n.startByte() or n.endByte() - n.startByte() > max_name) return null; + return .{ .kind = kind, .name = name, .end = end }; +} + +/// The longest name a symbol has: a longer one is no name. +const max_name = 200; + +/// The node naming `node`: its field `field`; without one, its declarator's +/// (C's `int *f(void)`: `f`); else the first name under it, past its +/// type, value, body and parameters (Kotlin's, Fortran's). +fn nameOf(node: ts.Node, field: []const u8) ?ts.Node { + if (field.len == 0) return null; + var n = node; + if (node.childByFieldName(field)) |f| n = f else while (n.childByFieldName("declarator")) |d| n = d; + if (nameLike(n.kind())) return n; + if (n.childByFieldName("name")) |f| if (nameLike(f.kind())) return f; + return firstName(n, 3); +} + +fn firstName(node: ts.Node, depth: u8) ?ts.Node { + if (depth == 0) return null; + const skipped = [_][]const u8{ "type", "value", "body", "parameters", "return_type", "returns", "result", "superclass", "arguments", "default", "trait" }; + var i: u32 = 0; + while (i < node.childCount()) : (i += 1) { + const child = node.child(i) orelse continue; + if (!child.isNamed()) continue; + const field = node.fieldNameForChild(i) orelse ""; + if (for (skipped) |s| { + if (std.mem.eql(u8, s, field)) break true; + } else false) continue; + const kind = child.kind(); + if (std.mem.indexOf(u8, kind, "modifier") != null or std.mem.indexOf(u8, kind, "annotation") != null or + std.mem.indexOf(u8, kind, "parameter") != null or std.mem.indexOf(u8, kind, "attribute") != null or + std.mem.indexOf(u8, kind, "decorator") != null or std.mem.indexOf(u8, kind, "comment") != null or + std.mem.indexOf(u8, kind, "literal") != null) continue; + if (nameLike(kind)) return child; + if (firstName(child, depth - 1)) |found| return found; + } + return null; +} + +/// A node kind that is a name: an identifier, a `*_name`, a word. +fn nameLike(kind: []const u8) bool { + if (std.ascii.endsWithIgnoreCase(kind, "identifier") or std.mem.endsWith(u8, kind, "name")) return true; + for ([_][]const u8{ "word", "constant", "atom", "variable", "constructor", "type_constructor", "alias" }) |k| { + if (std.mem.eql(u8, kind, k)) return true; + } + return false; +} + +/// What a binding's value makes it, where it says (else null): Zig's +/// `struct {...}`, `error{...}`, `@This()`, `@Type(...)` a type and +/// `@import(...)` a module; JavaScript's function a function and class a +/// type; OCaml's `let f x = ...` (a parameter) a function. +fn valueKind(node: ts.Node, source: []const u8) ?SymbolKind { + if (node.childByFieldName("value")) |value| { + const kind = value.kind(); + for ([_][]const u8{ "arrow_function", "function_expression", "generator_function" }) |k| if (std.mem.eql(u8, kind, k)) return .function; + if (std.mem.eql(u8, kind, "class")) return .type; + return null; + } + if (childOfKind(node, "parameter") != null) return .function; + // Zig's value: the last of the VarDecl, under its ErrorUnionExpr. + var v = node.namedChild(node.namedChildCount() -| 1) orelse return null; + while (std.mem.eql(u8, v.kind(), "ErrorUnionExpr")) v = v.namedChild(0) orelse return null; + if (!std.mem.eql(u8, v.kind(), "SuffixExpr")) return null; + const first = v.namedChild(0) orelse return null; + const kind = first.kind(); + if (std.mem.eql(u8, kind, "ContainerDecl") or std.mem.eql(u8, kind, "ErrorSetDecl")) return .type; + if (!std.mem.eql(u8, kind, "BUILTINIDENTIFIER")) return null; + const builtin = source[first.startByte()..first.endByte()]; + if (std.mem.eql(u8, builtin, "@This") or std.mem.eql(u8, builtin, "@Type")) return .type; + if ((std.mem.eql(u8, builtin, "@import") or std.mem.eql(u8, builtin, "@cImport")) and v.namedChildCount() == 2) return .module; + return null; +} + +/// Whether a binding is a const: a keyword says so between `from` and its +/// name, or after the name before its value (Ada's `K : constant`). +fn constant(source: []const u8, from: usize, name: ts.Node) bool { + const after = source[name.endByte()..]; + const before_value = std.mem.indexOfAny(u8, after, "=\n") orelse after.len; + for ([_][]const u8{ source[@min(from, name.startByte())..name.startByte()], after[0..before_value] }) |text| { + var words = std.mem.tokenizeAny(u8, text, " \t\r\n,:()*&"); + while (words.next()) |word| for ([_][]const u8{ "const", "constexpr", "val", "final", "readonly", "parameter", "constant" }) |k| { + if (std.mem.eql(u8, word, k)) return true; + }; + } + return false; +} + fn paint(styles: []u8, source: []const u8, selected: Selected) void { const tree = selected.parser.parseString(source, null) orelse return; defer tree.destroy(); @@ -2180,3 +2737,123 @@ test "syntax: a grammar handed in at run time colours and walks as the one compi forgetLanguages(); try std.testing.expect(!supportsPath("x.mine")); } + +/// Each of `source`'s symbols as `mark qualified name`, in the walk's order. +fn symbolLines(gpa: std.mem.Allocator, path: []const u8, source: []const u8) ![]const u8 { + var made = try context(gpa, path, source); + defer made.deinit(gpa); + var out: std.Io.Writer.Allocating = .init(gpa); + defer out.deinit(); + for (made.symbols) |sym| { + if (sym.kind == .scope) continue; + try out.writer.print("{s} ", .{sym.kind.mark()}); + var chain: [8]u32 = undefined; + var n: usize = 0; + var up = sym.parent; + while (up != 0 and n < chain.len) : (up = made.symbols[up - 1].parent) { + chain[n] = up; + n += 1; + } + while (n > 0) { + n -= 1; + const s = made.symbols[chain[n] - 1]; + try out.writer.print("{s}.", .{source[s.name_start..s.name_end]}); + } + try out.writer.print("{s}\n", .{source[sym.name_start..sym.name_end]}); + } + return out.toOwnedSlice(); +} + +test "syntax symbols: a Zig file's types, functions, fields and the rest by their declarations and values, each named in the containers it is in; a function's locals and an unnamed test none of them (UX DESIGN N2)" { + if (comptime !minimal_grammars) return error.SkipZigTest; + const gpa = std.testing.allocator; + start(gpa); + defer stop(); + const source = + \\const std = @import("std"); + \\pub const Counts = struct { + \\ lines: usize = 0, + \\ pub const zero: Counts = .{}; + \\ pub fn add(c: *Counts) void { + \\ const local = 1; + \\ c.lines += local; + \\ } + \\}; + \\const Mode = enum { fast, slow }; + \\const Failure = error{ Late, Lost }; + \\const Self = @This(); + \\var hits: u32 = 0; + \\fn List(comptime T: type) type { + \\ return struct { items: []T }; + \\} + \\test "count" {} + \\test {} + \\extern fn tick() void; + \\ + ; + const lines = try symbolLines(gpa, "a.zig", source); + defer gpa.free(lines); + try std.testing.expectEqualStrings( + \\n std + \\t Counts + \\m Counts.lines + \\c Counts.zero + \\f Counts.add + \\t Mode + \\m Mode.fast + \\m Mode.slow + \\t Failure + \\t Self + \\v hits + \\f List + \\m List.items + \\· "count" + \\f tick + \\ + , lines); +} + +test "syntax symbols: C, C++, Rust, Go, Python and JavaScript by their kind tables, members named in their types, an impl's in its type, locals none" { + if (!full_grammars) return error.SkipZigTest; + const gpa = std.testing.allocator; + start(gpa); + defer stop(); + const cases = [_]struct { path: []const u8, source: []const u8, want: []const u8 }{ + .{ .path = "a.c", .source = "#define LIMIT 4\nstruct point { int x; int *y; };\ntypedef struct { int a; } pair;\nenum color { RED };\nstatic int counter = 0;\nconst int limit = 4;\nint add(int a) { int local = a; return local; }\nint later(void);\nstruct point p;\n", .want = "· LIMIT\nt point\nm point.x\nm point.y\nt pair\nm pair.a\nt color\nm color.RED\nv counter\nc limit\nf add\nf later\nv p\n" }, + .{ .path = "a.cc", .source = "namespace torque {\nclass Parser : public Base {\n public:\n Parser();\n int Parse(int depth) const { return depth; }\n int depth_;\n};\nint Parser::Run(int n) { int local = n; return local; }\nusing Alias = int;\n}\n", .want = "n torque\nt torque.Parser\nf torque.Parser.Parser\nf torque.Parser.Parse\nm torque.Parser.depth_\nf torque.Parser::Run\nt torque.Alias\n" }, + .{ .path = "a.rs", .source = "mod m {\npub struct S { pub a: u32 }\nenum E { A, B(u32) }\ntrait T { fn f(&self); }\nimpl S { pub fn new() -> Self { let x = 1; S { a: x } } }\nconst C: u32 = 1;\nstatic G: u32 = 2;\nmacro_rules! mac { () => {} }\n}\n", .want = "n m\nt m.S\nm m.S.a\nt m.E\nm m.E.A\nm m.E.B\nt m.T\nf m.T.f\nf m.S.new\nc m.C\nv m.G\n· m.mac\n" }, + .{ .path = "a.go", .source = "package main\ntype S struct { A int }\ntype I interface { M() }\nconst C = 1\nvar V = 2\nfunc F() { var x = 1; _ = x }\nfunc (s *S) M() {}\n", .want = "t S\nm S.A\nt I\nf I.M\nc C\nv V\nf F\nf M\n" }, + .{ .path = "a.py", .source = "X = 1\nclass C:\n attr = 2\n def m(self):\n y = 3\n self.z = 4\ndef f():\n pass\n", .want = "v X\nt C\nm C.attr\nf C.m\nf f\n" }, + .{ .path = "a.js", .source = "const A = 1;\nlet b = 2;\nfunction f() { const local = 1; }\nclass K { field = 1; m() {} }\nconst arrow = () => 1;\nconst Klass = class {};\n", .want = "c A\nv b\nf f\nt K\nm K.field\nf K.m\nf arrow\nt Klass\n" }, + }; + for (cases) |case| { + const lines = try symbolLines(gpa, case.path, case.source); + defer gpa.free(lines); + std.testing.expectEqualStrings(case.want, lines) catch |err| { + std.debug.print("in {s}\n", .{case.path}); + return err; + }; + } +} + +test "syntax symbols: every kind table names nodes of its grammar, and a grammar with none (JSON) lists no symbol" { + if (!full_grammars) return error.SkipZigTest; + const gpa = std.testing.allocator; + start(gpa); + defer stop(); + var tables: usize = 0; + for (symbol_rules) |entry| { + const spec = for (&specs) |*spec| { + if (std.mem.eql(u8, spec.name, entry[0])) break spec; + } else return error.NoGrammar; + for (entry[1]) |rule| std.testing.expect(langOf(spec).idForNodeKind(rule.node, true) != 0) catch |err| { + std.debug.print("{s} has no node {s}\n", .{ entry[0], rule.node }); + return err; + }; + tables += 1; + } + try std.testing.expectEqual(@as(usize, 23), tables); + var made = try context(gpa, "a.json", "{\"a\": 1}\n"); + defer made.deinit(gpa); + try std.testing.expectEqual(@as(usize, 0), made.symbols.len); +} -- cgit v1.3 From 8393c24f76675f182055149645c10af3102b739e Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 02:49:36 -0300 Subject: lsp_client, Output, lspmock, syntax, Pick, Query, docs: the Symbols builtin (a language server's documentSymbol) gives the Symbols picker's marks and order (UX DESIGN N, binding: "The builtin `Symbols` keeps reading the server but gets the same mark, order and qualified names, from `SymbolKind`"): walkSymbols keeps each symbol's SymbolKind, mapped onto N2's kinds (5 Class, 10 Enum, 11 Interface, 23 Struct, 26 TypeParameter a type; 6 Method, 9 Constructor, 12 Function, 25 Operator a function; 7 Property, 8 Field, 22 EnumMember a field; 14 Constant a const; 13 Variable, 15 to 21 and 24 a var; 1 File to 4 Package a module; any other the other), and names each in the ones it is in (a DocumentSymbol's nesting, a SymbolInformation's `containerName`): a row is `shapes.rs:5:5-8 m Shape.side`, the rows types, functions, fields, then the rest, each in the server's order; the +Search keeps that order: a file's symbols are neither sorted by their places (Output.sortResults) nor laid out as Locations, which put a file's rows in their lines' order (Output.usesLocationsConfig): a row each, as the picker lists them; the walk's list picker (`Jumps walk`, Ask's) takes them in that order (tty `lsp` with zls: `f helper`, `f main`, `c std`, was `std`, `helper`, `main`); an index's Symbols (SCIP, dev/lsp/Scip.zig) keep their rows unmarked, one row each now too; the mock answers documentSymbol with a nested list in no kind's order (a const, a function, a struct with a field and a method, an enum with a member, a module); docs/typ guide's `Symbols name` and the reference's Symbols say the marks and the order; and three faults of the change before's rows, which its pictures showed (each TEST FIRST: the syntax.zig and Pick.zig tests failed with them first; the pattern guard came with its JavaScript case, not before it): a test whose name is longer than 200 bytes was no symbol, so its body was no scope and its local structs and functions were listed as types and functions (Pick.zig's own tests: `t typeIn = struct`): a name that long is cut, on a character, and a test's body lists nothing (370 rows of core/Pick.zig to 247); a name field is taken whole when it is one line (C++'s `namespace v8::internal::torque` named `v8`, now whole; a value binding's must still be a name, never a pattern: `const { x, y } = a`, OCaml's `let () =`); the qualifier dimmed in a row ran to the name's last `.`, a test's sentence's (`(SPEC §6.3, §7.3)` dimmed most of it): it is the candidate's `base` now, the qualifier's length from the gather, which also gives the scorer its basename bonus on the name; core/root.zig's import of syntax.zig (the change before) says what it does: without it a -Dtest-filter run compiles none of syntax.zig's tests, while a whole run has them (core-test 1135/1308 with it or without it; the change before said they ran nowhere: wrong); RUN (TEST FIRST): test/behaviour/language_servers.zig "language-servers: a server's Symbols are the Symbols picker's rows ..." opens shapes.rs with no index (the server asked) and asks the +Search's rows in that order: with walkSymbols' marks alone they came in their lines' order (`c LIMIT`, `f main`, `t Shape`, ...: the sort and the Locations layout), passes now; the index's Symbols test asks one row each (`lib.rs:1:11-15 Shape`); test/snapshots/lsp.golden re-recorded: only its symbols snap's three rows (marked and grouped) and the preview landing on their first, `helper`'s line 3; GATES on this stack (the change before under it): core-test 1135/1308 (173 skipped; base 1127/1301 with the base's one failure, a CPU-time test under load: colors' "the whole ring resolves in 150 ms"), shell-test 1356/1359 (3 skipped), pane-test 183/184 (1 skipped), behaviour-test 281/281 and --replay 281/281, process-test 1 of 147 failed (tty editing: lsp, its golden: re-recorded, the ten `tty editing: lsp` cases 0 of 10 failed), term-test 17/17, kitty-test 45/45; the dump fuzz (Names.Cand.group, Stream.Batch.symbols) at 40,000 join seeds twice and 1,779 image seeds 13/13; the soak `replicas -- --clients 5 --rtt 30,80,207`: diverged 0, unequal 0, quiet checks 421/0 415/0 590/0, unlisted stops 0, the corpus 22 of 22 scenes the same, no leak; the gui unit-test 1960/1964 (4 skipped; its one failure the perf check's BaselineHarnessMismatch, every base's); core-test, shell-test, pane-test and behaviour-test again after the three faults: the same counts; the pictures (the S kit at 26 px, neonotte84, 100x30, typed through the pty; .scratch/walkui/W6/png): today's install (install74) beside this tree's Debug gui, SPC s s on core/Pick.zig (today 127 rows of declarations, `pub fn deinit(...` first; here 247, `t Pick = @This()` first, the types, then the functions ...) and on V8's torque-parser.cc (today 132, here 273 under `v8::internal::torque.`), and `count` typed (today the cursor on `count`, then `paneCount` and every row whose signature holds c-o-u-n-t, `[]const u8` among them; here `f count` current, `f paneCount`, `c counts_zig`, then the tests whose sentences match); no frame or perf gate (the user's rule of 2026-11-26); load 3.0 to 14.2 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/Output.zig | 9 +++++-- core/Pick.zig | 10 ++++---- core/Query.zig | 7 ++++-- core/root.zig | 2 +- core/syntax.zig | 48 +++++++++++++++++++++++++++---------- dev/lsp/lsp_client.zig | 39 +++++++++++++++++++++++++----- docs/typ/guide.typ | 2 +- docs/typ/reference.typ | 3 ++- test/behaviour/language_servers.zig | 25 ++++++++++++++++++- test/lspmock.zig | 11 +++++++-- test/snapshots/lsp.golden | 12 +++++----- 11 files changed, 130 insertions(+), 38 deletions(-) (limited to 'core/syntax.zig') diff --git a/core/Output.zig b/core/Output.zig index fe1543fe..e55ff4a3 100644 --- a/core/Output.zig +++ b/core/Output.zig @@ -198,11 +198,15 @@ pub fn traits(o: Origin) Traits { }; } +/// A list laid out as Locations (each place's lines from its file, in +/// their order): not a file's symbols, a row each in their own order (UX +/// DESIGN N: types, functions, fields, the rest). pub fn usesLocationsConfig(from: Origin) bool { const tr = traits(from); return tr.steps and !tr.commands and from != .kind and !std.meta.eql(from, Origin{ .query = .completion }) and - !std.meta.eql(from, Origin{ .query = .callstack }); + !std.meta.eql(from, Origin{ .query = .callstack }) and + !std.meta.eql(from, Origin{ .query = .document_symbols }); } pub fn fileTraits(out: ?State) Traits { @@ -244,6 +248,8 @@ pub fn isResultRow(file: *const File.State, row: usize) bool { return !locations.isContextLine(modal.lineSlice(file.content, row)); } +/// A language server's places in the order of their places; a file's +/// symbols stay in theirs (lsp_client: types, functions, fields, the rest). fn sortResults(arena: std.mem.Allocator, from: Origin, content: []u8, anchor: ?usize) !?usize { switch (from) { .search => {}, @@ -258,7 +264,6 @@ fn sortResults(arena: std.mem.Allocator, from: Origin, content: []u8, anchor: ?u .outgoing_calls, .supertypes, .subtypes, - .document_symbols, .workspace_symbols, .diagnostics, .workspace_diagnostics, diff --git a/core/Pick.zig b/core/Pick.zig index 2b5714cb..dcb838f3 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -677,10 +677,9 @@ fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) std.me for (marks_in, row.marks) |*m, at| m.* = at -| line; row.marks = marks_in; const name_at = cand.key - line; - const dot = std.mem.lastIndexOfScalar(u8, row.text[name_at .. name_at + cand.key_len], '.'); row.kind = @intCast(name_at - 1); row.pre = @intCast(name_at); - row.faint = @intCast(if (dot) |at| at + 1 else 0); + row.faint = cand.base; if (name_at + cand.key_len < row.text.len) row.quiet = .{ @intCast(name_at + cand.key_len), @intCast(row.text.len) }; const owner = p.panes[p.paneBySerial(pk.owner) orelse return row] orelse return row; const f = owner.file orelse return row; @@ -3357,7 +3356,7 @@ const counts_zig = \\pub fn count(text: []const u8) Counts { \\ return .{ .lines = text.len }; \\} - \\test "count" {} + \\test "count.add" {} \\ ; @@ -3381,9 +3380,12 @@ test "Symbols (UX DESIGN N): a Zig file's rows types, functions, fields, then th \\ 1 n std = @import("std") \\ 5 c Counts.zero : Counts = .{} \\12 v hits : u32 = 0 - \\16 · "count" + \\16 · "count.add" \\ , try rowLines(p, a)); + // The qualifier dim, `Counts.`; a name holding a `.` none of it. + try std.testing.expectEqual(@as(u16, "Counts.".len), (try rowAt(p, live(p).?, a, 4)).faint); + try std.testing.expectEqual(@as(u16, 0), (try rowAt(p, live(p).?, a, 11)).faint); // Drawn: `m Counts.lines : usize = 0` (not the cursor's row). const pane = p.panes[p.paneBySerial(live(p).?.landing).?].?; _ = try p.render(a); diff --git a/core/Query.zig b/core/Query.zig index 743e9540..a5926e23 100644 --- a/core/Query.zig +++ b/core/Query.zig @@ -785,7 +785,8 @@ pub fn gather(p: *Pardes, names: *Names, source: Source, dir: []const u8, self: // 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. + // The qualified name alone is matched, its own name the + // basename. 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; @@ -793,13 +794,15 @@ pub fn gather(p: *Pardes, names: *Names, source: Source, dir: []const u8, self: 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; + // The name its basename: the qualifier dim (Pick.rowAt). + const base = row.end - key_at; 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.add(gpa, row.buffered(), key_at, key_len, @intCast(base), sym.line + 1) catch break; names.cands.items[names.cands.items.len - 1].group = @intCast(group); }; }, diff --git a/core/root.zig b/core/root.zig index 86ca62e0..a9c95a96 100644 --- a/core/root.zig +++ b/core/root.zig @@ -461,7 +461,7 @@ test { _ = @import("FrameStats.zig"); _ = @import("Query.zig"); _ = @import("Names.zig"); - _ = @import("syntax.zig"); // its tests ran nowhere before + _ = @import("syntax.zig"); // without it a -Dtest-filter run compiles none of its tests (a whole run has them) _ = @import("Stream.zig"); _ = @import("Tables.zig"); _ = @import("Handover.zig"); diff --git a/core/syntax.zig b/core/syntax.zig index 5cdc2ff3..9fbad3cf 100644 --- a/core/syntax.zig +++ b/core/syntax.zig @@ -1135,6 +1135,9 @@ const SymbolWalk = struct { fn visit(w: *SymbolWalk, node: ts.Node) !void { while (w.depth > 0 and w.scopes[w.depth - 1].end <= node.startByte()) w.depth -= 1; const in: Scope = if (w.depth > 0) w.scopes[w.depth - 1] else .{ .end = 0, .kind = .module, .symbol = 0 }; + // A test's body (a macro's) lists nothing: its types are its + // locals' (a test's `const Find = struct`). + if (in.kind == .other) return; const kind_name = node.kind(); const rule = for (w.rules) |r| { if (std.mem.eql(u8, r.node, kind_name)) break r; @@ -1145,11 +1148,17 @@ const SymbolWalk = struct { if (local and (found.kind == .constant or found.kind == .variable)) return; var named = in.symbol; if (found.name) |name| { + // A longer name is cut (a test's sentence), on a character. + var end = name.endByte(); + if (end - name.startByte() > max_name) { + end = name.startByte() + max_name; + while (end > name.startByte() and w.source[end] & 0xc0 == 0x80) end -= 1; + } try w.out.append(w.gpa, .{ .kind = found.kind, .line = name.startPoint().row, .name_start = name.startByte(), - .name_end = name.endByte(), + .name_end = end, .end = found.end, .parent = in.symbol, }); @@ -1190,7 +1199,10 @@ fn symbolOf(rule: Rule, node: ts.Node, source: []const u8, in: SymbolKind) ?stru if (kind == .variable and constant(source, node.startByte(), name orelse return null)) kind = .constant; }, .value => { + // Named by a name, never a pattern (`const { a, b } = ...`, + // OCaml's `let () = ...`). name = nameOf(node, rule.name); + if (name) |n| if (!nameLike(n.kind())) return null; kind = valueKind(node, source) orelse kind; // JavaScript's keyword is its declaration's (`const a = 1, b`). const from = if (std.mem.eql(u8, rule.node, "variable_declarator")) (node.parent() orelse node).startByte() else node.startByte(); @@ -1228,20 +1240,24 @@ fn symbolOf(rule: Rule, node: ts.Node, source: []const u8, in: SymbolKind) ?stru if (childOfKind(node, "Block")) |block| end = block.startByte(); } if (name == null and kind != .scope) return null; - if (name) |n| if (n.endByte() <= n.startByte() or n.endByte() - n.startByte() > max_name) return null; + if (name) |n| if (n.endByte() <= n.startByte()) return null; return .{ .kind = kind, .name = name, .end = end }; } -/// The longest name a symbol has: a longer one is no name. +/// The longest name a symbol has: a longer one is cut. const max_name = 200; -/// The node naming `node`: its field `field`; without one, its declarator's -/// (C's `int *f(void)`: `f`); else the first name under it, past its -/// type, value, body and parameters (Kotlin's, Fortran's). +/// The node naming `node`: its field `field`, whole on its line (C++'s +/// `namespace v8::internal`, Rust's `impl Vec`); without one, its +/// declarator's (C's `int *f(void)`: `f`); else the first name under it, +/// past its type, value, body and parameters (Kotlin's, Fortran's). fn nameOf(node: ts.Node, field: []const u8) ?ts.Node { if (field.len == 0) return null; var n = node; - if (node.childByFieldName(field)) |f| n = f else while (n.childByFieldName("declarator")) |d| n = d; + if (node.childByFieldName(field)) |f| { + if (f.startPoint().row == f.endPoint().row) return f; + n = f; + } else while (n.childByFieldName("declarator")) |d| n = d; if (nameLike(n.kind())) return n; if (n.childByFieldName("name")) |f| if (nameLike(f.kind())) return f; return firstName(n, 3); @@ -2786,12 +2802,20 @@ test "syntax symbols: a Zig file's types, functions, fields and the rest by thei \\fn List(comptime T: type) type { \\ return struct { items: []T }; \\} - \\test "count" {} + \\test "count" { + \\ const Local = struct { + \\ fn helper() void {} + \\ }; + \\ _ = Local; + \\} \\test {} \\extern fn tick() void; \\ ; - const lines = try symbolLines(gpa, "a.zig", source); + // A test's name longer than a row's room is cut, its body still none. + const xs: [250]u8 = @splat('x'); + const long = "test \"" ++ xs ++ "\" {\n const Inner = struct {};\n _ = Inner;\n}\n"; + const lines = try symbolLines(gpa, "a.zig", source ++ long); defer gpa.free(lines); try std.testing.expectEqualStrings( \\n std @@ -2810,7 +2834,7 @@ test "syntax symbols: a Zig file's types, functions, fields and the rest by thei \\· "count" \\f tick \\ - , lines); + ++ "· \"" ++ xs[0 .. max_name - 1].* ++ "\n", lines); } test "syntax symbols: C, C++, Rust, Go, Python and JavaScript by their kind tables, members named in their types, an impl's in its type, locals none" { @@ -2820,11 +2844,11 @@ test "syntax symbols: C, C++, Rust, Go, Python and JavaScript by their kind tabl defer stop(); const cases = [_]struct { path: []const u8, source: []const u8, want: []const u8 }{ .{ .path = "a.c", .source = "#define LIMIT 4\nstruct point { int x; int *y; };\ntypedef struct { int a; } pair;\nenum color { RED };\nstatic int counter = 0;\nconst int limit = 4;\nint add(int a) { int local = a; return local; }\nint later(void);\nstruct point p;\n", .want = "· LIMIT\nt point\nm point.x\nm point.y\nt pair\nm pair.a\nt color\nm color.RED\nv counter\nc limit\nf add\nf later\nv p\n" }, - .{ .path = "a.cc", .source = "namespace torque {\nclass Parser : public Base {\n public:\n Parser();\n int Parse(int depth) const { return depth; }\n int depth_;\n};\nint Parser::Run(int n) { int local = n; return local; }\nusing Alias = int;\n}\n", .want = "n torque\nt torque.Parser\nf torque.Parser.Parser\nf torque.Parser.Parse\nm torque.Parser.depth_\nf torque.Parser::Run\nt torque.Alias\n" }, + .{ .path = "a.cc", .source = "namespace torque {\nclass Parser : public Base {\n public:\n Parser();\n int Parse(int depth) const { return depth; }\n int depth_;\n};\nint Parser::Run(int n) { int local = n; return local; }\nusing Alias = int;\n}\nnamespace v8::internal {\nint flags;\n}\n", .want = "n torque\nt torque.Parser\nf torque.Parser.Parser\nf torque.Parser.Parse\nm torque.Parser.depth_\nf torque.Parser::Run\nt torque.Alias\nn v8::internal\nv v8::internal.flags\n" }, .{ .path = "a.rs", .source = "mod m {\npub struct S { pub a: u32 }\nenum E { A, B(u32) }\ntrait T { fn f(&self); }\nimpl S { pub fn new() -> Self { let x = 1; S { a: x } } }\nconst C: u32 = 1;\nstatic G: u32 = 2;\nmacro_rules! mac { () => {} }\n}\n", .want = "n m\nt m.S\nm m.S.a\nt m.E\nm m.E.A\nm m.E.B\nt m.T\nf m.T.f\nf m.S.new\nc m.C\nv m.G\n· m.mac\n" }, .{ .path = "a.go", .source = "package main\ntype S struct { A int }\ntype I interface { M() }\nconst C = 1\nvar V = 2\nfunc F() { var x = 1; _ = x }\nfunc (s *S) M() {}\n", .want = "t S\nm S.A\nt I\nf I.M\nc C\nv V\nf F\nf M\n" }, .{ .path = "a.py", .source = "X = 1\nclass C:\n attr = 2\n def m(self):\n y = 3\n self.z = 4\ndef f():\n pass\n", .want = "v X\nt C\nm C.attr\nf C.m\nf f\n" }, - .{ .path = "a.js", .source = "const A = 1;\nlet b = 2;\nfunction f() { const local = 1; }\nclass K { field = 1; m() {} }\nconst arrow = () => 1;\nconst Klass = class {};\n", .want = "c A\nv b\nf f\nt K\nm K.field\nf K.m\nf arrow\nt Klass\n" }, + .{ .path = "a.js", .source = "const A = 1;\nlet b = 2;\nfunction f() { const local = 1; }\nclass K { field = 1; m() {} }\nconst arrow = () => 1;\nconst Klass = class {};\nconst { x, y } = A;\n", .want = "c A\nv b\nf f\nt K\nm K.field\nf K.m\nf arrow\nt Klass\n" }, }; for (cases) |case| { const lines = try symbolLines(gpa, case.path, case.source); diff --git a/dev/lsp/lsp_client.zig b/dev/lsp/lsp_client.zig index a53ff57f..b76be78c 100644 --- a/dev/lsp/lsp_client.zig +++ b/dev/lsp/lsp_client.zig @@ -50,6 +50,7 @@ const std = @import("std"); const builtin = @import("builtin"); const libc = std.c; const lsp = @import("core").lsp; +const SymbolKind = @import("core").syntax.SymbolKind; const Scip = @import("Scip.zig"); extern "c" fn execv(path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8) c_int; @@ -1002,7 +1003,11 @@ fn run(c: *Conn, io: std.Io, si: usize, arena: std.mem.Allocator, req: lsp.Req, .document_symbols => { const b = try docParams(arena, uri.items); const result = (try call(c, io, arena, "textDocument/documentSymbol", b.items, deadline)) orelse return; - try walkSymbols(&cx, c.caps.enc, uri.items, result, 0); + // Types, functions, fields, then the rest, each in the + // server's order (UX DESIGN N, the Symbols picker's). + var found: std.ArrayList(Symbol) = .empty; + try walkSymbols(arena, &found, uri.items, result, "", 0); + for (0..4) |group| for (found.items) |sym| if (sym.kind.group() == group) try emitRange(&cx, c.caps.enc, sym.uri, sym.range, sym.note); }, .workspace_symbols => { var b: std.ArrayList(u8) = .empty; @@ -1106,20 +1111,42 @@ fn locations(cx: *Cx, enc: Enc, result: std.json.Value) Err!void { } } -/// DocumentSymbol[] nests (`children`), SymbolInformation[] is flat. -fn walkSymbols(cx: *Cx, enc: Enc, uri: []const u8, node: std.json.Value, depth: u8) Err!void { +/// A symbol a server listed: its row's place and words, `t Shape.area`. +const Symbol = struct { kind: SymbolKind, uri: []const u8, range: ?std.json.Value, note: []const u8 }; + +/// DocumentSymbol[] nests (`children`), SymbolInformation[] is flat: each +/// its kind's mark and its name qualified by the ones it is in (the +/// nesting, or SymbolInformation's `containerName`), into `out`. +fn walkSymbols(arena: std.mem.Allocator, out: *std.ArrayList(Symbol), uri: []const u8, node: std.json.Value, qualifier: []const u8, depth: u8) Err!void { if (depth > 8) return; for (items(node)) |sym| { const name = str(get(sym, "name")) orelse continue; + const kind = symbolKind(num(get(sym, "kind")) orelse 0); + const container = if (qualifier.len > 0) qualifier else str(get(sym, "containerName")) orelse ""; + const qualified = if (container.len > 0) try std.fmt.allocPrint(arena, "{s}.{s}", .{ container, name }) else name; + const note = try std.fmt.allocPrint(arena, "{s} {s}", .{ kind.mark(), qualified }); if (get(get(sym, "location"), "range")) |r| { - try emitRange(cx, enc, str(get(get(sym, "location"), "uri")) orelse uri, r, name); + try out.append(arena, .{ .kind = kind, .uri = str(get(get(sym, "location"), "uri")) orelse uri, .range = r, .note = note }); } else { - try emitRange(cx, enc, uri, get(sym, "selectionRange") orelse get(sym, "range"), name); + try out.append(arena, .{ .kind = kind, .uri = uri, .range = get(sym, "selectionRange") orelse get(sym, "range"), .note = note }); } - if (get(sym, "children")) |kids| try walkSymbols(cx, enc, uri, kids, depth + 1); + if (get(sym, "children")) |kids| try walkSymbols(arena, out, uri, kids, qualified, depth + 1); } } +/// LSP's SymbolKind as the Symbols picker's (UX DESIGN N2). +fn symbolKind(lsp_kind: i64) SymbolKind { + return switch (lsp_kind) { + 5, 10, 11, 23, 26 => .type, + 6, 9, 12, 25 => .function, + 7, 8, 22 => .field, + 14 => .constant, + 13, 15...21, 24 => .variable, + 1...4 => .module, + else => .other, + }; +} + /// Pull when the server does (LSP 3.17), the push store otherwise. The store /// path waits briefly for a publish that postdates the didChange we just /// sent, so `]d` right after an edit sees the new truth, not the old one. diff --git a/docs/typ/guide.typ b/docs/typ/guide.typ index 66d3bb00..d80302c5 100644 --- a/docs/typ/guide.typ +++ b/docs/typ/guide.typ @@ -207,7 +207,7 @@ Line 1's first word names what it searches, and editing the word changes it: [`Grep text`], [the lines of those files holding `text`, literally (#key("SPC f g"), #word("Grep")); past 2000 lines #word("More") goes on], [`Recent name`], [the files opened lately, in any window (#key("SPC f r"), #word("Recent"))], [`Panes name`], [the open panes, then the ones closed this session, `(closed)` and dimmer: #key("Enter") (or a #word("Look") at its `@pN`) brings one back where it was, its text with it (#key("SPC b b"), #word("Panes"))], - [`Symbols name`], [the text's declarations (#key("SPC s s"))], + [`Symbols name`], [the text's symbols, a row each: its kind's mark (`t` type, `f` function, `m` field, `c` const, `v` var, `n` module, `·` other), its name in the ones it is in (`Counts.lines`), what its line says after the name; types, functions, fields, then the rest, each in the text's order, and so while typed, the best match current (#key("SPC s s"))], [`All pat`], [every open pane's text, its rows under each pane (#key("SPC /"))], [`Refs`, `Def`, `Impl`, `Diagnostics`], [the language server's lists (#key("g r"), #key("g d"), #key("g i"), #key("SPC l d")): one answer is a jump, none a message; several open the list with the keyboard on its current row in normal mode (#keys("j", "k", "n", "N") step it, #key("Enter") lands, #key("Esc") goes back), the diagnostics' keeping it in the text for `]d`; their places in the text tinted as a `/`'s are], ) diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ index 42b44fc9..035625cf 100644 --- a/docs/typ/reference.typ +++ b/docs/typ/reference.typ @@ -290,7 +290,8 @@ A line written to #file("exec") is #word("Exec"): runtime depth (1–64, default 8) for subsequent queries. #word("Callers") and #word("Callees") keep their short lists and single-result jumps. - #word("Diagnostics") and #word("Symbols") list the file's in `+Search`; + #word("Diagnostics") and #word("Symbols") list the file's in `+Search` + (its symbols marked and in the order #key("SPC s s") lists them); #word("Lspinfo") fills `+Lsp`, the pane its write answers, with the index the file asks (`scip: , , , , indexed , files newer`, or `scip: no index.scip above ; diff --git a/test/behaviour/language_servers.zig b/test/behaviour/language_servers.zig index 13e42fa6..80d1cb1e 100644 --- a/test/behaviour/language_servers.zig +++ b/test/behaviour/language_servers.zig @@ -206,7 +206,7 @@ test "language-servers: Symbols lists the file's definitions by name, a local's try s.write(s.at("/pane/{d}/look", .{main}), s.at("{s}/lib.rs\n", .{std.fs.path.dirname(std.mem.trimEnd(u8, try s.read(s.at("/pane/{d}/name", .{main})), "\n")).?})); try s.write(s.at("/pane/{d}/ctl", .{try s.focused()}), "Symbols\n"); const rows = try bodyOf(&s, "+Search"); - for ([_][]const u8{ "lib.rs:1:11-15\nShape\n", "lib.rs:2:8-11\narea\n", "lib.rs:5:8-10\nadd\n", "lib.rs:8:12-17\nSquare\n", "lib.rs:10:8-11\narea\n" }) |row| + for ([_][]const u8{ "lib.rs:1:11-15 Shape\n", "lib.rs:2:8-11 area\n", "lib.rs:5:8-10 add\n", "lib.rs:8:12-17 Square\n", "lib.rs:10:8-11 area\n" }) |row| try std.testing.expect(has(rows, row)); try std.testing.expect(!has(rows, "lib.rs:5:12")); } @@ -323,3 +323,26 @@ test "language-servers: SPC l a lists the server's code actions in the pane's ta try s.keys("u"); try s.expect(body, before); } + +test "language-servers: a server's Symbols are the Symbols picker's rows: types, functions, fields, then the rest, each its kind's mark and its name in the ones it is in (UX DESIGN N)" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + var s = try Session.initLanguage(std.testing.allocator); + defer s.deinit(); + try s.write("/ctl", "Jumps new-pane\n"); + // No index: the server is asked. + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "shapes.rs", .data = "const LIMIT: u32 = 4;\n\nfn main() {}\npub struct Shape {\n side: u32,\n fn area() {}\n}\nenum Kind {\n Round,\n}\nmod lib;\n" }); + var buf: [4096]u8 = undefined; + const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)]; + const shapes = try s.lookFile(s.at("{s}/shapes.rs:1:1", .{dir})); + try s.write(s.at("/pane/{d}/ctl", .{shapes}), "Symbols\n"); + const rows = try bodyOf(&s, "+Search"); + var at: usize = 0; + for ([_][]const u8{ "shapes.rs:4:12-16 t Shape\n", "shapes.rs:8:6-9 t Kind\n", "shapes.rs:3:4-7 f main\n", "shapes.rs:6:8-11 f Shape.area\n", "shapes.rs:5:5-8 m Shape.side\n", "shapes.rs:9:5-9 m Kind.Round\n", "shapes.rs:1:7-11 c LIMIT\n", "shapes.rs:11:5-7 n lib\n" }) |row| { + const found = std.mem.indexOfPos(u8, rows, at, row) orelse { + std.debug.print("{s} not after {d} in\n{s}\n", .{ row, at, rows }); + return error.TestUnexpectedResult; + }; + at = found + row.len; + } +} diff --git a/test/lspmock.zig b/test/lspmock.zig index 0fd34677..6f52f568 100644 --- a/test/lspmock.zig +++ b/test/lspmock.zig @@ -257,8 +257,15 @@ fn handle(a: std.mem.Allocator, raw: []const u8) void { } else if (std.mem.eql(u8, method, "textDocument/hover")) { reply(a, rid, "{{\"contents\":{{\"kind\":\"markdown\",\"value\":\"mock hover: pub fn add\"}}}}", .{}); } else if (std.mem.eql(u8, method, "textDocument/documentSymbol")) { - reply(a, rid, "[{{\"name\":\"main\",\"kind\":12,\"range\":{s},\"selectionRange\":{s}}}]", .{ - range(a, 2, 0, 11), range(a, 2, 3, 7), + // Nested and in no kind's order: a const, a function, a struct + // with a field and a method, an enum with a member, a module. + reply(a, rid, "[{{\"name\":\"LIMIT\",\"kind\":14,\"range\":{s},\"selectionRange\":{s}}},{{\"name\":\"main\",\"kind\":12,\"range\":{s},\"selectionRange\":{s}}}," ++ + "{{\"name\":\"Shape\",\"kind\":23,\"range\":{s},\"selectionRange\":{s},\"children\":[{{\"name\":\"side\",\"kind\":8,\"range\":{s},\"selectionRange\":{s}}},{{\"name\":\"area\",\"kind\":6,\"range\":{s},\"selectionRange\":{s}}}]}}," ++ + "{{\"name\":\"Kind\",\"kind\":10,\"range\":{s},\"selectionRange\":{s},\"children\":[{{\"name\":\"Round\",\"kind\":22,\"range\":{s},\"selectionRange\":{s}}}]}},{{\"name\":\"lib\",\"kind\":2,\"range\":{s},\"selectionRange\":{s}}}]", .{ + range(a, 0, 0, 21), range(a, 0, 6, 11), range(a, 2, 0, 11), range(a, 2, 3, 7), + range(a, 3, 0, 18), range(a, 3, 11, 16), range(a, 4, 4, 14), range(a, 4, 4, 8), + range(a, 5, 4, 16), range(a, 5, 7, 11), range(a, 7, 0, 11), range(a, 7, 5, 9), + range(a, 8, 4, 10), range(a, 8, 4, 9), range(a, 10, 0, 8), range(a, 10, 4, 7), }); } else if (std.mem.eql(u8, method, "workspace/symbol")) { const q = str(get(params, "query")) orelse ""; diff --git a/test/snapshots/lsp.golden b/test/snapshots/lsp.golden index c680700d..0db3b21e 100644 --- a/test/snapshots/lsp.golden +++ b/test/snapshots/lsp.golden @@ -59,13 +59,13 @@ == snap symbols grid=120x41 cursor=24,2 |2: ^ a.zig:8 › ␣ l Symbols 1/3 |3: │ │ Walk Look Split Newcol Grep Edit Copy Keep Drop | Find Grep Recent Panes Symbols All Jumplist -|4: │ │ ▶ a.zig:1:7-9 std -|5: │ │ a.zig:3:4-9 helper -|6: │ │ a.zig:7:8-11 main +|4: │ │ ▶ a.zig:3:4-9 f helper +|5: │ │ a.zig:7:8-11 f main +|6: │ │ a.zig:1:7-9 c std |7: │ │ -|8: 1▸const std = @import("std"); +|8: 1 const std = @import("std"); |9: 2 -|10: 3 fn helper(x: u32) u32 { +|10: 3▸fn helper(x: u32) u32 { |11: fn helper(x: u32) u32 |12: (fn (u32) u32) |13: 4 return x + 1; @@ -81,6 +81,6 @@ |4: │ │ nothing matches |5: │ │ |6: │ │ -|8: 1 const std = @import("std"); +|10: 3 fn helper(x: u32) u32 { == snap nothing grid=120x41 cursor=29,2 |2: ^ a.zig:8 › ␣ l Symbols jngd 0 -- cgit v1.3