diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index a9f6b9edc1a..f7eb2ea69f5 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -2249,7 +2249,6 @@ private static void NativeCommandArgumentCompletion( } case "Group-Object": case "Measure-Object": - case "Select-Object": case "Sort-Object": case "Where-Object": case "Format-Custom": @@ -2263,6 +2262,16 @@ private static void NativeCommandArgumentCompletion( } break; } + case "Select-Object": + { + if (parameterName.Equals("Property", StringComparison.OrdinalIgnoreCase) + || parameterName.Equals("ExcludeProperty", StringComparison.OrdinalIgnoreCase) + || parameterName.Equals("ExpandProperty", StringComparison.OrdinalIgnoreCase)) + { + NativeCompletionMemberName(context.WordToComplete, result, commandAst, context); + } + break; + } case "New-Object": { diff --git a/test/powershell/Host/TabCompletion/BugFix.Tests.ps1 b/test/powershell/Host/TabCompletion/BugFix.Tests.ps1 index 38feaceb4b8..d97d4a36688 100644 --- a/test/powershell/Host/TabCompletion/BugFix.Tests.ps1 +++ b/test/powershell/Host/TabCompletion/BugFix.Tests.ps1 @@ -35,4 +35,23 @@ Describe "Tab completion bug fix" -Tags "CI" { $result.CompletionMatches[1].CompletionText | Should Be "-NoClobber" $result.CompletionMatches[2].CompletionText | Should Be "-NoOverwrite" } + Context "Issue#3416 - 'Select-Object'" { + BeforeAll { + $DatetimeProperties = @((Get-Date).psobject.baseobject.psobject.properties) | Sort-Object -Property Name + } + It "Issue#3416 - 'Select-Object -ExcludeProperty ' should work" { + $cmd = "Get-Date | Select-Object -ExcludeProperty " + $result = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length + $result.CompletionMatches.Count | Should Be $DatetimeProperties.Count + $result.CompletionMatches[0].CompletionText | Should Be $DatetimeProperties[0].Name # Date + $result.CompletionMatches[1].CompletionText | Should Be $DatetimeProperties[1].Name # DateTime + } + It "Issue#3416 - 'Select-Object -ExpandProperty ' should work" { + $cmd = "Get-Date | Select-Object -ExpandProperty " + $result = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length + $result.CompletionMatches.Count | Should Be $DatetimeProperties.Count + $result.CompletionMatches[0].CompletionText | Should Be $DatetimeProperties[0].Name # Date + $result.CompletionMatches[1].CompletionText | Should Be $DatetimeProperties[1].Name # DateTime + } + } }