Automattic / Automattic/harper

LaTeX: Diagnostics halt for the rest of the file after inline math ($...$) inside a macro

Open
#3,791 3 comments 0 reactions 0 assignees View on GitHub
bug tex
Dominant language
Rust
Stars
15.4k
Forks
627
Avg merge
1d 15h
Merged PRs (30d)
106

Description

**Describe the bug**
`harper-ls` completely stops providing diagnostics for the remainder of a LaTeX document after encountering an inline math mode node (`$...$`) that is opened inside a macro (such as `\caption{`). After parsing the math node, the language server silently fails to check any further spelling or grammar errors.

**To Reproduce**
Steps to reproduce the behavior:
1. Create a new `.tex` file with the following minimal working example:
```latex
\begin{document}
\section{TEST}
errawr % this typo will be caught by harper-ls

\begin{figure}
\caption{This is a test of the projection space ($N_{THC}$
\end{figure}

errawr % this typo will be completely ignored
\end{document}
```
2. Open the file in an editor with `harper-ls` attached.
3. Observe that diagnostics are provided for the first "errawr".
4. Scroll down past the `\caption` block and observe that the second "errawr" (and any subsequent text) receives no diagnostics.

**Expected behavior**
`harper-ls` should successfully parse and ignore the inline math block within the macro argument and continue providing diagnostics for the remainder of the document.

**Screenshots**
N/A - The issue can be reproduced strictly via the text snippet above.

**Platform**
Helix (via `harper-ls` v2.6.0).

**Additional context**
Through testing, the parser halt seems directly tied to how `harper-ls` handles the state transition of creating a math node while already inside a macro argument scope.
* The bug does NOT require the macro to be properly closed with `}`. The presence of the `$ ... $` pair inside the opening `{` is enough to trigger the bailout.
* If the dollar signs are escaped (`\$N_{THC}\$`), the server *does not* break and checks the whole file.
* If standard LaTeX parenthesis delimiters are used (`\( N_{THC} \)`), the server *does not* break.
The crash specifically occurs when paired `$` delimiters are successfully matched inside a macro, causing the AST parser to drop the rest of the file.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with the minimal .tex document and inspect the LaTeX AST parsing path for paired `$...$` math opened inside a macro argument. Done means the parser continues after that node and harper-ls reports diagnostics for the later "errawr" text, including when the macro is unclosed.

Written by the indexing model from the issue text.

Assessment

Tech stack
latex, rust
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.