Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lmerz1 opened this issue Jul 12, 2024 · 3 comments
Closed

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

lmerz1 opened this issue Jul 12, 2024 · 3 comments
Labels
C-bug Category: This is a bug

Comments

@lmerz1
Copy link

lmerz1 commented Jul 12, 2024

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:

  • Buggy case:
    screenshot image screenshot image screenshot image
  • Correct case 1: Either of the symbols not present (or at a different location)
    screenshot image screenshot image
  • Correct case 2: Added closing quote
    screenshot image
  • Correct case 3: Not in the first line
    screenshot image

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 (2cadec0)

@lmerz1 lmerz1 added the C-bug Category: This is a bug label Jul 12, 2024
@lmerz1 lmerz1 closed this as completed Jul 12, 2024
@lmerz1
Copy link
Author

lmerz1 commented Jul 12, 2024

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.

@lmerz1 lmerz1 reopened this Jul 12, 2024
@krish-r
Copy link
Contributor

krish-r commented Jul 13, 2024

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

@lmerz1
Copy link
Author

lmerz1 commented Jul 13, 2024

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. :-)

@lmerz1 lmerz1 closed this as completed Jul 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug
Projects
None yet
Development

No branches or pull requests

2 participants