mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
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:
committed by
Jason Shirk
parent
a042dc1ff1
commit
ca5fc9c5a8
@@ -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 = @(
|
||||
|
||||
Reference in New Issue
Block a user