Skip to content

Highlight parameter names after function invocation #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
omniomi opened this issue May 1, 2018 · 3 comments
Open

Highlight parameter names after function invocation #76

omniomi opened this issue May 1, 2018 · 3 comments

Comments

@omniomi
Copy link
Contributor

omniomi commented May 1, 2018

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" in switch -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 on constant.numeric and override negative integer highlighting.

Playing around on my own computer and adding this to powershell.tmLanguage.json:

{
    "match": "\\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+",
    "name": "variable.parameter.powershell"
},

I get the desired result although there may be edge cases I am not considering...

operators
commands

@omniomi
Copy link
Contributor Author

omniomi commented May 2, 2018

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.

@omniomi omniomi changed the title Highlight parameter names after function invocation? Highlight parameter names after function invocation May 21, 2018
@anthonyjvoss
Copy link

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:
image

@msftrncs
Copy link
Contributor

msftrncs commented Dec 17, 2018

		{
			"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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants