lzybkr / TabExpansionPlusPlus

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

Import-Module completer interferes with loading modules by path #70

Closed jazzdelightsme closed 8 years ago

jazzdelightsme commented 8 years ago

When loading a module that is not in $Env:PsModulePath, you have to specify the full path to the .psd1/.psm1, like "ipmo C:\src\MyMod\MyMod.psd1". It is handy to use tab completion to complete various parts of that path.

Unfortunately, the completer for Import-Module's Name parameter interferes with this. When you hit [Tab], it replaces the path you've been building with just the name of a module that it discovered on that path. For instance, typing something like "ipmo C:\src\MyM[Tab]" completes to just "ipmo MyMod", which won't work (or vexingly, if C:\src\MyMod contains an in-development version of your module, but MyMod also exists on $Env:PsModulePath, it will work, but load the other one that you didn't want).

For reference, here is the completer (found in Microsoft.PowerShell.Core.ArgumentCompleters.ps1):

function ImportModuleNameCompleter
{
    param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)

    Microsoft.PowerShell.Core\Get-Module -ListAvailable -Name "$wordToComplete*" | Sort-Object Name | ForEach-Object {
        $tooltip = "Description: {0}`nModuleType: {1}`nPath: {2}" -f $_.Description,$_.ModuleType,$_.Path
        New-CompletionResult $_.Name $tooltip
    }
}