Skip to content

mac: rank math commands first when the caret is in math mode - #245

Merged
GoKubar merged 1 commit into
mainfrom
agent/mac-math-ranking
Sep 14, 2026
Merged

GoKubar merged 1 commit into
mainfrom
agent/mac-math-ranking

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

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.

$x \se          before                 now
                \section              \sec        math · upright operator name
                \setcounter           \setminus   math · symbol ∖
                \setlength            \section
                …                     \setcounter
                \sec                  …
                \setminus

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.

Where "math mode" 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. 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 mathModeAtCaret from its in-sync syntax model on the main thread 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.

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 the supported: 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

`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
GoKubar marked this pull request as ready for review September 14, 2026 15:54
@GoKubar
GoKubar merged commit f07ac6b into main Sep 14, 2026
20 checks passed
@GoKubar
GoKubar deleted the agent/mac-math-ranking 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.

1 participant