Fix tab completion of native parameters (#2919)

Native argument completers were not invoked when the argument was a single dash.

The fix is to treat unbound command parameters as command arguments for the purposes of parameter/argument completion.
This commit is contained in:
Andrew Gaspar
2017-02-13 16:02:56 -08:00
committed by Jason Shirk
parent a042dc1ff1
commit ca5fc9c5a8
2 changed files with 35 additions and 2 deletions
@@ -566,10 +566,11 @@ namespace System.Management.Automation
PseudoBindingInfo pseudoBinding = new PseudoParameterBinder()
.DoPseudoParameterBinding(commandAst, null, parameterAst, PseudoParameterBinder.BindingType.ParameterCompletion);
// The command cannot be found or it's not a cmdlet, not a script cmdlet, not a function
// The command cannot be found or it's not a cmdlet, not a script cmdlet, not a function.
// Try completing as if it the parameter is a command argument for native command completion.
if (pseudoBinding == null)
{
return result;
return CompleteCommandArgument(context);
}
switch (pseudoBinding.InfoType)
@@ -229,6 +229,38 @@ Describe "Test extensible completion of native commands" -Tags "CI" {
} | Get-CompletionTestCaseData | Test-Completions
}
Describe "Test completion of parameters for native commands" -Tags "CI" {
Register-ArgumentCompleter -Native -CommandName foo -ScriptBlock {
Param($wordToComplete)
@("-dir", "-verbose", "-help", "-version") |
Where-Object {
$_ -match "$wordToComplete*"
} |
ForEach-Object {
[CompletionResult]::new($_, $_, [CompletionResultType]::ParameterName, $_)
}
}
@{
ExpectedResults = @(
@{CompletionText = "-version"; ResultType = "ParameterName"}
@{CompletionText = "-verbose"; ResultType = "ParameterName"}
@{CompletionText = "-dir"; ResultType = "ParameterName"}
@{CompletionText = "-help"; ResultType = "ParameterName"}
)
TestInput = 'foo -'
} | Get-CompletionTestCaseData | Test-Completions
@{
ExpectedResults = @(
@{CompletionText = "-version"; ResultType = "ParameterName"}
@{CompletionText = "-verbose"; ResultType = "ParameterName"}
)
TestInput = 'foo -v'
} | Get-CompletionTestCaseData | Test-Completions
}
Describe "Test extensible completion of using namespace" -Tags "CI" {
@{
ExpectedResults = @(