From 8744f461f66210dc8a982c082684db8a02f9131c Mon Sep 17 00:00:00 2001 From: Andrew Gaspar Date: Wed, 21 Dec 2016 17:48:17 -0800 Subject: [PATCH 1/2] Treat unbound command parameters as command arguments --- .../engine/CommandCompletion/CompletionCompleters.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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) From 0217379006bb22268b0c0c6870eada80cd351d8e Mon Sep 17 00:00:00 2001 From: Andrew Gaspar Date: Tue, 27 Dec 2016 09:16:00 +0000 Subject: [PATCH 2/2] Add test that validates extensible completion for tokens that begin with a Dash for native commands --- .../Parser/ExtensibleCompletion.Tests.ps1 | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) 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 = @(