Repository navigation
mac: typing opens the completion list (no ⌃Space) - #215
Merged
Merged
Conversation
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
This was referenced Sep 13, 2026
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.requestCompletionhad exactly four callers: AppKit'scomplete:, ⌃Space, Esc, and the re-scan that narrows an already open list. Nothing opened it from typing. Worse, typing actively suppressed it — every keystroke reachedtextChanged, which didscheduler.cancel()and closed any open session.So the popup was 100% manual-invoke. The
prefix.utf8.count >= 2gates are not the cause: the one atmatchRankonly limits subsequence matching, and the one insuggestionsonly 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 calledrequestCompletionin response to a typed character.EditorPreferences.completionPopuphas 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:\— including\on its own, which lists the vocabulary\begin{…}/\end{…}\ref/\eqref/\autoref/\pageref— the document's real\labels plus the project index's\citeand friends — real\bibitemkeys 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.
wordSuggestionsoffers 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
.noCandidates) — already worked, now testedCost
This runs on every keystroke, so the gate does not touch the document.
Completion.caretTokenreads 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: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
CompletionLatencyTestspins 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.6c738349swift buildclean. All 3 remaining failures are present at the base and unrelated:testBundledInventoryMatchesTheCompiler(bundledsupported-latex.jsondrifted from the compiler's), and twoPanelAccessibilityTestsswitch 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