r/PowerShell • • 27d ago

Script Sharing Syntax highlighting for PS7's null operators in VS Code

https://github.com/BryanCuneo/ps-null-operator-scopes

I saw a comment on here earlier today about VS Code's syntax highlighting for PowerShell not being able to properly color PowerShell 7's null operators: ??, ??=, ?., and ?[]. I had never noticed this before because I've never even tried to do that, but it turns out that there is not built-in tokenization for these operators despite a 7 year old issue on the topic. I'd never written a VS Code extension before and this seemed like a fairly easy first task, so I wrote a small MIT-licensed extension that allows you to add syntax highlighting to these operators. Source code on GitHub here, install it from the VS Marketplace here.

Was pretty fun to build, though I don't know how practical it'll be for me since I use pretty minimal syntax highlighting personally. But I got to learn how to build and publish a VS Code extension and I'm considering tackling that GitHub issue and getting this functionality into the official highlighter. No promises though lol


I did use an LLM to help me find documentation, fix some errors in my JSON, and remind me how to write regex lookbehinds. I didn't use any agent system to write or publish the extension or documentation for me.

13 Upvotes

3 comments sorted by

3

u/omers 27d ago

Props for seeing something that needed fixing and doing it. I used to maintain the PowerShell/EditorSyntax repo but walked away for reasons we won't get into. It's unfortunate that it hasn't been shown any love in many years it seems.

1

u/lan-shark 27d ago

Thank you!

I have forked that repo and am at least somewhat understanding what's going on. I've been able to get the rules for these tokens working, tomorrow I'll see about tackling tests and all that. With any luck, we may actually get this updated at least a little

2

u/BlackV 27d ago

Nice!