Skip to content

[ValidateScript()] highlighting very incorrect #65

Closed

Description

The simplest test case for this is as follows:

function Verb-Noun{
    param(
        [ValidateScript({ Test-Path -Path $_ })]
        [string]
        $Path
    )
    Begin { }
    Process { }
    End { }
}

In about half of the themes I've looked through, and the majority of the default ones (especially the PS extension's ISE theme) there is a very glaring syntax highlight issue. Any cmdlet placed in the inline scriptblock will be highlighted in two different colours, switching colours at the dash. The closing brace will also inherit the offending colour.

Adding a line-break after the opening brace will hide the issue, but the cmdlet within the script block is then not highlighted as a cmdlet at all, either.

Some darker themes will obscure the issue, giving a similar colour pairing to the two halves of the cmdlet (e.g., Monokai Dark), but if you look you can still see the issue is present. On themes with a more restricted color palette (e.g., monochrome themes) the difference is often not noticeable.

Activity

  1. csandfeld commented on Mar 27, 2018

    @csandfeld

    And with this test case you will see that everything in the ValidateScript after if statements closing paren is not being highlighted (on the plus side the command within the parens is now highlighted with just one incorrect color)

    function Get-Something {
        [CmdletBinding()]
        Param(
            [ValidateScript({
                if (Test-Path -Path $_) {
                    $true
                }
                else {
                    $message = 'Cannot access path {0} as it does not exist' -f $_
                    Throw $message
                }
            })]
            [string]
            $Path
        )
        
        Get-ChildItem -Path $Path
    }
    

    Screenshot:
    snag-20180327_153058_0001

    Operating System:

    ProductName                      Version Build UBR
    -----------                      ------- ----- ---
    Windows 10 Enterprise Evaluation 1703    15063 966
    

    VSCode version:

    1.21.1
    79b44aa704ce542d8ca4a3cc44cfca566e7720f1
    x64
    

    PowerShell Editor Services Version:

    Major  Minor  Build  Revision
    -----  -----  -----  --------
    1      6      0      0
    

    VSCode Extensions:
    [email protected]

    PowerShell Version Table:

    Name                           Value
    ----                           -----
    PSVersion                      5.1.15063.966
    PSEdition                      Desktop
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
    BuildVersion                   10.0.15063.966
    CLRVersion                     4.0.30319.42000
    WSManStackVersion              3.0
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1
    
  2. omniomi commented on May 21, 2018

    @omniomi
    Contributor

    Fixed by #94

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions