Fix completion of variables assigned inside Do loops (#25076)

This commit is contained in:
MartinGC94
2025-02-26 17:04:36 +05:00
committed by GitHub
parent 33d4bf5228
commit c64a636d9b
2 changed files with 23 additions and 3 deletions
@@ -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)