Skip to content

Pseudo binding for tab completion doesn't work property for positional arguments #17653

@MartinGC94

Description

@MartinGC94

Prerequisites

Steps to reproduce

Consider this example:

function Verb-Noun
{
    Param
    (
        [Parameter(Position = 0)]
        [string]
        $Param1,
        [Parameter(Position = 1)]
        [System.Management.Automation.ActionPreference]
        $Param2
    )
}
Verb-Noun -Param1 Hello <Tab>

I would expect the tab completion to suggest values for Param2 because it's the first positional parameter that hasn't been bound to a named parameter and this is how the real parameter binder works. Unfortunately it doesn't work, it simply falls back to the file/directory suggestions.
The same issue occurs if you (presumably by mistake) try to start the positional parameters at 1 instead of 0:

function Verb-Noun
{
    Param
    (
        [Parameter(Position = 1)]
        [System.Management.Automation.ActionPreference]
        $Param1
    )
}
Verb-Noun <Tab>

As far as I can tell the issue is here: https://github.com/PowerShell/PowerShell/blob/master/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs#L1596 where it looks if the position for the parameter matches exactly the position the cursor is at.

Expected behavior

Tab completion should find the right parameter to offer completions for.

Actual behavior

It falls back to the generic file/directory completion

Error details

No response

Environment data

PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.3.0-preview.5
PSEdition                      Core
GitCommitId                    7.3.0-preview.5
OS                             Microsoft Windows 10.0.19044
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

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