summaryrefslogtreecommitdiff
path: root/core/syntax.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-26 02:49:36 -0300
committerGabriel Schneider <[email protected]>2026-11-26 04:10:54 -0300
commit8393c24f76675f182055149645c10af3102b739e (patch)
tree3844cb4b77d4225d604e7ad18dbf6dfd64dc72de /core/syntax.zig
parent148e48dd9b8cd7e66aa1521daa49a64852b1650e (diff)
downloadpardes-8393c24f76675f182055149645c10af3102b739e.tar.gz
pardes-8393c24f76675f182055149645c10af3102b739e.zip
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
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core/syntax.zig')
-rw-r--r--core/syntax.zig48
1 files changed, 36 insertions, 12 deletions
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<T>`); 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);