helix-editor / helix

A post-modern modal text editor.
https://helix-editor.com
Mozilla Public License 2.0
32.53k stars 2.4k forks source link

Bash/Posix sh: Syntax highlighting wrong in specific `cat << EOF` case #11148

Closed lmerz1 closed 1 month ago

lmerz1 commented 1 month ago

Summary

Given a

cat <<EOF
[some text]
EOF

heredoc block in a Unix shell script, syntax highlighting stops working for anything after the closing EOF if the [some text], seemingly only in the first line of the block, contains a single quote (') anywhere in the line and the line starts with a variable ($ as line's first character).

I have tested this with different and the default themes, so it does not appear to be a theming issue.

From a quick test, my old-ish VSCodium I still keep around does not seem to exhibit this issue, so I don't think it's the language server. I might be wrong on that.

Reproduction Steps

Save the following as repro.sh and open it.

usage() {
    cat <<EOF
${1}: text with quote'

more text (contents of which do not seem to matter)
    more text, indented
more text
EOF
    exit 2
}

err() {
    # some other code to illustrate incorrect syntax highlighting
    echo "hi"
}

verbose() {
    echo github
}

Delete either the ', $, or both in line 3 in order for the syntax highlighting to be correct again. Alternatively, add a second single quote anywhere before the closing EOF.

Notice how syntax highlighting also turns correct if you add another line with any non-empty content (even whitespace) above ${1}: text with quote' – it really has to be these two characters (and with the single quote only occurring once or possibly an uneven number of times), and both occurring in the first line as described.

Screenshots:

Edit: added more screenshots

Helix log

No response

Platform

macOS

Terminal Emulator

n/a (kitty and Hyper and Terminal.app)

Installation Method

brew

Helix Version

helix 24.3 (2cadec0b)

lmerz1 commented 1 month ago

Perhaps also interestingly, when adding quotes to the EOF symbol, which means "interpret the following block literally and do not substitute any values", the now-not-a-variable-anymore ${1} doesn't trigger the incorrect highlighting.

Screenshot screenshot image

Edit: did not mean to close, oops.

krish-r commented 1 month ago

I believe heredoc highlighting in bash was recently fixed in #11118

lmerz1 commented 1 month ago

Thanks. You would of course be correct. I didn't recall the name of the construct which is why searching for this issue didn't work for me. :-)