From 39be7109d4afc50c9f92f0fde46d2f4199bf6a23 Mon Sep 17 00:00:00 2001 From: Ilya Date: Wed, 29 Mar 2017 21:36:18 +0400 Subject: [PATCH] Add tab completion for Select-Object -ExcludeProperty -ExpandProperty (#3443) --- .../CommandCompletion/CompletionCompleters.cs | 11 ++++++++++- .../Host/TabCompletion/BugFix.Tests.ps1 | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index a9f6b9edc1..f7eb2ea69f 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -2249,7 +2249,6 @@ namespace System.Management.Automation } case "Group-Object": case "Measure-Object": - case "Select-Object": case "Sort-Object": case "Where-Object": case "Format-Custom": @@ -2263,6 +2262,16 @@ namespace System.Management.Automation } 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 38feaceb4b..d97d4a3668 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 + } + } }