fix: bash heredoc ending prematurely on single-word content lines
A bash heredoc like this gets its syntax highlighting cut off at "DoesNotWork":
cat <<HELLO
# comment
DoesNotWork
HELLO
The heredoc end regex in sh.yaml (^[^\s]+[A-Za-z0-9]+$) matched any line that was a single word, regardless of whether it was actually the delimiter. So a content line with one word and nothing after it ended the heredoc, turning the rest of the block into un-highlighted text. The same bug fires for any line where a word sits alone without spaces around it and no trailing words.
The fix has two parts:
-
Engine-side: added a delimiter tracking mechanism to the highlighter. The
regionstruct gets adelimiterfield. When a region starts with a regex that has a capture group (like the heredoc start),regionWithDelimiter()captures the matched delimiter word. Then inhighlightRegion(), when the end regex fires, the matched text is verified against the stored delimiter before the region actually closes. This means the end regex only ever closes the region that the start regex opened, which is how heredocs are supposed to work. -
Syntax-side: updated the heredoc rules in sh.yaml. The start regex now captures the delimiter into a group:
<<-?([A-Za-z_][A-Za-z0-9_]*). The end regex is simplified to match identifiers:^([A-Za-z_][A-Za-z0-9_]*). The engine's delimiter check handles the rest.
Added a test in pkg/highlight/heredoc_bug_test.go that loads the sh.yaml syntax, highlights a heredoc with a single-word content line, and asserts the line stays inside the constant.string group and that the real delimiter line properly ends the region. Without the fix the test fails: "DoesNotWork" gets assigned group 0 (un-highlighted) instead of constant.string. With the fix it passes cleanly. All existing tests pass too.
Closes #4114