diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-10 03:35:02 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-10 04:08:29 -0300 |
| commit | a9529fa5712298e9005b77b471400529a2ebbc32 (patch) | |
| tree | 50633449f495e32f0a263277c260c7bef1a0db4d | |
| parent | c40b95b8f938e01b7e8846bae53f16b0c1cd5654 (diff) | |
| download | pardes-a9529fa5712298e9005b77b471400529a2ebbc32.tar.gz pardes-a9529fa5712298e9005b77b471400529a2ebbc32.zip | |
hxdiff: a case may name its file pane ("path", whose extension picks the grammar), and test/hxcases/indent.jsonl pins the new line's indent in a Zig, a Python, a Rust and a plain-text file against the reference helix with its grammars, typed into a real hx in a pty by hx_indent.py since the harness runs without any; zig build hxdiff runs it before the suite
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
| -rw-r--r-- | build.zig | 8 | ||||
| -rw-r--r-- | docs/helix-keys.md | 15 | ||||
| -rw-r--r-- | test/hxcases/hx_indent.py | 89 | ||||
| -rw-r--r-- | test/hxcases/indent-goldens.jsonl | 25 | ||||
| -rw-r--r-- | test/hxcases/indent.jsonl | 25 | ||||
| -rw-r--r-- | test/hxdiff.zig | 8 |
6 files changed, 167 insertions, 3 deletions
@@ -1346,6 +1346,14 @@ pub fn build(b: *std.Build) void { // runs each case in a file pane and a pty pane and compares the two. run_hxdiff.addPassthruArgs(); run_hxdiff.setCwd(b.path(".")); + // the new line's indent per file type, against the reference helix + // with its grammars (test/hxcases/hx_indent.py): before the suite, + // whose count stays the last line + const run_hxindent = b.addRunArtifact(hxdiff); + run_hxindent.has_side_effects = true; + run_hxindent.addArgs(&.{ "--strict", "test/hxcases/indent.jsonl", "test/hxcases/indent-goldens.jsonl" }); + run_hxindent.setCwd(b.path(".")); + run_hxdiff.step.dependOn(&run_hxindent.step); const hxdiff_step = b.step("hxdiff", "compare Helix results (-- --strict cases reference [waivers]; cases alone emits; --parity: a pty pane against a file pane)"); hxdiff_step.dependOn(&run_hxdiff.step); diff --git a/docs/helix-keys.md b/docs/helix-keys.md index f7a3093d..86c50722 100644 --- a/docs/helix-keys.md +++ b/docs/helix-keys.md @@ -117,7 +117,7 @@ language-backend queries, and the shell pipe. | `zm` | scroll the unwrapped view so the cursor's column is in its middle | helix `align_view_middle`; with soft wrap on there is no horizontal scroll, and nothing happens | out of corpus (the harness's text never scrolls sideways) | | `i` `a` | insert at selection start / after selection end | helix semantics: `i` before the selection, `a` selects and appends after it | helix-verified | | `I` `A` | insert at first non-ws / line end | matches `insert_at_line_start` / `insert_at_line_end` | helix-verified | -| `o` `O` | open line below / above, with the current line's indent as it is (acme's autoindent, tabs and all); `<n>o` opens n | `open_below`/`open_above`, except that helix's no-language fallback rounds the indent down to whole units: under its 4-space unit, two spaces open a line with none (waiver `o-partial-indent-drops`) | helix-verified (whole units) / pardes-specific (partial) | +| `o` `O` | open line below / above, with helix's indent from the syntax tree where the file's grammar has an indent query (src/indent.zig, as Enter), else the current line's indent as it is (acme's autoindent, tabs and all); `<n>o` opens n | `open_below`/`open_above`, except that helix's no-language fallback rounds the indent down to whole units: under its 4-space unit, two spaces open a line with none (waiver `o-partial-indent-drops`) | helix-verified (whole units) / pardes-specific (partial) | | `v` | select (extend) mode: motions extend from the fixed anchor; `v` again exits KEEPING the selection | mode "select" is reported only while this is on (helix keeps mode normal for x/%/mi selections) | helix-verified | | `x` / `<n>x` | select current line / extend one (n) line(s) down, char-range through the newline, cursor ON the `\n` | col-0 vim-ism removed (phase 5); matches `extend_line_below`, mode stays normal | helix-verified | | `d` | delete selection (implicit or explicit); bare cursor = the 1-wide selection | always yanks (`Alt-d` noyank in B); terminals: drops typed runs only | helix-verified | @@ -141,7 +141,7 @@ language-backend queries, and the shell pipe. | `n` / `N` | next / previous match of the text's places when a query pane fed them (a `/`, a list's places in this text: refs, diagnostics, a Grep's hits), round the ends without a message; else the last search register's regex in the current text, as before; counts repeat | only the primary selection is replaced; in select mode each match is added and becomes primary. Named registers work. `*` sets the pattern from selections with word boundaries (`Alt-*` without) and seeds the text's query pane with it, the keyboard staying. The former Look ring is `LookNext` / `LookPrev`, `SPC j n` / `SPC j p`. PDFs retain their location-result navigation | helix-verified | | insert: printable text | file: real edit; terminal: typed run splice | | helix-verified (file) | -| insert: `Enter` | newline; keeps the current line's indent as it is and adds one 4-space logical tab (a tab where the indent is tabs) when the text before the cursor ends in `(`, `[`, `{`, or `)` (including `})`) | plain lines match `insert_newline` at whole indent units (helix drops a partial one, as for `o`); delimiter heuristic is pardes-specific | helix-verified (plain) / pardes-specific (partial indent, delimiter) | +| insert: `Enter` | newline; where the file's grammar has an indent query (vendor/queries/*/indents.scm), helix's `indent_for_newline` over the syntax tree (src/indent.zig, the reference's containment engine, `hybrid` heuristic); else keeps the current line's indent as it is and adds one 4-space logical tab (a tab where the indent is tabs) when the text before the cursor ends in `(`, `[`, `{`, or `)` (including `})`). Between a pair (helix's default auto-pairs) the closer gets a line of its own at that indent and the cursor one a level in (`insert_newline`'s `on_auto_pair`) | plain lines match `insert_newline` at whole indent units (helix drops a partial one, as for `o`); delimiter heuristic is pardes-specific; with a grammar, `test/hxcases/indent.jsonl` against the reference `hx` and its grammars (`hx_indent.py`) | helix-verified (plain, grammar) / pardes-specific (partial indent, delimiter) | | insert: `Backspace` (+ `Shift-Backspace`) | delete prev char, joins lines at col 0; in a line's leading blanks, back to the previous 4-column indent stop (a whole unit when on one; a tab still goes alone) | matches `delete_char_backward` and its dedent; `Ctrl-h` alias in B | helix-verified | | insert: `Up` `Down` `Left` `Right` | move cursor | matches helix's "not recommended" insert arrows | helix-verified | | `gd` `gD` `gy` `gi` `gr` | LSP definition / declaration / type-definition / implementation / references. One answer jumps straight there; several (definition, implementation, references) fill the text's query pane, line 1 `Def`/`Impl`/`Refs`, their places in the text tinted and stepped by `n`/`N`; the others fill `+Search`, where `LookNext` / `LookPrev` walk and Enter opens | Ctrl+left-click is the mouse spelling of `gd`; language support depends on the configured backend | out of corpus | @@ -443,6 +443,17 @@ Files (all in `test/hxcases/`): harness and absent in pardes) to close its `VALUES (`, and `invert_dictionary_2` needs 25.07.1's `<count>Alt-(` (rotate within groups of count) where the reference helix rotates by count. +- `indent.jsonl` + `indent-goldens.jsonl` — the new line's indent in a Zig, + a Python, a Rust and a plain-text file (each case's `path` names its file + pane): Enter after an opener, inside a block, before a closer and between + a pair, `o` and `O`. Their goldens are not the harness's, which runs + without grammars: `test/hxcases/hx_indent.py` types each case into a real + `hx` in a pty, the reference build (`cargo build --release --bin hx` at + the harness commit) with `HELIX_RUNTIME` the checkout's `runtime/`. + `zig build hxdiff` runs them first, their count a line before the suite's. + hx 25.07.1 agrees but on `py-ret-after-last-line`: its engine (before + upstream 3013c107d) keeps a function's level after its last line, the + reference's ends it there. - `smoke.jsonl` — 20 cases referenced by nothing in the tree: no build step, no script. Either wire it up or delete it. diff --git a/test/hxcases/hx_indent.py b/test/hxcases/hx_indent.py new file mode 100644 index 00000000..c85c9417 --- /dev/null +++ b/test/hxcases/hx_indent.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python3 +"""The goldens of indent.jsonl from helix itself, in a pty: $HX (else `hx` +on PATH) with its grammars and queries ($HELIX_RUNTIME) and its defaults +(auto-pairs on), LSP and auto-format off. They were made by the reference +helix (docs/helix-keys.md), 278b24389's `hx` built from the genizah checkout +with HELIX_RUNTIME its runtime/. Each case's file is named by its "path" (its +extension picks the language) and holds its "text"; the keys are typed, then +a marker where the cursor is, then `:wq!`. The marker's place is the cursor, +and the anchor: every case ends in insert mode with one cursor no wider than +helix's block (no `a` or `c` over a selection, whose anchor stays behind). + + HX=... HELIX_RUNTIME=... python3 -B test/hxcases/hx_indent.py \ + test/hxcases/indent.jsonl > test/hxcases/indent-goldens.jsonl +""" +import json, os, pty, select, struct, sys, tempfile, time, fcntl, termios + +MARK = "§" +KEYS = {"ret": "\r", "esc": "\x1b", "tab": "\t", "backspace": "\x7f", "lt": "<", "gt": ">"} + + +def keys(spec): + out, i = [], 0 + while i < len(spec): + if spec[i] == "<": + j = spec.index(">", i) + out.append(KEYS[spec[i + 1 : j]]) + i = j + 1 + else: + out.append(spec[i]) + i += 1 + return out + + +def drain(fd, secs): + end = time.time() + secs + while time.time() < end: + r, _, _ = select.select([fd], [], [], 0.02) + if r: + try: + os.read(fd, 65536) + except OSError: + return + + +def run(case, home): + path = os.path.join(home, os.path.basename(case["path"])) + with open(path, "w") as f: + f.write(case["text"]) + cfg = os.path.join(home, "config.toml") + with open(cfg, "w") as f: + f.write("[editor]\nauto-format = false\n[editor.lsp]\nenable = false\n") + pid, fd = pty.fork() + if pid == 0: + for v in ("CONFIG", "CACHE", "DATA", "STATE"): + os.environ["XDG_%s_HOME" % v] = home + os.environ["TERM"] = "xterm-256color" + hx = os.environ.get("HX", "hx") + os.execvp(hx, [hx, "-c", cfg, path]) + fcntl.ioctl(fd, termios.TIOCSWINSZ, struct.pack("HHHH", 24, 80, 0, 0)) + drain(fd, 1.0) + for k in keys(case["keys"]) + [MARK, "\x1b"]: + os.write(fd, k.encode()) + drain(fd, 0.25 if k == "\x1b" else 0.05) + for k in ":wq!\r": + os.write(fd, k.encode()) + drain(fd, 0.05) + for _ in range(100): + done, _ = os.waitpid(pid, os.WNOHANG) + if done: + break + drain(fd, 0.05) + else: + os.kill(pid, 9) + os.waitpid(pid, 0) + sys.exit("hx did not quit on case " + case["name"]) + os.close(fd) + with open(path) as f: + text = f.read() + at = text.index(MARK) + row = text.count("\n", 0, at) + col = len(text[text.rfind("\n", 0, at) + 1 : at].encode()) + cursor = {"row": row, "col": col} + return {"name": case["name"], "text": text.replace(MARK, "", 1), "mode": "insert", "cursor": cursor, "anchor": cursor} + + +with tempfile.TemporaryDirectory() as home: + for line in open(sys.argv[1]): + if line.strip(): + print(json.dumps(run(json.loads(line), home), separators=(",", ":"), ensure_ascii=False)) diff --git a/test/hxcases/indent-goldens.jsonl b/test/hxcases/indent-goldens.jsonl new file mode 100644 index 00000000..8e1b0f21 --- /dev/null +++ b/test/hxcases/indent-goldens.jsonl @@ -0,0 +1,25 @@ +{"name":"zig-ret-after-opener","text":"fn f() void {\n \n}\n","mode":"insert","cursor":{"row":1,"col":4},"anchor":{"row":1,"col":4}} +{"name":"zig-ret-inside-block","text":"fn f() void {\n a();\n \n}\n","mode":"insert","cursor":{"row":2,"col":4},"anchor":{"row":2,"col":4}} +{"name":"zig-ret-nested-block","text":"fn f() void {\n if (x) {\n \n a();\n }\n}\n","mode":"insert","cursor":{"row":2,"col":8},"anchor":{"row":2,"col":8}} +{"name":"zig-ret-before-closer","text":"fn f() void {\n a();\n}\n","mode":"insert","cursor":{"row":2,"col":0},"anchor":{"row":2,"col":0}} +{"name":"zig-ret-between-braces","text":"fn f() void {\n \n}\n","mode":"insert","cursor":{"row":1,"col":4},"anchor":{"row":1,"col":4}} +{"name":"zig-o","text":"fn f() void {\n a();\n \n}\n","mode":"insert","cursor":{"row":2,"col":4},"anchor":{"row":2,"col":4}} +{"name":"zig-O-after-opener","text":"fn f() void {\n \n a();\n}\n","mode":"insert","cursor":{"row":1,"col":4},"anchor":{"row":1,"col":4}} +{"name":"zig-O-before-closer","text":"fn f() void {\n a();\n \n}\n","mode":"insert","cursor":{"row":2,"col":4},"anchor":{"row":2,"col":4}} +{"name":"zig-typed-closer-stays","text":"fn f() void {\n a();\n }\n}\n","mode":"insert","cursor":{"row":2,"col":5},"anchor":{"row":2,"col":5}} +{"name":"py-ret-after-colon","text":"def f():\n \n pass\n","mode":"insert","cursor":{"row":1,"col":4},"anchor":{"row":1,"col":4}} +{"name":"py-ret-inside-block","text":"def f():\n x = 1\n \n y = 2\n","mode":"insert","cursor":{"row":2,"col":4},"anchor":{"row":2,"col":4}} +{"name":"py-ret-after-last-line","text":"def f():\n x = 1\n\n","mode":"insert","cursor":{"row":2,"col":0},"anchor":{"row":2,"col":0}} +{"name":"py-ret-after-return","text":"def f():\n return 1\n\n","mode":"insert","cursor":{"row":2,"col":0},"anchor":{"row":2,"col":0}} +{"name":"py-o","text":"if x:\n \n y()\n","mode":"insert","cursor":{"row":1,"col":4},"anchor":{"row":1,"col":4}} +{"name":"py-O","text":"if x:\n \n y()\n","mode":"insert","cursor":{"row":1,"col":4},"anchor":{"row":1,"col":4}} +{"name":"py-ret-between-brackets","text":"x = [\n \n]\n","mode":"insert","cursor":{"row":1,"col":4},"anchor":{"row":1,"col":4}} +{"name":"rs-ret-after-opener","text":"fn f() {\n \n}\n","mode":"insert","cursor":{"row":1,"col":4},"anchor":{"row":1,"col":4}} +{"name":"rs-ret-inside-block","text":"fn f() {\n a();\n \n}\n","mode":"insert","cursor":{"row":2,"col":4},"anchor":{"row":2,"col":4}} +{"name":"rs-ret-before-closer","text":"fn f() {\n a();\n}\n","mode":"insert","cursor":{"row":2,"col":0},"anchor":{"row":2,"col":0}} +{"name":"rs-ret-between-parens","text":"fn g() {\n f(\n \n );\n}\n","mode":"insert","cursor":{"row":2,"col":8},"anchor":{"row":2,"col":8}} +{"name":"rs-o","text":"fn f() {\n a();\n \n}\n","mode":"insert","cursor":{"row":2,"col":4},"anchor":{"row":2,"col":4}} +{"name":"rs-O","text":"fn f() {\n a();\n \n}\n","mode":"insert","cursor":{"row":2,"col":4},"anchor":{"row":2,"col":4}} +{"name":"txt-ret-copies-indent","text":"a\n b\n \n","mode":"insert","cursor":{"row":2,"col":4},"anchor":{"row":2,"col":4}} +{"name":"txt-ret-between-braces","text":"a\n x {\n \n }\n","mode":"insert","cursor":{"row":2,"col":8},"anchor":{"row":2,"col":8}} +{"name":"txt-o","text":"a\n b\n \n","mode":"insert","cursor":{"row":2,"col":4},"anchor":{"row":2,"col":4}} diff --git a/test/hxcases/indent.jsonl b/test/hxcases/indent.jsonl new file mode 100644 index 00000000..8330badf --- /dev/null +++ b/test/hxcases/indent.jsonl @@ -0,0 +1,25 @@ +{"name": "zig-ret-after-opener", "path": "/x.zig", "text": "fn f() void {\n}\n", "keys": "A<ret>"} +{"name": "zig-ret-inside-block", "path": "/x.zig", "text": "fn f() void {\n a();\n}\n", "keys": "jA<ret>"} +{"name": "zig-ret-nested-block", "path": "/x.zig", "text": "fn f() void {\n if (x) {\n a();\n }\n}\n", "keys": "jA<ret>"} +{"name": "zig-ret-before-closer", "path": "/x.zig", "text": "fn f() void {\n a();}\n", "keys": "jgli<ret>"} +{"name": "zig-ret-between-braces", "path": "/x.zig", "text": "fn f() void {}\n", "keys": "gli<ret>"} +{"name": "zig-o", "path": "/x.zig", "text": "fn f() void {\n a();\n}\n", "keys": "jo"} +{"name": "zig-O-after-opener", "path": "/x.zig", "text": "fn f() void {\n a();\n}\n", "keys": "jO"} +{"name": "zig-O-before-closer", "path": "/x.zig", "text": "fn f() void {\n a();\n}\n", "keys": "jjO"} +{"name": "zig-typed-closer-stays", "path": "/x.zig", "text": "fn f() void {\n a();\n}\n", "keys": "jo}"} +{"name": "py-ret-after-colon", "path": "/x.py", "text": "def f():\n pass\n", "keys": "A<ret>"} +{"name": "py-ret-inside-block", "path": "/x.py", "text": "def f():\n x = 1\n y = 2\n", "keys": "jA<ret>"} +{"name": "py-ret-after-last-line", "path": "/x.py", "text": "def f():\n x = 1\n", "keys": "jA<ret>"} +{"name": "py-ret-after-return", "path": "/x.py", "text": "def f():\n return 1\n", "keys": "jA<ret>"} +{"name": "py-o", "path": "/x.py", "text": "if x:\n y()\n", "keys": "o"} +{"name": "py-O", "path": "/x.py", "text": "if x:\n y()\n", "keys": "jO"} +{"name": "py-ret-between-brackets", "path": "/x.py", "text": "x = []\n", "keys": "gli<ret>"} +{"name": "rs-ret-after-opener", "path": "/x.rs", "text": "fn f() {\n}\n", "keys": "A<ret>"} +{"name": "rs-ret-inside-block", "path": "/x.rs", "text": "fn f() {\n a();\n}\n", "keys": "jA<ret>"} +{"name": "rs-ret-before-closer", "path": "/x.rs", "text": "fn f() {\n a();}\n", "keys": "jgli<ret>"} +{"name": "rs-ret-between-parens", "path": "/x.rs", "text": "fn g() {\n f();\n}\n", "keys": "jglhi<ret>"} +{"name": "rs-o", "path": "/x.rs", "text": "fn f() {\n a();\n}\n", "keys": "jo"} +{"name": "rs-O", "path": "/x.rs", "text": "fn f() {\n a();\n}\n", "keys": "jjO"} +{"name": "txt-ret-copies-indent", "path": "/x.txt", "text": "a\n b\n", "keys": "jA<ret>"} +{"name": "txt-ret-between-braces", "path": "/x.txt", "text": "a\n x {}\n", "keys": "jgli<ret>"} +{"name": "txt-o", "path": "/x.txt", "text": "a\n b\n", "keys": "jo"} diff --git a/test/hxdiff.zig b/test/hxdiff.zig index 5c1bc04e..010cc674 100644 --- a/test/hxdiff.zig +++ b/test/hxdiff.zig @@ -201,6 +201,8 @@ pub fn main(init: std.process.Init) !void { const Case = struct { name: []const u8, pane: []const u8 = "file", + /// the file pane's name, whose extension picks its grammar + path: ?[]const u8 = null, text: []const u8, keys: []const u8, }; @@ -303,7 +305,11 @@ fn runCase(arena: std.mem.Allocator, case: Case, pane_kind: []const u8) !Result pump(core); if (std.mem.eql(u8, pane_kind, "file")) { - _ = try core.setTestFile(case.text); + const pane = try core.setTestFile(case.text); + if (case.path) |path| { + core.gpa.free(pane.file.?.path); + pane.file.?.path = try core.gpa.dupe(u8, path); + } } else if (std.mem.eql(u8, pane_kind, "tty")) { // the harness is the pty here: cook \n to \r\n the way ONLCR would const cooked_len = std.math.add(usize, case.text.len, std.mem.count(u8, case.text, "\n")) catch return error.OutOfMemory; |
