some-sass icon indicating copy to clipboard operation
some-sass copied to clipboard

Indented comments don't have correct syntax highlighting

Open wkillerud opened this issue 1 year ago • 1 comments

In which editor is this a problem?

Visual Studio Code

Describe the bug

For Sass indented, indented-style comments don't get the correct syntax highlighting.

What's the expected result?

Indented comments should work the same as non-indented.

Link to minimal reproducible example

https://gist.github.com/wkillerud/1bf8ebb0d1c9db10bf4c7bca45805f13

Participation

  • [ ] I am willing to submit a pull request for this issue.

wkillerud avatar Oct 02 '24 16:10 wkillerud

The syntax highlighting is based on the TextMate grammar in vscode-extension/languages/. These lines to be specific:

https://github.com/wkillerud/some-sass/blob/b88b5f7937bc4b85e6968f3b7fa2a1d345d18f96/vscode-extension/languages/sass.tmLanguage.json#L933-L957

The problem is to figure out how to end the comment block.

I did an experiment with semantic tokens to perhaps fix this issue outside of the TextMate grammar, but it didn't seem to have any visual effect.

wkillerud avatar Oct 02 '24 16:10 wkillerud

can use begin/while (instead of begin/end) https://github.com/RedCMD/TmLanguage-Syntax-Highlighter/blob/main/documentation/rules.md#while

"begin": "//"
"while": "^(  |\t|$)"

here's my VSCode extension to help with authoring TextMate grammars https://marketplace.visualstudio.com/items?itemName=RedCMD.tmlanguage-syntax-highlighter

RedCMD avatar Aug 15 '25 09:08 RedCMD

Hi @RedCMD, thanks for the suggestion. Unfortunately it only works at the root level. With that grammar any time I use // in a lower scope all the lines below it get treated as a comment.

Image

wkillerud avatar Aug 15 '25 17:08 wkillerud

ah my bad should add the prefix whitespace on it aswell

"begin": "^([ \t]*)(//)"
"while": "^\\1(  |\t)|[ \t]*$"

this won't work for comments on the end of code lines so just fall back to the begin/end rule

I assume empty lines (with any number of whitespace) counts towards the comment otherwise just remove the $ section

RedCMD avatar Aug 15 '25 19:08 RedCMD

Had to make some slight tweaks, the |[ \t]* made the while always apply (zero or more), but I got it working! Didn't know about while or the option to reference capture groups. Thank you @RedCMD 🎉

wkillerud avatar Aug 16 '25 13:08 wkillerud