Skip to content

mac: typing opens the completion list (no ⌃Space) - #215

Merged
jay3332 merged 1 commit into
mainfrom
agent/claude/mac-completion-auto
Sep 13, 2026
Merged

jay3332 merged 1 commit into
mainfrom
agent/claude/mac-completion-auto

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Owner feedback on v0.1.2: "getting better lsp features / autocomplete / intellisense is another thing (autocomplete should be automatic)".

What actually happened before this

CompletingTextView.requestCompletion had exactly four callers: AppKit's complete:, ⌃Space, Esc, and the re-scan that narrows an already open list. Nothing opened it from typing. Worse, typing actively suppressed it — every keystroke reached textChanged, which did scheduler.cancel() and closed any open session.

So the popup was 100% manual-invoke. The prefix.utf8.count >= 2 gates are not the cause: the one at matchRank only limits subsequence matching, and the one in suggestions only applies to prose words (context == .none) — every structured context already had a zero-length minimum. There was no "requires a backslash" rule and no too-slow debounce either. The single cause was that no code path ever called requestCompletion in response to a typed character.

EditorPreferences.completionPopup has documented "the completion list may open (typing, Esc, ⌃Space)" all along. Only the last two were implemented. This PR implements the first.

What opens it now

Completion.opensAutomatically, decided from the token at the caret alone:

  • command names after \ — including \ on its own, which lists the vocabulary
  • environment names in \begin{…} / \end{…}
  • \ref / \eqref / \autoref / \pageref — the document's real \labels plus the project index's
  • \cite and friends — real \bibitem keys and the project index's bibliography keys
  • \includegraphics / \input / \include — real project file paths
  • \usepackage — package names
  • \label{ — the derived unique key

(The suggestion engine already covered all of these; they were just unreachable without ⌃Space. Math symbols come from the same vocabulary, tagged mode: math.)

Prose words deliberately do not auto-open. wordSuggestions offers words counted from the document — worth asking for with ⌃Space, noise over every fourth letter of a sentence. Say the word if you'd rather have it and it's a one-line change.

Not fighting the user

  • typing through a non-match closes it (.noCandidates) — already worked, now tested
  • Esc dismisses for the token it was pressed on; typing more of that token stays quiet. Any other token, or a caret move, re-arms it. ⌃Space and Esc are never suppressed
  • a session with nothing selected now hands the key back to the editor instead of eating it, so Return and Tab can never be swallowed
  • deletion, caret moves, ⌘/⌃ shortcuts, IME composition and any programmatic replacement (document switch, paste) never open it — the trigger gates on a real keystroke, not on the text having changed

Cost

This runs on every keystroke, so the gate does not touch the document. Completion.caretToken reads the token from a bounded 1024-UTF-16-unit window; every token the file recognises is short, so the answer is identical and the cost is flat in file size. Measured on a 118 KB document:

per read
windowed gate 0.039 ms
whole-text token scan 2.147 ms

The document-wide scan that produces the candidates is unchanged — still off-main, still cancellable — and now sits behind a 50 ms coalescing timer, so a burst of typing costs one scan, not one per keystroke (asserted). Narrowing an already-open list stays immediate, as CompletionLatencyTests pins it. No new index, no new document scan: nothing here repeats the per-formula-scan pattern the engine just removed.

Tests

12 new in AutomaticCompletionTests.swift: the pure policy; the windowed token against the whole-text scan (including an emoji prefix, so the window never splits a surrogate pair); which key events arm it; every argument context opening while typing, against real labels / bib keys / project files; prose staying quiet; Esc suppression and re-arming; keys never stolen; one-scan-per-burst.

SnippetTests' ranking contract is untouched — no ranking changes in this PR.

tests skipped failures
control @ 6c738349 941 134 4
this branch 953 134 3

swift build clean. All 3 remaining failures are present at the base and unrelated: testBundledInventoryMatchesTheCompiler (bundled supported-latex.json drifted from the compiler's), and two PanelAccessibilityTests switch counts (6 vs 4) from preference toggles other lanes landed today. The control run showed a 4th (CommandTableTests.testPanelFocusOrderMatchesThePanelSources) that came from another agent's in-flight edit in the shared worktree, which is why the isolated run has one fewer.

Syntax highlighting is a separate PR.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

The owner's report was "autocomplete should be automatic". It was not:
`CompletingTextView.requestCompletion` had exactly four callers — AppKit's
`complete:`, ⌃Space, Esc, and the re-scan that narrows an *already open*
list — so a list nobody explicitly asked for never appeared. Typing did the
opposite: every keystroke reached `textChanged`, which cancelled the
scheduler and closed any open list. `EditorPreferences.completionPopup` has
documented "typing, Esc, ⌃Space" all along; only the last two existed.

Typing now opens it, through a gate that is deliberately narrow and cheap.

What opens it (`Completion.opensAutomatically`, decided from the token at
the caret alone): a control word — including the `\` on its own, which
lists the vocabulary — and an argument key whose command gives it meaning
(`\begin{`, `\end{`, `\ref{`/`\eqref{`/`\autoref{`/`\pageref{`, `\cite{`
and friends, `\label{`, `\usepackage{`, `\input{`/`\include{`/
`\includegraphics{`). A plain prose word does not: `wordSuggestions` offers
words counted from the document, which is worth asking for with ⌃Space and
is noise over every fourth letter of a sentence. ⌃Space still offers it.

What does not open it: deletion, caret moves, ⌘/⌃ shortcuts, IME
composition, and any programmatic replacement — a document switch or the
owner's paste is not a key event, so `typingKey` gates on a real keystroke
rather than on the text having changed.

Not fighting the user: typing through a non-match still closes the list
(`.noCandidates`); Esc dismisses for the token it was pressed on and typing
more of that token stays quiet, while any other token or a caret move
re-arms it; and a session with nothing selected now hands the key back to
the editor instead of eating it, so Return and Tab can never be swallowed.

Cost, which matters because this runs on every keystroke. The per-keystroke
gate reads the token from a bounded window (`Completion.caretToken`,
1024 UTF-16 units) instead of the document — every token this file
recognises is short, so the answer is the same and the cost does not grow
with the file. Measured in `AutomaticCompletionTests` on a 118 KB document:
0.039 ms/read windowed against 2.147 ms/read for the whole-text scan, 55×.
The document-wide scan that produces the candidates is unchanged and still
runs off-main, cancellable; it is now behind a 50 ms coalescing timer, so a
burst of typing costs one scan rather than one per keystroke. Narrowing an
already-open list stays immediate, as `CompletionLatencyTests` pins it.

No new index and no new document scan, so nothing here repeats the
per-formula-scan pattern the engine just removed.

Tests: 12 new in `AutomaticCompletionTests` — the pure policy, the windowed
token against the whole-text scan (including an emoji prefix, so the window
never splits a surrogate pair), which key events arm it, every argument
context opening while typing against real labels/keys/files, prose staying
quiet, Esc's suppression and re-arming, keys never being stolen, and the
one-scan-per-burst cost. Suite on this Mac: 953 tests, 134 skipped,
3 failures, all three present at the 6c73834 base and unrelated
(supported-latex.json drift, two preference-panel switch counts).

Implementation-Agent: Claude Opus 5 (mac-completion lane, linux-primary)
Commit-Executor: Claude Opus 5 via direct agent Git (Cursor usage limit)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
@jay3332
jay3332 merged commit b135225 into main Sep 13, 2026
19 of 20 checks passed
@jay3332

jay3332 commented Sep 13, 2026

Copy link
Copy Markdown
Member

Merged to main via integration/2026-09-13m (Commander).

d-q222 added a commit that referenced this pull request Sep 14, 2026
…ppet undo test (GH#256)

testSnippetsInsertThroughTheRealTextViewAsOneUndoStep types \se through
keyDown, which since #215 arms the automatic open on a 50 ms timer. It then
presses ⌃Space, waits for any session, and presses Return. The timer's open and
the ⌃Space open were two lifecycles racing, so Return could meet no session:
the reported lastCloseReason .textChanged, no snippet, undo name "Typing".

The test now fires the armed open deterministically
(flushAutomaticCompletion, as AutomaticCompletionTests do). It then presses
⌃Space and waits until a session exists AND every scan either lifecycle
scheduled has resolved (delivered + refusedStale + cancelled >= scheduled)
before Return.

Measured on mac-m5pro-dq222 under CPU load (8 busy processes):
- original test: 1 of 5 runs failed;
- this change: 5 of 5 passed (also 5 of 5 without load).

Part 1 of #256, the live-compiler count pins in
EditorDiagnosticsPartialOutputTests, was already fixed on main by 11ef11d's
generated fixture. With a flashtex-compiler freshly built from main
5baa9e6, all 6 tests pass; no change is needed there.

Implementation-Agent: daniel-vpclaude (Claude Code, Claude Pro plan)
Commit-Executor: daniel-vpclaude, direct git (Cursor-limit fallback)
Co-authored-by: d-q222 <[email protected]>

Claude-Session: https://claude.ai/code/session_012iWhnaQddU1UTMh6ZssGBJ
GoKubar pushed a commit that referenced this pull request Sep 14, 2026
…ppet undo test (GH#256) (#318)

testSnippetsInsertThroughTheRealTextViewAsOneUndoStep types \se through
keyDown, which since #215 arms the automatic open on a 50 ms timer. It then
presses ⌃Space, waits for any session, and presses Return. The timer's open and
the ⌃Space open were two lifecycles racing, so Return could meet no session:
the reported lastCloseReason .textChanged, no snippet, undo name "Typing".

The test now fires the armed open deterministically
(flushAutomaticCompletion, as AutomaticCompletionTests do). It then presses
⌃Space and waits until a session exists AND every scan either lifecycle
scheduled has resolved (delivered + refusedStale + cancelled >= scheduled)
before Return.

Measured on mac-m5pro-dq222 under CPU load (8 busy processes):
- original test: 1 of 5 runs failed;
- this change: 5 of 5 passed (also 5 of 5 without load).

Part 1 of #256, the live-compiler count pins in
EditorDiagnosticsPartialOutputTests, was already fixed on main by 11ef11d's
generated fixture. With a flashtex-compiler freshly built from main
5baa9e6, all 6 tests pass; no change is needed there.

Implementation-Agent: daniel-vpclaude (Claude Code, Claude Pro plan)
Commit-Executor: daniel-vpclaude, direct git (Cursor-limit fallback)
Co-authored-by: d-q222 <[email protected]>

Claude-Session: https://claude.ai/code/session_012iWhnaQddU1UTMh6ZssGBJ
@GoKubar
GoKubar deleted the agent/claude/mac-completion-auto branch September 16, 2026 04:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants