Exclude redundant parameter aliases from completion results (#19382)

This commit is contained in:
MartinGC94 authored and GitHub committed 2023-03-22 08:58:15 +05:00
1 parent 190c99a416
commit 18f0c5ad4b
3 files changed
+44 -20

No files matched your search

@@ -719,13 +719,21 @@ namespace System.Management.Automation
string tooltip = parameterType + matchedParameterName;
result.Add(new CompletionResult(completionText, matchedParameterName, CompletionResultType.ParameterName, tooltip));
}
// Process alias when there is partial input
result.AddRange(from alias in param.Parameter.Aliases
where pattern.IsMatch(alias)
select
new CompletionResult("-" + alias + colonSuffix, alias, CompletionResultType.ParameterName,
parameterType + alias));
else
{
// Process alias when there is partial input
foreach (var alias in param.Parameter.Aliases)
{
if (pattern.IsMatch(alias))
{
result.Add(new CompletionResult(
$"-{alias}{colonSuffix}",
alias,
CompletionResultType.ParameterName,
parameterType + alias));
}
}
}
return result;
}
@@ -791,15 +799,20 @@ namespace System.Management.Automation
tooltip));
}
}
if (parameterName != string.Empty)
else if (parameterName != string.Empty)
{
// Process alias when there is partial input
listInUse.AddRange(from alias in param.Parameter.Aliases
where pattern.IsMatch(alias)
select
new CompletionResult("-" + alias + colonSuffix, alias, CompletionResultType.ParameterName,
type + alias));
foreach (var alias in param.Parameter.Aliases)
{
if (pattern.IsMatch(alias))
{
listInUse.Add(new CompletionResult(
$"-{alias}{colonSuffix}",
alias,
CompletionResultType.ParameterName,
type + alias));
}
}
}
}
@@ -28,10 +28,9 @@ Describe "Tab completion bug fix" -Tags "CI" {
It "Issue#1345 - 'Import-Module -n<tab>' should work" {
$cmd = "Import-Module -n"
$result = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length
$result.CompletionMatches | Should -HaveCount 3
$result.CompletionMatches | Should -HaveCount 2
$result.CompletionMatches[0].CompletionText | Should -BeExactly "-Name"
$result.CompletionMatches[1].CompletionText | Should -BeExactly "-NoClobber"
$result.CompletionMatches[2].CompletionText | Should -BeExactly "-NoOverwrite"
}
It "Issue#11227 - [CompletionCompleters]::CompleteVariable and [CompletionCompleters]::CompleteType should work" {
@@ -871,6 +871,18 @@ class InheritedClassTest : System.Attribute
$res.CompletionMatches.CompletionText | Should -Contain 'TypeId'
}
it 'Should not complete parameter aliases if the real parameter is in the completion results' {
$res = TabExpansion2 -inputScript 'Get-ChildItem -p'
$res.CompletionMatches.CompletionText | Should -Not -Contain '-proga'
$res.CompletionMatches.CompletionText | Should -Contain '-ProgressAction'
}
it 'Should not complete parameter aliases if the real parameter is in the completion results (Non ambiguous parameters)' {
$res = TabExpansion2 -inputScript 'Get-ChildItem -prog'
$res.CompletionMatches.CompletionText | Should -Not -Contain '-proga'
$res.CompletionMatches.CompletionText | Should -Contain '-ProgressAction'
}
Context "Script name completion" {
BeforeAll {
Setup -f 'install-powershell.ps1' -Content ""
@@ -1646,15 +1658,15 @@ dir -Recurse `
It "Test completion with exact match" {
$inputStr = 'get-content -wa'
$res = TabExpansion2 -inputScript $inputStr -cursorColumn $inputStr.Length
$res.CompletionMatches | Should -HaveCount 4
[string]::Join(',', ($res.CompletionMatches.completiontext | Sort-Object)) | Should -BeExactly "-wa,-Wait,-WarningAction,-WarningVariable"
$res.CompletionMatches | Should -HaveCount 3
[string]::Join(',', ($res.CompletionMatches.completiontext | Sort-Object)) | Should -BeExactly "-Wait,-WarningAction,-WarningVariable"
}
It "Test completion with splatted variable" {
$inputStr = 'Get-Content @Splat -P'
$res = TabExpansion2 -inputScript $inputStr -cursorColumn $inputStr.Length
$res.CompletionMatches | Should -HaveCount 6
[string]::Join(',', ($res.CompletionMatches.completiontext | Sort-Object)) | Should -BeExactly "-Path,-PipelineVariable,-proga,-ProgressAction,-PSPath,-pv"
$res.CompletionMatches | Should -HaveCount 4
[string]::Join(',', ($res.CompletionMatches.completiontext | Sort-Object)) | Should -BeExactly "-Path,-PipelineVariable,-ProgressAction,-PSPath"
}
It "Test completion for HttpVersion parameter name" {