Open omniomi opened 6 years ago
On further experimentation the regex above does indeed catch negative integers. A quick n' dirty workaround is to include \\d+
in the negative lookahead as a purely numerical parameter name is unlikely although parameter names that include some numbers do exist such as -UseUTF16
on New-PSSessionOption
making the \\w+
necessary.
Glad I found an existing open issue on this. It would be great to see the same syntax highlighting that exists in the Powershell console:
{
"match": "(?:(?<!\\w|!)|\\G)-[\\p{L}][\\w]*(?!\\p{L})",
"name": "entity.other.attribute-name.powershell"
},
I added this to my JSON file after all the other operators, seems to do the trick. I think the look ahead is redundant, but it was left over from the other operators. The scope was just what I experimented with.
~I couldn't find anything definitive, can a parameter name begin with a digit? Or is that impossible since variable names cannot start with a digit?~ EDIT, forgot, in PowerShell, they can be entirely numeric! That raises the level of complexity.
Given
Get-ChildItem -Path . -Recurse
I cannot find a way to highlight "Path" and "Recurse". Currently I've only managed to highlight the-
. The same goes for say "regex" inswitch -Regex () {}
.It's gross but surly something like
\\s\\-(?!(?i:[ic]?(?:eq|ne|gt|lt|ge|le|not|isnot|is|f|as|like|notmatch|match|notcontains|contains|in|and|or|xor|join|split|band|bor|bnot|bxor|replace))\\s)\\w+
would cover it? Provided it didn't step onconstant.numeric
and override negative integer highlighting.Playing around on my own computer and adding this to powershell.tmLanguage.json:
I get the desired result although there may be edge cases I am not considering...