Skip to content

Bug in Get-CommandTreeCompletion with dynamic completion of option #26

@powercode

Description

@powercode

I'm trying to write a completer for p4 edit

nct edit $msgTable.p4_edit {
                nct '-c' $msgTable.p4_edit_c {
                    nct {
                        param($wordToComplete, $commandAst)

                        p4 -ztag changes -s pending -u $env:DomainName\$env:UserName | 
                            Select-String '^\.\.\. change (\d+)' | 
                                ForEach-Object {$_.matches.Groups[1].Value} | 
                                    where {$_ -like "$wordToComplete*"} 
                    }
                }                                
            }

but the completer never seems to get called.

-c is parsed as a System.Management.Automation.Language.CommandParameterAst and the check in Get-CommandTreeCompletion

if (!($commandElements[$i] -is [System.Management.Automation.Language.StringConstantExpressionAst]))

skips that commandElement.

I'm a bit uncertain what the correct fix is? Should I change the condition toaccept CommandParameterAst or StringConstantExpressionAst?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions