Skip to content

Commit ec2ab16

Browse files
committed
Clean out some dead code
1 parent 1dc9d91 commit ec2ab16

File tree

2 files changed

+0
-100
lines changed

2 files changed

+0
-100
lines changed

src/PowerShellEditorServices/Services/TextDocument/RenameService.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,6 @@ internal static TextEdit[] RenameVariable(Ast symbol, Ast scriptAst, RenameParam
132132
throw new HandlerErrorException($"Asked to rename a variable but the target is not a viable variable type: {symbol.GetType()}. This is a bug, file an issue if you see this.");
133133
}
134134

135-
// RenameVariableVisitor visitor = new(
136-
// requestParams.NewName,
137-
// symbol.Extent.StartLineNumber,
138-
// symbol.Extent.StartColumnNumber,
139-
// scriptAst,
140-
// createParameterAlias
141-
// );
142135
NewRenameVariableVisitor visitor = new(
143136
symbol, requestParams.NewName
144137
);

src/PowerShellEditorServices/Utility/AstExtensions.cs

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -196,42 +196,6 @@ public static string GetUnqualifiedName(this VariableExpressionAst ast)
196196
? ast.VariablePath.ToString()
197197
: ast.VariablePath.ToString().Split(':').Last();
198198

199-
/// <summary>
200-
/// Finds the closest variable definition to the given reference.
201-
/// </summary>
202-
public static VariableExpressionAst? FindVariableDefinition(this Ast ast, Ast reference)
203-
{
204-
string? name = reference switch
205-
{
206-
VariableExpressionAst var => var.GetUnqualifiedName(),
207-
CommandParameterAst param => param.ParameterName,
208-
// StringConstantExpressionAst stringConstant => ,
209-
_ => null
210-
};
211-
if (name is null) { return null; }
212-
213-
return ast.FindAll(candidate =>
214-
{
215-
if (candidate is not VariableExpressionAst candidateVar) { return false; }
216-
if (candidateVar.GetUnqualifiedName() != name) { return false; }
217-
if
218-
(
219-
// TODO: Replace with a position match
220-
candidateVar.Extent.EndLineNumber > reference.Extent.StartLineNumber
221-
||
222-
(
223-
candidateVar.Extent.EndLineNumber == reference.Extent.StartLineNumber
224-
&& candidateVar.Extent.EndColumnNumber >= reference.Extent.StartColumnNumber
225-
)
226-
)
227-
{
228-
return false;
229-
}
230-
231-
return candidateVar.HasParent(reference.Parent);
232-
}, true).Cast<VariableExpressionAst>().LastOrDefault();
233-
}
234-
235199
public static Ast GetHighestParent(this Ast ast)
236200
=> ast.Parent is null ? ast : ast.Parent.GetHighestParent();
237201

@@ -405,7 +369,6 @@ public static bool TryGetFunction(this ParameterAst ast, out FunctionDefinitionA
405369
return false;
406370
}
407371

408-
409372
/// <summary>
410373
/// Finds the highest variable expression within a variable assignment within the current scope of the provided variable reference. Returns the original object if it is the highest assignment or null if no assignment was found. It is assumed the reference is part of a larger Ast.
411374
/// </summary>
@@ -546,62 +509,6 @@ public static bool TryGetFunction(this ParameterAst ast, out FunctionDefinitionA
546509
return null;
547510
}
548511

549-
public static bool WithinScope(this Ast Target, Ast Child)
550-
{
551-
Ast childParent = Child.Parent;
552-
Ast? TargetScope = Target.GetScopeBoundary();
553-
while (childParent != null)
554-
{
555-
if (childParent is FunctionDefinitionAst FuncDefAst)
556-
{
557-
if (Child is VariableExpressionAst VarExpAst && !IsVariableExpressionAssignedInTargetScope(VarExpAst, FuncDefAst))
558-
{
559-
560-
}
561-
else
562-
{
563-
break;
564-
}
565-
}
566-
if (childParent == TargetScope)
567-
{
568-
break;
569-
}
570-
childParent = childParent.Parent;
571-
}
572-
return childParent == TargetScope;
573-
}
574-
575-
public static bool IsVariableExpressionAssignedInTargetScope(this VariableExpressionAst node, Ast scope)
576-
{
577-
bool r = false;
578-
579-
List<VariableExpressionAst> VariableAssignments = node.FindAll(ast =>
580-
{
581-
return ast is VariableExpressionAst VarDef &&
582-
VarDef.Parent is AssignmentStatementAst or ParameterAst &&
583-
VarDef.VariablePath.UserPath.ToLower() == node.VariablePath.UserPath.ToLower() &&
584-
// Look Backwards from the node above
585-
(VarDef.Extent.EndLineNumber < node.Extent.StartLineNumber ||
586-
(VarDef.Extent.EndColumnNumber <= node.Extent.StartColumnNumber &&
587-
VarDef.Extent.EndLineNumber <= node.Extent.StartLineNumber)) &&
588-
// Must be within the the designated scope
589-
VarDef.Extent.StartLineNumber >= scope.Extent.StartLineNumber;
590-
}, true).Cast<VariableExpressionAst>().ToList();
591-
592-
if (VariableAssignments.Count > 0)
593-
{
594-
r = true;
595-
}
596-
// Node is probably the first Assignment Statement within scope
597-
if (node.Parent is AssignmentStatementAst && node.Extent.StartLineNumber >= scope.Extent.StartLineNumber)
598-
{
599-
r = true;
600-
}
601-
602-
return r;
603-
}
604-
605512
public static bool HasParent(this Ast ast, Ast parent)
606513
{
607514
Ast? current = ast;

0 commit comments

Comments
 (0)