Feature Request: Syntax Highlight 'script:' and 'shell:' blocks as scripts
MillironX opened this issue · 4 comments
It would be extremely helpful to have script
and shell
blocks syntax highlighted in the proper language rather than as string literals.
Expected Behavior
Multi-line strings at the end of a process
, those within an if
block, and those marked as script:
or shell:
should have syntax highlighting matching their language. Without any label, these should be highlighted as a shell script, but a shebang would change the highlighting of that block to match the indicated language (e.g. a block starting with #!/usr/bin/env perl
would receive Perl syntax highlighting). In the case of a shell
block, the !
variable placeholder should receive variable highlighting distinct from the target language.
Current Behavior
End-process strings, script
blocks and shell
blocks are all highlighted as string literals. The only highlighting that takes place within these blocks occurs when using curly bracket variable syntax (i.e. ${var}
). No distinction is made at all for the !
variable placeholder regardless of curly brackets.
Possible Implementation
A short-term fix would be to replace multi-line strings with shellscript
as an embedded language. This would impede the use of multi-line strings elsewhere, but IMHO this tradeoff is worth it. This wouldn't allow for changing the language based on shebang, though.
In the longer-term, semantic highlighting might be able to highlight blocks according to shebang, and parse which are simple multi-line strings and which are code.
I don't know how/if DSL2 affects this behavior.
Came here to make the same issue after seeing this twitter post (and this thread below it).
Hey Phil!
Not sure if what I did will apply to you, but I followed the steps outlined in the section “Injection grammars” in this guide.
I created the TCSS grammar that you can see here: https://github.com/Textualize/tcss-vscode-extension/tree/main/syntaxes
And then I created thepython.injection.json
grammar that hooks the TCSS grammar into Python.
I've wanted this feature for years but never realised that it was a possibility until now.
I'm the OP of the linked Twitter post. Just wanted to say I'm available to give some pointers, if needed, but I'm not an expert on these matters. I essentially just followed the instructions in the extension guide that was also linked above :)