lzybkr / TabExpansionPlusPlus

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

Minor fix for when there are completers with no applicable commands #6

Closed jazzdelightsme closed 11 years ago

jazzdelightsme commented 11 years ago

This is the thing that is always populating my $Error with stuff, because I don't have the Hyper-V module installed.

lzybkr commented 11 years ago

Thanks for tracking down the problem.

The proposed fix isn't quite right - I think it breaks 2 scenarios:

I'm happy to fix the bug if you prefer.

jazzdelightsme commented 11 years ago

Hmm... will it break those scenarios, or are they already broken? Without the change, the errors that show up in $error are like this:

Register-ArgumentCompleter : Cannot bind argument to parameter 'CommandName' because it is null.
At C:\Projects\DbgShell\DbgShell\bin\Debug\x86\TabExpansion++\TabExpansion++.psm1:675 char:40
+             Register-ArgumentCompleter @parameters
+                                        ~~~~~~~~~~~

So if it can't bind the param, it doesn't end up calling Register-ArgumentCompleter in those cases at all, right? (or does it?)

jazzdelightsme commented 11 years ago

Oh... maybe you're saying that we should supply an empty string for the CommandName? Which could be done by adding $parameters[ 'CommandName' ] = @( '' ). But would it be weird, or a pessimization, to have completers for commands you don't have?

lzybkr commented 11 years ago

CommandName doesn't need to be specified, e.g.:

Register-ArgumentCompleter -ParameterName FooBar -ScriptBlock {
    New-CompletionResult -CompletionText Zoo
}
function zed($FooBar) {}
zed -FooBar <TAB>

I tried a quick repro by taking one of the Hyper-V completers and changing the module name. I didn't see any errors in $error. The completer is also not registered, which I think is a good thing, but the background processing makes it hard to figure out why, in the case of a typo for example, nothing was registered.

lzybkr commented 11 years ago

Never mind - user error. I found a repro and found a better fix, now committed.

jazzdelightsme commented 11 years ago

Thanks!