mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Fix tab completions for a hash table (#6839)
Now working:
- Get-Date | Sort-Object @{Expression=<tab>
- Get-Date | Sort-Object @{Expression=...;<tab>
This commit is contained in:
@@ -473,6 +473,16 @@ namespace System.Management.Automation
|
||||
replacementLength = 0;
|
||||
break;
|
||||
|
||||
case TokenKind.Semi:
|
||||
// Handle scenarios such as 'gci | Format-Table @{Label=...;<tab>'
|
||||
if (lastAst is HashtableAst)
|
||||
{
|
||||
result = GetResultForHashtable(completionContext);
|
||||
replacementIndex += 1;
|
||||
replacementLength = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case TokenKind.Number:
|
||||
// Handle scenarios such as Get-Process -Id 5<tab> || Get-Process -Id 5210, 3<tab> || Get-Process -Id: 5210, 3<tab>
|
||||
if (lastAst is ConstantExpressionAst &&
|
||||
@@ -537,10 +547,15 @@ namespace System.Management.Automation
|
||||
completionContext.ReplacementLength = replacementLength = 0;
|
||||
result = GetResultForAttributeArgument(completionContext, ref replacementIndex, ref replacementLength);
|
||||
}
|
||||
else if (lastAst is HashtableAst hashTableAst && !(lastAst.Parent is DynamicKeywordStatementAst) && CheckForPendingAssignment(hashTableAst))
|
||||
{
|
||||
// Handle scenarios such as 'gci | Format-Table @{Label=<tab>' if incomplete parsing of the assignment.
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Handle auto completion for enum/dependson property of DSC resource,
|
||||
// Handle scenarios such as 'configuration foo { File ab { Attributes ='
|
||||
// (auto completion for enum/dependson property of DSC resource),
|
||||
// cursor is right after '=', '(' or '@('
|
||||
//
|
||||
// Configuration config
|
||||
@@ -552,8 +567,7 @@ namespace System.Management.Automation
|
||||
// DependsOn=(|
|
||||
//
|
||||
bool unused;
|
||||
result = GetResultForEnumPropertyValueOfDSCResource(completionContext, string.Empty,
|
||||
ref replacementIndex, ref replacementLength, out unused);
|
||||
result = GetResultForEnumPropertyValueOfDSCResource(completionContext, string.Empty, ref replacementIndex, ref replacementLength, out unused);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -65,4 +65,21 @@ Describe "Tab completion bug fix" -Tags "CI" {
|
||||
$result.CompletionMatches[1].CompletionText | Should -Be 'Ascending'
|
||||
$result.CompletionMatches[2].CompletionText | Should -Be 'Descending'
|
||||
}
|
||||
|
||||
It "'Get-Date | Sort-Object @{Expression=<tab>' should work without completion" {
|
||||
$cmd = "Get-Date | Sort-Object @{Expression="
|
||||
$result = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length
|
||||
$result.CompletionMatches.Count | Should -Be 0
|
||||
}
|
||||
|
||||
It "Issue#5322 - 'Get-Date | Sort-Object @{Expression=...;' should work" {
|
||||
$cmd = "Get-Date | Sort-Object @{Expression=...;"
|
||||
$result = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length
|
||||
$result.CurrentMatchIndex | Should -Be -1
|
||||
$result.ReplacementIndex | Should -Be 40
|
||||
$result.ReplacementLength | Should -Be 0
|
||||
$result.CompletionMatches[0].CompletionText | Should -Be 'Expression'
|
||||
$result.CompletionMatches[1].CompletionText | Should -Be 'Ascending'
|
||||
$result.CompletionMatches[2].CompletionText | Should -Be 'Descending'
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user