Skip to content

Commit 950b3e5

Browse files
Razmo99JustinGrote
authored andcommitted
case insensitive compare & adjustment for get ast parent scope to favour functions
1 parent 3419910 commit 950b3e5

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/PowerShellEditorServices/Services/PowerShell/Refactoring/VariableVisitor.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ internal static Ast GetAstParentScope(Ast node)
162162
}
163163
parent = parent.Parent;
164164
}
165-
if (parent is ScriptBlockAst && parent.Parent != null)
165+
if (parent is ScriptBlockAst && parent.Parent != null && parent.Parent is FunctionDefinitionAst)
166166
{
167-
parent = GetAstParentScope(parent.Parent);
167+
parent = parent.Parent;
168168
}
169169
return parent;
170170
}
@@ -252,7 +252,7 @@ public object VisitCommandExpression(CommandExpressionAst commandExpressionAst)
252252
public object VisitCommandParameter(CommandParameterAst commandParameterAst)
253253
{
254254
// TODO implement command parameter renaming
255-
if (commandParameterAst.ParameterName == OldName)
255+
if (commandParameterAst.ParameterName.ToLower() == OldName.ToLower())
256256
{
257257
if (commandParameterAst.Extent.StartLineNumber == StartLineNumber &&
258258
commandParameterAst.Extent.StartColumnNumber == StartColumnNumber)
@@ -429,6 +429,7 @@ public object VisitScriptBlock(ScriptBlockAst scriptBlockAst)
429429
{
430430
ScopeStack.Push(scriptBlockAst);
431431

432+
scriptBlockAst.ParamBlock?.Visit(this);
432433
scriptBlockAst.BeginBlock?.Visit(this);
433434
scriptBlockAst.ProcessBlock?.Visit(this);
434435
scriptBlockAst.EndBlock?.Visit(this);
@@ -493,15 +494,15 @@ public object VisitSubExpression(SubExpressionAst subExpressionAst)
493494
public object VisitThrowStatement(ThrowStatementAst throwStatementAst) => throw new NotImplementedException();
494495
public object VisitTrap(TrapStatementAst trapStatementAst) => throw new NotImplementedException();
495496
public object VisitTryStatement(TryStatementAst tryStatementAst) => throw new NotImplementedException();
496-
public object VisitTypeConstraint(TypeConstraintAst typeConstraintAst) => throw new NotImplementedException();
497+
public object VisitTypeConstraint(TypeConstraintAst typeConstraintAst) => null;
497498
public object VisitTypeDefinition(TypeDefinitionAst typeDefinitionAst) => throw new NotImplementedException();
498499
public object VisitTypeExpression(TypeExpressionAst typeExpressionAst) => throw new NotImplementedException();
499500
public object VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) => throw new NotImplementedException();
500501
public object VisitUsingExpression(UsingExpressionAst usingExpressionAst) => throw new NotImplementedException();
501502
public object VisitUsingStatement(UsingStatementAst usingStatement) => throw new NotImplementedException();
502503
public object VisitVariableExpression(VariableExpressionAst variableExpressionAst)
503504
{
504-
if (variableExpressionAst.VariablePath.UserPath == OldName)
505+
if (variableExpressionAst.VariablePath.UserPath.ToLower() == OldName.ToLower())
505506
{
506507
if (variableExpressionAst.Extent.StartColumnNumber == StartColumnNumber &&
507508
variableExpressionAst.Extent.StartLineNumber == StartLineNumber)

0 commit comments

Comments
 (0)