Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1983,8 +1983,19 @@ private void InferTypeFrom(VariableExpressionAst variableExpressionAst, List<PST
{
if (switchErrorStatement.Conditions?.Count > 0)
{
parent = switchErrorStatement.Conditions[0];
if (switchErrorStatement.Conditions[0].Extent.EndOffset < variableExpressionAst.Extent.StartOffset)
{
parent = switchErrorStatement.Conditions[0];
break;
}
else
{
// $_ is inside the condition that is being declared, eg: Get-Process | Sort-Object -Property {switch ($_.Proc<Tab>
parent = switchErrorStatement.Parent;
continue;
}
}

break;
}
else if (parent is ScriptBlockExpressionAst)
Expand Down
5 changes: 5 additions & 0 deletions test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1860,6 +1860,11 @@ class InheritedClassTest : System.Attribute
$res.CompletionMatches[0].CompletionText | Should -BeExactly 'Black' # 0 = NonPositive
}

It 'Tab completion of $_ inside incomplete switch condition' {
$res = TabExpansion2 -inputScript 'Get-PSDrive | Sort-Object -Property {switch ($_.nam'
$res.CompletionMatches[0].CompletionText | Should -Be 'Name'
}

It "Test [CommandCompletion]::GetNextResult" {
$inputStr = "Get-Command -Type Alias,c"
$res = TabExpansion2 -inputScript $inputStr -cursorColumn $inputStr.Length
Expand Down