diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs index 32057fce1c4..759b60ea0c1 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs @@ -442,6 +442,12 @@ internal List GetResultHelper(CompletionContext completionCont result = GetResultForEnumPropertyValueOfDSCResource(completionContext, string.Empty, ref replacementIndex, ref replacementLength, out unused); } break; + case TokenKind.AtCurly: + // Handle scenarios such as 'Sort-Object @{' and 'gci | Format-Table @{' + result = GetResultForHashtable(completionContext); + replacementIndex += 2; + replacementLength = 0; + break; case TokenKind.Number: // Handle scenarios such as Get-Process -Id 5 || Get-Process -Id 5210, 3 || Get-Process -Id: 5210, 3 diff --git a/test/powershell/Host/TabCompletion/BugFix.Tests.ps1 b/test/powershell/Host/TabCompletion/BugFix.Tests.ps1 index d97d4a36688..291dc1165c7 100644 --- a/test/powershell/Host/TabCompletion/BugFix.Tests.ps1 +++ b/test/powershell/Host/TabCompletion/BugFix.Tests.ps1 @@ -54,4 +54,13 @@ Describe "Tab completion bug fix" -Tags "CI" { $result.CompletionMatches[1].CompletionText | Should Be $DatetimeProperties[1].Name # DateTime } } + + It "Issue#3628 - 'Sort-Object @{' should work" { + $cmd = "Get-Date | Sort-Object @{" + $result = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length + $result.CompletionMatches.Count | Should Be 3 + $result.CompletionMatches[0].CompletionText | Should Be 'Expression' + $result.CompletionMatches[1].CompletionText | Should Be 'Ascending' + $result.CompletionMatches[2].CompletionText | Should Be 'Descending' + } }