You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// walk backwards till we hit a functiondefinition if any
100
-
while(null!=parent)
85
+
if(funcDef.Name.ToLower()!=name)
101
86
{
102
-
if(parentisFunctionDefinitionAst)
103
-
{
104
-
break;
105
-
}
106
-
parent=parent.Parent;
87
+
returnfalse;
107
88
}
108
-
// we have hit the global scope of the script file
109
-
if(null==parent)
89
+
90
+
// If the function is recursive (calls itself), its parent is a match unless a more specific in-scope function definition comes next (this is a "bad practice" edge case)
returncommand.HasParent(funcDef.Parent);// The command is in the same scope as the function definition
112
+
},true).Cast<FunctionDefinitionAst>().ToArray();
113
+
114
+
// There should only be one match most of the time, the only other cases is when a function is defined multiple times (bad practice). If there are multiple definitions, the candidate "closest" to the command, which would be the last one found, is the appropriate one
??thrownewTargetSymbolNotFoundException("The command to rename does not have a function definition. Renaming a function is only supported when the function is defined within the same scope"),
231
231
_ =>thrownewException($"Unsupported AST type {target.GetType()} encountered")
232
232
};
233
-
234
-
OldName=functionDef.Name;
235
233
};
236
234
237
235
if(CurrentDocument!=ast.GetHighestParent())
@@ -241,7 +239,7 @@ public AstVisitAction Visit(Ast ast)
241
239
242
240
if(ShouldRename(ast))
243
241
{
244
-
Edits.Add(GetRenameFunctionEdits(ast));
242
+
Edits.Add(GetRenameFunctionEdit(ast));
245
243
returnAstVisitAction.Continue;
246
244
}
247
245
else
@@ -254,10 +252,10 @@ public AstVisitAction Visit(Ast ast)
254
252
255
253
privateboolShouldRename(Astcandidate)
256
254
{
257
-
// There should be only one function definition and if it is not our target, it may be a duplicately named function
255
+
// Rename our original function definition. There may be duplicate definitions of the same name
258
256
if(candidateisFunctionDefinitionAstfuncDef)
259
257
{
260
-
returnfuncDef==target;
258
+
returnfuncDef==FunctionToRename;
261
259
}
262
260
263
261
// Should only be CommandAst (function calls) from this point forward in the visit.
thrownewInvalidOperationException($"ShouldRename for a function had an Unexpected Ast Type {candidate.GetType()}. This is a bug and you should file an issue.");
thrownewInvalidOperationException("CurrentDoc should always be set by now from first Visit. This is a bug and you should file an issue.");
285
270
}
286
271
287
-
// If the command is defined in the same parent scope as the function
288
-
returncommand.HasParent(target.Parent);
289
-
290
-
// If we get this far, we hit an edge case
291
-
thrownewInvalidOperationException("ShouldRename for a function could not determine the viability of a rename. This is a bug and you should file an issue.");
272
+
// Match up the command to its function definition
if(command.CommandElements[0]is not StringConstantExpressionAstfuncName)
320
301
{
321
-
if(command.CommandElements[0]is not StringConstantExpressionAstfuncName)
322
-
{
323
-
thrownewInvalidOperationException("Command element should always have a string expresssion as its first item. This is a bug and you should report it.");
324
-
}
325
-
326
-
returnnewTextEdit()
327
-
{
328
-
NewText=newName,
329
-
Range=newScriptExtentAdapter(funcName.Extent)
330
-
};
302
+
thrownewInvalidOperationException("Command element should always have a string expresssion as its first item. This is a bug and you should report it.");
331
303
}
332
304
333
-
thrownewInvalidOperationException("GetRenameFunctionEdit was not provided a FuncitonDefinition or a CommandAst");
0 commit comments