ValidateSet/Register-ArgumentCompleter/Enum completions does not work correctly on Arrays · Issue #13757 · PowerShell/PowerShell · GitHub
Skip to content

ValidateSet/Register-ArgumentCompleter/Enum completions does not work correctly on Arrays #13757

@PrzemyslawKlys

Description

@PrzemyslawKlys

Steps to reproduce

function New-Function {
    [cmdletBinding()]
    param(
        [validateSet('New', 'Old', 'Other')][string[]] $Test1,
        [validateSet('New', 'Old', 'Other')][string[]] $Test2
    )
}
New-Function -Test1 New -Test2 New
New-Function -Test1 New, Old -Test2 New
New-Function -Test1 New, Old -Test2 New

Paste in VSCode. Try to autocomplete Test2 parameter on line 8 (first instance in the script). It will work for 1st element of array, but if you try adding 2nd or 3rd element autocomplete fails.

It works correctly if you start from top to bottom as in

function New-Function {
    [cmdletBinding()]
    param(
        [validateSet('New', 'Old', 'Other')][string[]] $Test1,
        [validateSet('New', 'Old', 'Other')][string[]] $Test2
    )
}
New-Function -Test1 New -Test2 New

It will work on line 8

function New-Function {
    [cmdletBinding()]
    param(
        [validateSet('New', 'Old', 'Other')][string[]] $Test1,
        [validateSet('New', 'Old', 'Other')][string[]] $Test2
    )
}
New-Function -Test1 New -Test2 New
New-Function -Test1 New, Old -Test2 New
New-Function -Test1 New, Old -Test2 New

It will work on line 10 but fails for lines 8 and 9.

image

Originally reported in VSCode PowerShell extension where more discussion is present: PowerShell/vscode-powershell#2982

Expected behavior

Autocomplete working on arrays in any order. On first line, last line, middle line.

Actual behavior


Environment data

Name                           Value
----                           -----
PSVersion                      7.1.0-rc.1
PSEdition                      Core
GitCommitId                    7.1.0-rc.1
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Interactive-IntelliSensetab completion

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions