TabExpansionPlusPlus icon indicating copy to clipboard operation
TabExpansionPlusPlus copied to clipboard

Bug in Get-CommandTreeCompletion with dynamic completion of option

Open powercode opened this issue 12 years ago • 5 comments

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?

powercode avatar Dec 09 '13 17:12 powercode

Yeah, this is a weak spot in TabExpansion++ - I'll look into it.

lzybkr avatar Dec 09 '13 21:12 lzybkr

There are a couple of use cases I've run in to. parameters with values of the form --parameter=value or --parameter value or --parameter:value

powercode avatar Dec 10 '13 10:12 powercode

Also running into this - has any progress been made here?

AndrewGaspar avatar Dec 23 '15 20:12 AndrewGaspar

I'm not sure, I recall @powercode fixing some things he ran into, but if you're having problems, it would seem like he hadn't fixed it, or at least not submitted a PR.

I'm happy to give pointers if you can contribute a fix.

lzybkr avatar Dec 24 '15 22:12 lzybkr

I found the source of the issue, and have created a pull request:

#79

razaraz avatar Sep 09 '16 20:09 razaraz