lzybkr / TabExpansionPlusPlus

A V3 PowerShell module to improve tab expansion and Intellisense
BSD 2-Clause "Simplified" License
196 stars 33 forks source link

Completion in WMF 5 April preview #41

Closed powercode closed 8 years ago

powercode commented 9 years ago

I don't get any custom completion working at all, whether I use tabexpansion++ or the built-in Register-ArgumentCompleter.

Know issue or supid user error?

bielawb commented 9 years ago

Check if you are not using New-CompletionResult in your code. Register-ArgumentCompleter is now cmdlet and won't work with this function (that is private to TabExpansion++ module).

For example, to get VM Name completed in Hyper-V module you'd have to:

$list = (Get-Command -Module Hyper-V -Noun VM).Name
Register-ArgumentCompleter -CommandName $list -ParameterName Name -ScriptBlock {
    param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)

    $optionalCn = @{}
    $cn = $fakeBoundParameter["ComputerName"]
    if($cn)
    {
        $optionalCn.ComputerName = $cn
    }

    Hyper-V\Get-VM -Name "$wordToComplete*" @optionalCn |
        Sort-Object |
        ForEach-Object {
            $toolTip = "State: $($_.State) Status: $($_.Status)"
            [System.Management.Automation.CompletionResult]::new(
                $_.Name,
                $_.Name,
                'ParameterValue',
                $toolTip
            )
        }
}

As you can see I'm using [ComletionResult] constructor. AFAIK this is the only way in this release. I hope to see some friendly command to that in the next one TBH. ;)

pcgeek86 commented 9 years ago

@powercode @bielawb I am having the same problem with this. I just installed TabExpansion++ on Windows 10 Build 10130, ran Get-ArgumentCompleter, and have no results.

Cheers, Trevor Sullivan Microsoft MVP: PowerShell

lzybkr commented 9 years ago

This is a known issue - the ArgumentCompleter attribute in TabExpansion++ is colliding with the attribute in WMF5.

I will be removing the attribute based registration mechanism in TabExpansion++ because:

I wrote a script to convert existing completers, you can see it here: https://gist.github.com/lzybkr/0329f3346730c6135121

I think I'm mostly done fixing TabExpansion++, I just haven't found the time to test the changes thoroughly.

pcgeek86 commented 9 years ago

@lzybkr I tried to run the conversion script against the TabExpansion++ module directory, and received the following exceptions. Are there any specific requirements to run the conversion script? Should I copy the argument completer scripts to a new, empty folder? Perhaps the script is barfing on the non-PowerShell files in the module directory?

2015-06-25 11_28_41-start

Cheers, Trevor Sullivan Microsoft MVP: PowerShell

lzybkr commented 9 years ago

Hmm, yeah, just run it on ps1 files. I know I ran it on *.ArgumentCompleters.ps1 and inspected some of results and it looked good.

pcgeek86 commented 9 years ago

@lzybkr I think I see the problem. I was not pipelining objects into it. Looks like it doesn't support passing in a folder path.

lzybkr commented 8 years ago

Closing as this is probably a non-issue now - folks have probably already converted to support WMF5 and the latest TabExpansionPlusPlus on the PowerShell gallery.