mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Fix completion of the foreach-statement variable (#19814)
This commit is contained in:
@@ -5592,6 +5592,17 @@ namespace System.Management.Automation
|
||||
return AstVisitAction.Continue;
|
||||
}
|
||||
|
||||
public override AstVisitAction VisitForEachStatement(ForEachStatementAst forEachStatementAst)
|
||||
{
|
||||
if (forEachStatementAst.Extent.StartOffset > StopSearchOffset || forEachStatementAst.Variable == CompletionVariableAst)
|
||||
{
|
||||
return AstVisitAction.StopVisit;
|
||||
}
|
||||
|
||||
SaveVariableInfo(forEachStatementAst.Variable.VariablePath.UserPath, variableType: null, isConstraint: false);
|
||||
return AstVisitAction.Continue;
|
||||
}
|
||||
|
||||
public override AstVisitAction VisitAttribute(AttributeAst attributeAst)
|
||||
{
|
||||
// Attributes can't assign values to variables so they aren't interesting.
|
||||
|
||||
@@ -74,6 +74,11 @@ Describe "TabCompletion" -Tags CI {
|
||||
$res.CompletionMatches[0].CompletionText | Should -BeExactly 'pscustomobject'
|
||||
}
|
||||
|
||||
It 'Should complete foreach variable' {
|
||||
$res = TabExpansion2 -inputScript 'foreach ($CurrentItem in 1..10){$CurrentIt'
|
||||
$res.CompletionMatches[0].CompletionText | Should -BeExactly '$CurrentItem'
|
||||
}
|
||||
|
||||
foreach ($Operator in [System.Management.Automation.CompletionCompleters]::CompleteOperator(""))
|
||||
{
|
||||
It "Should complete $($Operator.CompletionText)" {
|
||||
|
||||
Reference in New Issue
Block a user