Repository navigation
mac: rank math commands first when the caret is in math mode - #245
Merged
Merged
Conversation
`Completion.Vocabulary` is ordered text entries first, then math ones, and the command list offered that order everywhere. Inside `$…$` that is backwards: typing `\se` in a formula wants `\setminus` and `\sec`, and they sit at the very back behind every text command that happens to start with `se`. The list now floats the compiler's math commands above the text ones when the caret is in math mode. Nothing else changes: the same candidates, the same table order within each half, and in text mode the order is untouched — the existing ordering assertions in `CompletionTests` pass unedited. Two things keep their place above both halves: the spelling typed exactly (`\section` while in a formula is still `\section`), and the project index's own declarations, because the user's `\sigmoid` is more relevant than `\sigma` wherever the caret is. The mode itself comes from `SyntaxHighlighter`'s lexer, which already owns the delimiter, nesting and verbatim rules — a `$` inside a `verbatim` is a dollar sign, `cases` inside `align` is still math, and `\(…\)`/`\[…\]`/`$$…$$` are all handled. A second set of rules here would have been a second thing to drift. `SyntaxHighlighter.mode(at:text:)` is new: the mode *at* an offset rather than at its line start, re-lexing only the caret's line from that line's own start mode, so it costs one line and not a document. A model that does not match the text answers "not math" instead of guessing from a stale line table. The editor answers `mathModeAtCaret` from its in-sync syntax model on the main thread, where it is one line's lexing, and passes the result into the off-main scan through `CompletionScheduler.Request`. An unwired text view says no and gets the plain text-mode order. Implementation-Agent: claude-mac-lsp Commit-Executor: claude-mac-lsp Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
GoKubar
added a commit
that referenced
this pull request
Sep 14, 2026
…#397) `testBackslashTriggersCommandsAndPrefixFilters` asks for completions of `$\al` and asserted exactly `\alpha`, `\aleph`. amsmath's `\allowdisplaybreaks` entered the compiler's inventory today and matches that prefix too, so main's Mac suite has been failing on both halves of that assertion — labels and details. The completion is correct: the command is supported, it matches, and it sorts ahead of the two symbols in inventory order. The golden was stale, not the behaviour, so the golden moves. Worth noting separately, not fixed here: typing `\al` in math now offers a page-break permission ahead of `\alpha`. That is inventory order doing exactly what it says, but it is probably not what someone typing `\al` wants. Ranking is #245's subject, and #245 does not change this case — I checked by running it. apps/mac `swift test --skip NearbyInterfaceTests --skip NearbyLANInterfaceTests` on this branch: 1072 tests, 136 skipped, 0 failures (main is 2 failures at 23f6611). Implementation-Agent: Claude Opus 5 (Commander session, linux-primary) Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit) Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu Co-authored-by: Claude Opus 5 <[email protected]>
GoKubar
marked this pull request as ready for review
September 14, 2026 15:54
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.
Completion.Vocabularyis ordered text entries first, then math ones, and the command list offered that order everywhere. Inside$…$that is backwards: typing\sein a formula wants\setminusand\sec, and they sit at the very back behind every text command that happens to start withse.Nothing else changes: the same candidates, the same table order within each half, and in text mode the order is untouched — the existing ordering assertions in
CompletionTestspass unedited.Two things keep their place above both halves: the spelling typed exactly (
\sectionwhile in a formula is still\section), and the project index's own declarations, because the user's\sigmoidis more relevant than\sigmawherever the caret is.Where "math mode" comes from
SyntaxHighlighter's lexer, which already owns the delimiter, nesting and verbatim rules — a$inside averbatimis a dollar sign,casesinsidealignis still math, and\(…\)/\[…\]/$$…$$are all handled. A second set of rules here would have been a second thing to drift.SyntaxHighlighter.mode(at:text:)is new: the mode at an offset rather than at its line start, re-lexing only the caret's line from that line's own start mode. It costs one line, never a document, so it is fine on the main thread on every keystroke. A model that does not match the text answers "not math" rather than guessing from a stale line table.The editor answers
mathModeAtCaretfrom its in-sync syntax model on the main thread and passes the result into the off-main scan throughCompletionScheduler.Request. An unwired text view says no and gets the plain text-mode order.Tests
8 new cases in
CompletionMathModeTests: where the caret counts as math (all four delimiter pairs, nested math environments, verbatim, degenerate offsets), the ranking rule through thesupported:injection seam, the two things that outrank math symbols, that argument and word completions are byte-identical either way, and that the editor wires the hook up.🤖 Generated with Claude Code
https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu