fix: LaTeX diagnostics halt after unmatched inline math ($) inside a macro - #3835
Open
mvanhorn wants to merge 1 commit into
Open
fix: LaTeX diagnostics halt after unmatched inline math ($) inside a macro#3835mvanhorn wants to merge 1 commit into
mvanhorn wants to merge 1 commit into
Conversation
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.
Issues
Fixes #3791
Description
The tex masker lives in
harper-tex/src/masker.rs. Its top-levelcreate_maskloop reaches\caption{...}and callsdeconstruct_command, whose curly-content scan stops at the FIRST}(the inner}ofN_{THC}), truncating the caption argument so the cursor lands on the second, now-unpaired$. The loop then callsmath_mode_at_cursoron that lone$; because there is no closing$left in the document it counts every remaining character and returnsremaining + 2, so the followingPushMaskAndIncBymasks the entire rest of the file - dropping all later tokens and hence all diagnostics. Primary fix: makemath_mode_at_cursorrequire a matching closing$- when no closing$follows the opener, returnNone(or mask only the single$) instead of consuming to end-of-file, mirroring the running-off-the-end guard already present inequation_at_cursor. This restores diagnostics for the remainder of the document exactly as the reporter expects, and is a minimal, convergent change. The deeper root cause (naive first-}curly-argument parsing indeconstruct_commandnot balancing nested braces) may optionally be hardened in the same function, but the reported halt is fully resolved by themath_mode_at_cursorguard, so scope stays tight to avoid regressing existing tex snapshots.Demo
N/A - behavioral fix; validated by the tests below.
How Has This Been Tested?
harper-tex/tests/test_sources/issue_3791.texreproducing the issue snippet (twoerrawrtypos around a\caption{ ... ($N_{THC}$block) and acreate_test!(issue_3791.tex, N)entry inrun_tests.rsasserting both typos are still linted (rest-of-file diagnostics no longer suppressed), following the existingissue_2835.texprecedent.#[cfg(test)] mod testsblock ofmasker.rs: a lone/unmatched$does not mask the remainder - text after the stray$remains in the allowed spans of the mask.$...$is still fully masked;\$ ... \$and\( ... \)continue to work; empty$$and a trailing$at end-of-file neither panic nor over-consume.create_maskdoes not panic on a document that ends with an unclosed$(extends the existing trailing-backslash non-panic guarantees).AI Disclosure
If Your PR Implements or Enhances a Linter
Checklist