IronGeek / vscode-env

.ENV formatter for Visual Studio Code
MIT License
25 stars 1 forks source link

Syntax coloring is incorrect for inline comments #12

Closed eric-burel closed 1 year ago

eric-burel commented 1 year ago

Example:

FOOBAR= # set foobar here

Result: image

The comment should be displayed as text.

I think more broadly anything after "=" should be displayed in the same color, avoiding risks of confusions

IronGeek commented 1 year ago

Thank you for filling this issue.

I've tested your example using motdotla/dotenv and joho/godotenv

In both test, the comment is actually treated as comment (ignored) The FOOBAR value in this case is <empty string>

To treat any string with hash (#) as part of the value itself instead of comment, you actually need to wrap it in quotes:

# this is a comment
FOOBAR=value
FOOBAR_COMMENT=value # comment
FOOBAR_QUOTED="value"
FOOBAR_QUOTED_COMMENT="value" # comment
FOOBAR_EMPTY=
FOOBAR_EMPTY_COMMENT= # comment
FOOBAR_EMPTY_QUOTED_COMMENT="" # comment
FOOBAR_QUOTED_HASH="value # comment"
FOOBAR_SQUOTED_HASH='value # comment'

just in case GitHub syntax highlighting is not working: image

What env parser implementation are you using? Is the # set foobar here in FOOBAR= # set foobar here actualy treated as value?

eric-burel commented 1 year ago

Hi, thanks for your fast reply and experiment, this helped a lot understanding the issue.

This is an issue that affects Next.js apps during build, I've built a repro.

Closing this issue as indeed inline comments are expected to work as intended with dotenv, so your plugin works as expected.