Skip to content

Tab completion confusion with common parameters #1265

Closed

Description

@lzybkr

Steps to reproduce

function foo { param($DebugBuild) }

  1. Receive-Job -wa<TAB>
  2. foo -D<TAB>
  3. foo -Debug<TAB>

Expected behavior

  1. Cycle through -Wait and -WarningAction
  2. Cycle through -Debug and -DebugBuild
  3. Cycle through -Debug and -DebugBuild

Actual behavior

  1. Only completes -WarningAction
  2. Only completes -DebugBuild
  3. No additional completion

Activity

  1. added
    Issue-Bug
    Up-for-Grabs
    on Jul 1, 2016
  2. modified the milestone: on Aug 4, 2016
  3. Peter-Schneider commented on Aug 25, 2016

    @Peter-Schneider
    Contributor

    The actual behavior of case 2 should be ok unless you are using the cmdletbinding attribute.

  4. modified the milestones: , on May 22, 2017
  5. adamgauthier commented on Jul 25, 2018

    @adamgauthier
    Contributor

    Additional information on this issue

    First, the matcher finds 3 possible matches: -Wait, -WarningAction and -WarningVariable (which is normal).

    There are 2 issues here:

    • The matcher finds an exact match so it autocompletes to it without cycling through other results (in this case alias wa is an exact match for parameter WarningAction). Is this intended behavior? Should Tab cycle through matches or simply complete an alias like it does now?

    • Even if the text doesn't match an exact alias, for example with Import-Module -ve (Tab expansion for cmdlet arguments prefers aliases #6150), the matcher will find 2 possible matches: -MinimumVersion and -Verbose, however, it will prefer parameters in the cmdlet over common parameters, and will effectively return -MinimumVersion as the only match since Verbose is a common parameter (same thing would happen for -Wait if wa wasn't an alias for WarningAction).

    I doubt the second one is intended behavior, but digging through the code I think I'm too unfamiliar with the codebase to find a good solution. Hope this helps other people:

    If you want to dig in, this occurs in
    CompletionCompleters.CompleteCommandParameter() ->
    PseudoParameterBinder.DoPseudoParameterBinding() ->
    PseudoParameterBinder.BindNamedParameters() ->
    MergedCommandParameterMetadata.GetMatchingParameter()
    You can see there the aliases loop and then the logic to filter common parameters.

  6. removed
    Up-for-Grabs
    on Jul 26, 2018
  7. SteveL-MSFT commented on Jul 26, 2018

    @SteveL-MSFT
    Member

    Adam Gauthier (@louistio) Thanks for the investigation details!

    In the your first issue, even if an exact match is found, I would expect it to cycle through other possible matches. For the second, it should also all possible matches including common parameters.

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

Metadata

Metadata

Labels

Issue-BugResolution-FixedWG-Interactive-IntelliSense

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions