mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Fix completion of variables assigned inside Do loops (#25076)
This commit is contained in:
@@ -5546,7 +5546,7 @@ namespace System.Management.Automation
|
||||
internal Type LastAssignedType;
|
||||
}
|
||||
|
||||
private sealed class FindVariablesVisitor : AstVisitor
|
||||
private sealed class FindVariablesVisitor : AstVisitor2
|
||||
{
|
||||
internal Ast Top;
|
||||
internal Ast CompletionVariableAst;
|
||||
@@ -5621,7 +5621,11 @@ namespace System.Management.Automation
|
||||
{
|
||||
if (ast.Extent.StartOffset > StopSearchOffset)
|
||||
{
|
||||
return AstVisitAction.StopVisit;
|
||||
// When visiting do while/until statements, the condition will be visited before the statement block.
|
||||
// The condition itself may not be interesting if it's after the cursor, but the statement block could be.
|
||||
return ast is PipelineBaseAst && ast.Parent is DoUntilStatementAst or DoWhileStatementAst
|
||||
? AstVisitAction.SkipChildren
|
||||
: AstVisitAction.StopVisit;
|
||||
}
|
||||
|
||||
return AstVisitAction.Continue;
|
||||
@@ -5631,7 +5635,9 @@ namespace System.Management.Automation
|
||||
{
|
||||
if (assignmentStatementAst.Extent.StartOffset > StopSearchOffset)
|
||||
{
|
||||
return AstVisitAction.StopVisit;
|
||||
return assignmentStatementAst.Parent is DoUntilStatementAst or DoWhileStatementAst ?
|
||||
AstVisitAction.SkipChildren
|
||||
: AstVisitAction.StopVisit;
|
||||
}
|
||||
|
||||
if (assignmentStatementAst.Left is AttributedExpressionAst attributedExpression)
|
||||
|
||||
Reference in New Issue
Block a user