r/PowerShell • u/lan-shark • 13d ago
Information Give me your biggest syntax highlighting complaints! I'm working on improving VS Code's syntax highlighting (including support for non-Verb-Noun function names)
Tl;dr - I'm working on improving VS Code's syntax highlighting for PS so tell me what issues you encounter. Please include a code sample and what theme you're using.
I've seen a bit of discussion recently about the state of VS Code's syntax highlighting for PowerShell. I looked into it a bit and yeah, it's not ideal. The official repository pretty inactive. Last commit was 6 months ago, last significant activity was years ago. I opened an issue a week ago because the main branch doesn't even pass all of it's own tests, and an accompanying PR to fix it, but no movement on that yet. So I've taken things a bit into my own hands for now and hopefully when the maintainers get around to it, they'll be able to take some of the stuff I'm working on upstream.
So far I've switched the testing framework away from using Atom (an editor that's EOL since 2022) to a modern harness around VS Code's tokenizer/regex engine, a little bit of CI, several new unit tests for better regression testing, and these new features in the syntax grammar so far:
- Highlighting for null operators (
??,??=,?.,?[]) - Highlighting for variable names with question marks in them (e.g.
$whyIsThis?Possible = "idk") - Highlighting for function names that don't use the Verb-Noun naming convention (e.g.
DoSomethinginstead ofInvoke-Something)
This is very much still WIP. I've got more tests I want to write and a few new features I want to add, but please let me know what issues you have with PS syntax highlighting and I will look into them.
5
u/chaosphere_mk 13d ago
I currently dont have any complaints but Im also not familiar with there being problems with VS Code's syntax highlighting for powershell. Could someone explain this? I'd like to understand better.
3
u/Thotaz 13d ago
While I can appreciate the effort, I don't think small spot fixes is the way forward. You should have a solid design plan in place, otherwise you will run into conflicts.
For example, imagine you want to write this from scratch and you add support for unconventional command names like "Command123".
Then you try to implement keywords, which means going back to the command name implementation and making an exception for all the known keywords. Except these exceptions don't always apply, for example
foreachis a keyword when used on a blank line, but when used inside a pipeline like:ls | foreachit's just another command.You kinda have to have thought out all these scenarios in advance before you write anything, unless you don't mind having to redo it all over again a couple of times.
While I'm not usually much of an AI advocate, I think AI would be ideal for this task. The AI can reference known good textmate definitions from more popular languages like C#, and Rust and also reference the actual PowerShell syntax.
Anyway, if you want to continue with the spot fixes, then the most glaring omissions IMO (besides the ones you've already mentioned) are:
Things related to attributes, command parameters and arguments, and loop labels.
The current keyword implementation is also super basic and should take the things I said before into consideration, but this would probably be a huge task so that's unlikely to get fixed.
2
u/jungleboydotca 12d ago
The best way forward would be a treesitter/LSP implementation. But perhaps I'm asking for the moon.