Skip to content

Commit b385e54

Browse files
authored
Add completion single/double quote support for -PSEdition parameter (PowerShell#24971)
1 parent f22ad2e commit b385e54

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

src/System.Management.Automation/engine/Modules/GetModuleCommand.cs

+15-14
Original file line numberDiff line numberDiff line change
@@ -586,24 +586,25 @@ private static IEnumerable<ModuleSpecification> GetCandidateModuleSpecs(
586586
}
587587

588588
/// <summary>
589-
/// PSEditionArgumentCompleter for PowerShell Edition names.
589+
/// Provides argument completion for PSEdition parameter.
590590
/// </summary>
591591
public class PSEditionArgumentCompleter : IArgumentCompleter
592592
{
593593
/// <summary>
594-
/// CompleteArgument.
594+
/// Returns completion results for PSEdition parameter.
595595
/// </summary>
596-
public IEnumerable<CompletionResult> CompleteArgument(string commandName, string parameterName, string wordToComplete, CommandAst commandAst, IDictionary fakeBoundParameters)
597-
{
598-
var wordToCompletePattern = WildcardPattern.Get(string.IsNullOrWhiteSpace(wordToComplete) ? "*" : wordToComplete + "*", WildcardOptions.IgnoreCase);
599-
600-
foreach (var edition in Utils.AllowedEditionValues)
601-
{
602-
if (wordToCompletePattern.IsMatch(edition))
603-
{
604-
yield return new CompletionResult(edition, edition, CompletionResultType.Text, edition);
605-
}
606-
}
607-
}
596+
/// <param name="commandName">The command name.</param>
597+
/// <param name="parameterName">The parameter name.</param>
598+
/// <param name="wordToComplete">The word to complete.</param>
599+
/// <param name="commandAst">The command AST.</param>
600+
/// <param name="fakeBoundParameters">The fake bound parameters.</param>
601+
/// <returns>List of completion results.</returns>
602+
public IEnumerable<CompletionResult> CompleteArgument(
603+
string commandName,
604+
string parameterName,
605+
string wordToComplete,
606+
CommandAst commandAst,
607+
IDictionary fakeBoundParameters)
608+
=> CompletionCompleters.GetMatchingResults(wordToComplete, possibleCompletionValues: Utils.AllowedEditionValues);
608609
}
609610
}

test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1

+9-6
Original file line numberDiff line numberDiff line change
@@ -2653,15 +2653,18 @@ dir -Recurse `
26532653
Context "Module cmdlet completion tests" {
26542654
It "ArugmentCompleter for PSEdition should work for '<cmd>'" -TestCases @(
26552655
@{cmd = "Get-Module -PSEdition "; expected = "Desktop", "Core"}
2656+
@{cmd = "Get-Module -PSEdition '"; expected = "'Desktop'", "'Core'"}
2657+
@{cmd = "Get-Module -PSEdition """; expected = """Desktop""", """Core"""}
2658+
@{cmd = "Get-Module -PSEdition 'Desk"; expected = "'Desktop'"}
2659+
@{cmd = "Get-Module -PSEdition ""Desk"; expected = """Desktop"""}
2660+
@{cmd = "Get-Module -PSEdition Co"; expected = "Core"}
2661+
@{cmd = "Get-Module -PSEdition 'Co"; expected = "'Core'"}
2662+
@{cmd = "Get-Module -PSEdition ""Co"; expected = """Core"""}
26562663
) {
26572664
param($cmd, $expected)
26582665
$res = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length
2659-
$res.CompletionMatches | Should -HaveCount $expected.Count
2660-
$completionOptions = ""
2661-
foreach ($completion in $res.CompletionMatches) {
2662-
$completionOptions += $completion.ListItemText
2663-
}
2664-
$completionOptions | Should -BeExactly ([string]::Join("", $expected))
2666+
$completionText = $res.CompletionMatches.CompletionText
2667+
$completionText -join ' ' | Should -BeExactly ($expected -join ' ')
26652668
}
26662669
}
26672670

0 commit comments

Comments
 (0)