Skip to content

Highlight parameter names after function invocation #76

Open

Description

@omniomi

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

Activity

  1. omniomi commented on May 2, 2018

    @omniomi
    ContributorAuthor

    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.

  2. changed the title [-]Highlight parameter names after function invocation?[/-] [+]Highlight parameter names after function invocation[/+] on May 21, 2018
  3. anthonyjvoss commented on Dec 12, 2018

    @anthonyjvoss

    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

  4. msftrncs commented on Dec 17, 2018

    @msftrncs
    Contributor
    		{
    			"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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions