Skip to content

editor: T-114, follow up Khakha's answers on PR #42 - #45

Merged
shubhook merged 9 commits into
mainfrom
t3/t114-t109-followups
Nov 28, 2026
Merged

shubhook merged 9 commits into
mainfrom
t3/t114-t109-followups

Conversation

@shubhook

@shubhook shubhook commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

Task: T-114, tasks/114-t109-followups.md

PRD: ED-5, NF-1

Khakha's answers and grants

Stage 0, Khakha's answers to PR #42's open questions, as the orchestrator relayed them:

Answers to PR #42's open questions, from Khakha:

  1. Question 6 (no-pair bracket scan): cap the scan at 1 MiB in each direction from the cursor, and treat a capped scan as no pair. List it in vim.rs's 'Measured against Vim' as a difference.
  2. Repeated visual bracket objects (va(a(, vi(i(): grow to the next pair out, as Vim does.
  3. Escaped quotes: a quote is escaped only when an odd number of backslashes come right before it, as Vim does.
  4. The 1 GiB put limit: keep it, refused silently, for now. Feedback for a refused put is a later helm-ui task.
  5. Update the stale 'How this compiles without the two pending grants' section of tasks/109-vim-objects.md to describe what merged.

If any of 1 to 3 would change an assertion in an existing test, stop and tell me which one.

Khakha's answers to this PR's questions, written grants:

Khakha's answers. Quote them in the PRs as written grants.

  1. Stage 0: all five answers stand as written. PR editor: T-114, follow up Khakha's answers on PR #42 #45 needs no change for them.
  2. Forward search for bracket objects: keep it listed as a difference in PR editor: T-114, follow up Khakha's answers on PR #42 #45. Cut a new follow-up task to follow Vim 9.1's forward search (the next pair after the cursor, including on later lines) within the 1 MiB cap. Do not change PR editor: T-114, follow up Khakha's answers on PR #42 #45's behaviour for this.
  3. Granted: change the module comment in crates/helm-bench/benches/vim_objects.rs to the wording in PR editor: T-114, follow up Khakha's answers on PR #42 #45's description. Put it in its own commit, quote this grant, and change nothing else in that file.

Grant 1 needs no change. Under grant 2, no behaviour changes here, and the follow-up task isn't in this PR. Grant 3 is commit 7.

What changed

Nine commits on main at 7638344. Commits 5 and 6 answer council round 1. Commit 7 is grant 3, and commit 8 carries council round 2's nits. Commit 9 records grant 2 in the task file. None of the three changes behaviour. The task file and the work land in one PR, as T-111 did.

1. 88f7b52 adds tasks/114-t109-followups.md. It quotes Khakha's answers to PR #42's open questions as the orchestrator relayed them, and records the Vim 9.1 measurements below.

2. 69347ef carries out answers 1 to 3 in src/motion/vim/object.rs, Editor::vim_select_object and the vim module docs, with the new tests in tests/vim_t114.rs.

  • Answer 1, the cap. A bracket object reads at most 1 MiB (1 << 20 bytes) each way from where its scan starts: the cursor, or the first char of a longer visual selection. A pair counts only if both brackets are in [start - 1 MiB, start + 1 MiB). A scan that reaches either end without its bracket finds no pair. Counts and visual growth steps share one window. The backward reader gets a crate-private constructor, Backward::floored, that stops at a floor like a budgeted reader but keeps only its latest window, as Backward::new does. The forward reader uses the existing Forward::bounded. vim.rs lists the cap under "Measured against Vim".

  • Answer 2, repeated visual bracket objects. From a selection longer than one char, a bracket object now follows Vim 9.1's measured rule:

    • The scan starts before the selection's first char, so a bracket there isn't the pair's. The pair is the nth out from there.
    • a selects that pair.
    • i selects its inside, and moves out one pair while that inside lies within the selection and is more than one char.
    • The new selection runs forward.

    So va(a( and vi(i( grow to the next pair out. A one-char selection still starts a fresh object, and word, quote and paragraph objects are unchanged.

  • Answer 3, escaped quotes. escaped = c == '\\' && !escaped, so a backslash also escapes a backslash, and a quote is escaped only after an odd number of them.

The bracket code is split into find_pair (the scan) and inside (the i rules), which pair and the new grow_pair share. The i rules themselves are unchanged.

3. 4e04a27 fixes the two comments from round 3 of PR #42's council. EditorId's docs now say the editor owns the only lasting strong reference, and that CommandRegistry::run_in holds a clone while a command runs. The linewise p comment now says split_off copies the 1- or 2-byte line break into a small string while the rest stays in the text's allocation. The third note, the missing CRLF test for normal linewise p below a last line with no line break, is linewise_p_below_a_last_line_with_no_crlf_puts_one in commit 2.

4. b34716f carries out answer 5. In tasks/109-vim-objects.md, "How this compiles without the two pending grants" becomes "How the two grants landed". It describes what merged: CommandArgs::register, the two ..CommandArgs::default() literals, and 107 ids, 143 commands, eight modes and 506 bindings (115 + 391).

Answer 4 (keep the 1 GiB put limit, refused silently) needs no change.

5. 31c2dce checks both brackets against the 1 MiB window (council round 1, finding 1). A reader reads at least 4 bytes per window, and it ends each window on a char boundary. So a scan could read up to 3 bytes past the window and count a bracket there. Two cases triggered it: a rope chunk boundary 1 to 3 bytes inside the window, and a multi-byte char across the window's end. find_pair now returns a pair only if o >= floor && c < ceiling. A pair further out is also outside the window, so the check never drops a pair inside it. The shared readers, which Up and Down also use, are unchanged. The commit also rewraps two long doc lines (finding 2) and adds six tests to vim_t114.rs. Four of them fail at b34716f:

  • a ( one byte before the window, with chunk boundaries swept by k leading xs (fails at k = 980);
  • a ) at the window's end, swept the same way (fails at k = 368);
  • va(a( growing to an outer pair outside the window (fails at k = 980);
  • é or 中 across the window's end, with ) right after it (fails for é).

Two pass at b34716f and guard against regressions:

  • é or 中 across the window's start. The old code didn't count a ( there, so I couldn't reproduce that half of Gemini's report.
  • A backslash ending the line before a quote (finding 3).

6. 89c5bd1 records the fix and the six tests in the task file.

7. 012a0d4 changes the module comment of crates/helm-bench/benches/vim_objects.rs, under grant 3. It touches only that file, quotes the grant in its body, and changes one line. The comment now says di_paren_no_pair_10mb's "bracket object with no enclosing pair scans 1 MiB of the text before the cursor, the cap T-114 set." Nothing else in the file changed.

8. e34271a carries council round 2's nits. PAIR_SCAN is private, since only object.rs uses it. A comment in vim_t114.rs says the k ranges (940..1030 and 330..420) match where ropey puts chunk boundaries today. If helm-text's chunking changes, those three tests still pass but may stop reaching a boundary. The é and 中 tests don't depend on chunks.

9. 1d11d5e records grant 2 in the task file's "Out of scope".

No new dependency. No unsafe. No threading change. No public signature changes. Nothing outside crates/helm-editor/src/**, the new test file, the two task files and the granted comment line in benches/vim_objects.rs changed. No existing test, benchmark code or budget changed. None of answers 1 to 3 changes an existing test's assertion.

Protected paths

This PR changes tasks/114-t109-followups.md (new) and tasks/109-vim-objects.md, both under tasks/**. It also changes one comment line in crates/helm-bench/benches/vim_objects.rs, an existing bench file, under grant 3. The protected-paths check fails until Khakha adds the approved-protected label.

Left as they are

The module docs of crates/helm-bench/benches/vim_objects.rs used to say di_paren_no_pair_10mb "scans the text before the cursor to its start". I proposed "a bracket object with no enclosing pair scans 1 MiB of the text before the cursor, the cap T-114 set." Khakha granted it (grant 3), and it is commit 7.

tasks/109-vim-objects.md has two other sentences written before the grants: the "Choices" bullet ending "That leaves open question 2 open", and the doc comment at the top of tests/vim_harness/mod.rs. Answer 5 covered only the one section, so I left both.

Measured against Vim 9.1

vim -u NONE -N -i NONE -n, binary, noeol. Keys were fed with feedkeys(..., "xt"), and a <Cmd> mapping at the end recorded the mode and both visual ends. I checked that a failing object doesn't flush that mapping. The full tables are in the task file.

Answer 2. Each row ends in d. Vim 9.1 and this PR agree on every row.

Text Keys Vim 9.1 = this PR main
f(a(b|c)d)e va(a(d f|e f(a|d)e
f(a(b|c)d)e vi(i(d f(|)e f(a(|)d)e
f(a(b|c)d)e va(i(d f(|)e f(a|d)e
((((|bc)))) vi(i(i(d ((|)) ((((|))))
f(a(|b)c(d)e) v4la(d f(a|c(d)e) f(a(|e)
f(a(b|)c) vli(d f(a(|)c) f(|)

I also compared two random runs of 3,000 cases each: v, up to three of h/l/o, one to three of i(/a(/2i(/2a(, then d, on one line of (, ), a, b and spaces.

  • Where ten pairs enclose the cursor, 0 of 3,000 differ.
  • On random lines, 286 differ. Every one has a step where no pair encloses the selection's start, and there Vim 9.1 searches forward (see the question below).
  • A Python model of the new rule reproduces Helm's result in all 6,000 cases.

Answer 3. Each row is di", with the text as a Rust string.

Text Vim 9.1 = this PR main
"\"|a\\\\\"b\"" (2 backslashes) "\"|\"b\"" "\"|\""
"x\\\\\"|a\"b\"" "x\\\\\"|\"b\"" "x\\\\\"a\"|\""
"\"a\\\\\" |x \"c\"" "\"a\\\\\"|\"c\"" "\"|\"c\""
"\"|a\\\\\\\"b\"" (3) "\"|\"" "\"|\""

Differences kept, each listed in vim.rs:

  • The 1 MiB cap (answer 1).
  • With no unescaped quote before the cursor, Vim takes the line's first quote as the opening one even if it is escaped. di" from a in x\"a"b" leaves x\""b" in Vim and x\"a"" here.
  • With no pair around the cursor, Vim 9.1 looks for the next pair after it, even on a later line, and Helm finds nothing. In a visual mode Helm keeps the selection, where Vim's forward search can select a pair inside it: va(a(a( in f(a(bc)d)e leaves (bc) selected in Vim. Khakha has asked for a follow-up task to follow Vim's forward search within the 1 MiB cap (grant 2). This PR keeps the difference.
  • A grown inner block of lines stops before the closing line's line break, as every visual end has since T-108.

Tests

tests/vim_t114.rs has 19 tests. Of the first 13, 10 fail on main at 7638344. Of the six from round 1, 4 fail at b34716f. All 19 pass here. The three that pass on main:

  • the CRLF p test, a missing test, not a bug;
  • the capped visual growth, since main never grew;
  • the escaped quote that never opens a pair, since main counted a single backslash too.

Benchmarks

CI run 46143827954 on b34716f against base 7638344, on the same runner.

vim_objects/di_paren_no_pair_10mb puts one cursor about 5 MiB into the text. With the cap, its backward scan reads 1 MiB instead of about 5 MiB. Criterion means of the three rounds, from the bench job's artifact (criterion-pr-45-shard-1):

Round 1 Round 2 Round 3 Average of the means
Base 7638344 6.217 ms 6.141 ms 6.070 ms 6.143 ms
Head b34716f 752.90 µs 755.74 µs 754.13 µs 754.26 µs

bench-compare, fastest of three medians: 6.062 ms to 752.52 µs, −87.59%. The head is below NF-1's 5 ms keypress budget, which base passed on several of PR #42's runs.

No benchmark is over the 5% gate. bench-compare reported "No benchmark regressed past its budget." The largest increase, as fastest of three medians, is cursor/down_up_1000_cursors_10mb at +3.38%. The next is cursor/word_right_1000_cursors_10mb at +2.12%. Neither path reaches the changed code. The other vim_objects/ benchmarks moved between −0.61% and +0.98%. Since nothing passed the gate, I ran no controlled comparison.

Local (macOS aarch64), labelled local: di_paren_no_pair_10mb had a criterion mean of 850.68 µs at b34716f and 841.50 µs at 89c5bd1.

The cap applies per cursor. With N cursors and no pair, one keypress can still read N × 2 MiB (council round 1, finding 4). That is outside this task.

Round 1 fix, CI run 46148812050 on 89c5bd1

The table above is from b34716f. On 89c5bd1, against the same base 7638344 on that run's runner, vim_objects/di_paren_no_pair_10mb gave these criterion means, from the bench job's artifact:

Round 1 Round 2 Round 3 Average of the means
Base 7638344 7.195 ms 7.858 ms 7.656 ms 7.569 ms
Head 89c5bd1 1.132 ms 1.139 ms 1.138 ms 1.136 ms

bench-compare, fastest of three medians: 7.183 ms to 1.128 ms, −84.30%. This runner was slower than b34716f's: base's means are about 23% higher here. On that slower runner, head is still about 6.7 times faster than base.

No benchmark is over the 5% gate. bench-compare reported every row as ok. The largest increase, as fastest of three medians, is vim_objects/dap_undo_1000_cursors_10mb at +4.07%, which was +0.42% on b34716f. The next is vim_objects/yy_p_undo_1000_cursors_10mb at +3.02%. Neither path reaches find_pair. Since nothing passed the gate, I ran no controlled comparison.

Council review

Each cell is overall score, performance score and verdict.

Round Head Claude Opus 5.5 GPT-6.1 Sol Gemini 4 Argon
1 b34716f 7/10, 9/10, not satisfied 7/10, 8/10, not satisfied 8.5/10, 10/10, not satisfied
2 89c5bd1 9/10, 9/10, satisfied 9/10, 9/10, satisfied 10/10, 10/10, satisfied

Round 1

  1. Fixed in 31c2dce. The 1 MiB window let in a bracket up to 3 bytes outside it. All three reviewers raised it, and two confirmed it with throwaway tests. find_pair now checks both offsets against the window, and the shared readers are unchanged. Four of the six new tests fail at b34716f: a chunk boundary on either side, visual growth past the window, and é across the window's end. Gemini's other half, a multi-byte char across the window's start, didn't reproduce. Its test stays as a guard.
  2. Fixed in 31c2dce. Two doc lines were longer than the text around them. Rewrapped.
  3. Added in 31c2dce. No test for a backslash ending the line before a quote. The test passes before and after, as the reviewer expected.
  4. Noted, out of scope. The cap is per cursor, so N cursors with no pair can read N × 2 MiB in one keypress. It is recorded under "Benchmarks".

Round 2

  1. Fixed. The description called run 46148812050 on 89c5bd1 pending. "Benchmarks" and "Commands run" now give its finished result: criterion means of 7.569 ms for base and 1.136 ms for head, and bench-compare's fastest of three medians, 7.183 ms against 1.128 ms, −84.30%.
  2. Rejected. Keep the PR as a draft until the label lands. The brief's rule 10 says to mark a PR ready once CI is green apart from the protected-paths check waiting on the label. The PR follows that rule.
  3. Fixed in e34271a. The chunk-boundary tests depend on ropey's chunking. A comment in vim_t114.rs now says that the k ranges match where ropey puts chunk boundaries today, and that the é and 中 tests don't depend on chunks.
  4. Fixed in e34271a. PAIR_SCAN was pub(crate) with no user outside object.rs. It is private now.
  5. Carried over from round 1. The per-cursor cap. Already recorded as out of scope.

The commits after 89c5bd1 change no behaviour. 012a0d4 is Khakha's grant 3 comment, e34271a carries the round 2 nits, and 1d11d5e records grant 2 in the task file.

Commands run

Local, macOS (aarch64), at e34271a, at the default job count. Commit 9 changes only the task file. Each command's output went to its own log, and each exit code is cargo's own.

$ cargo build --workspace                                => exit 0
$ cargo test --workspace                                 => exit 0 (584 passed, 0 failed, 0 ignored)
$ cargo fmt --all --check                                => exit 0
$ cargo clippy --workspace --all-targets -- -D warnings  => exit 0
$ cargo bench -p helm-bench                              => exit 0

CI on 89c5bd1 (runs 46148812050 and 46148809007): 13 checks passed: test (ubuntu-latest), test (macos-latest), cargo-deny, bench-plan, the eight bench shards and the bench gate. bench-record is skipped on PRs by design. protected-paths fails until Khakha adds the approved-protected label.

Questions for Khakha

None open. Khakha answered the forward-search question (grant 2) and the bench comment (grant 3).

Outside sources

None. Behaviour came from running Vim 9.1 myself, as rule 6 allows. I didn't read Vim's source or :help pages, or any other editor's code.

Agent and model

Claude Code, Claude Opus 5.5 (claude-opus-5-5), for the whole thread.

…ackslashes

A bracket object reads at most 1 MiB each way from where its scan
starts and finds no pair past that. From a visual selection longer
than one char, a bracket object follows Vim 9.1: the pair is the nth
out from before the selection's first char, and i moves out while its
inside lies within the selection, so va(a( and vi(i( grow to the next
pair out. A quote is escaped only after an odd number of backslashes.

Refs: T-114, ED-5, NF-1
@shubhook
shubhook marked this pull request as ready for review November 28, 2026 12:40
The readers read at least 4 bytes per window and end each window on a
char boundary, so a scan could read up to 3 bytes past the window and
count a bracket there. find_pair now checks both offsets before it
returns a pair. Also rewrap two long doc lines and add tests for the
window's edges at chunk boundaries and inside multi-byte chars.

Refs: T-114, ED-5, NF-1
Only the module comment changes, as granted:

> 3. Granted: change the module comment in crates/helm-bench/benches/vim_objects.rs to the wording in PR #45's description. Put it in its own commit, quote this grant, and change nothing else in that file.

Refs: T-114, ED-5, NF-1
Council round 2 nits. No behaviour changes.

Refs: T-114
@shubhook shubhook added the approved-protected Khakha approves a change to a protected path. Agents never add or remove it. label Nov 28, 2026
@shubhook
shubhook merged commit 3566348 into main Nov 28, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved-protected Khakha approves a change to a protected path. Agents never add or remove it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant