diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index d5cfae97fb6..16fbfe27ec6 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -566,10 +566,11 @@ internal static List CompleteCommandParameter(CompletionContex 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) diff --git a/test/powershell/Language/Parser/ExtensibleCompletion.Tests.ps1 b/test/powershell/Language/Parser/ExtensibleCompletion.Tests.ps1 index 436d9bffd8c..b17afc8226a 100644 --- a/test/powershell/Language/Parser/ExtensibleCompletion.Tests.ps1 +++ b/test/powershell/Language/Parser/ExtensibleCompletion.Tests.ps1 @@ -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 = @(