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
if(targetis not FunctionDefinitionAst or CommandAst)
122
115
{
123
-
tokenName=CommAst.GetCommandName();
116
+
thrownewHandlerErrorException($"Asked to rename a function but the target is not a viable function type: {target.GetType()}. This should not happen as PrepareRename should have already checked for viability. File an issue if you see this.");
??thrownewTargetSymbolNotFoundException("The command to rename does not have a function definition.");
227
+
}
228
+
}
229
+
if(CurrentDocument!=ast)
230
+
{
231
+
thrownewTargetSymbolNotFoundException("The visitor should not be reused to rename a different document. It should be created new for each rename operation. This is a bug and you should file an issue");
232
+
}
233
+
234
+
if(ShouldRename(ast))
235
+
{
236
+
Edits.Add(GetRenameFunctionEdit(ast));
237
+
returnAstVisitAction.Continue;
238
+
}
239
+
else
240
+
{
241
+
returnAstVisitAction.SkipChildren;
242
+
}
243
+
244
+
/// TODO: Is there a way we can know we are fully outside where the function might be referenced, and if so, call a AstVisitAction Abort as a perf optimization?
245
+
}
246
+
247
+
publicboolShouldRename(Astcandidate)
248
+
{
249
+
// There should be only one function definition and if it is not our target, it may be a duplicately named function
250
+
if(candidateisFunctionDefinitionAstfuncDef)
251
+
{
252
+
returnfuncDef==target;
253
+
}
254
+
255
+
if(candidateis not CommandAst)
256
+
{
257
+
thrownewInvalidOperationException($"ShouldRename for a function had an Unexpected Ast Type {candidate.GetType()}. This is a bug and you should file an issue.");
258
+
}
259
+
260
+
// Determine if calls of the function are in the same scope as the function definition
thrownewInvalidOperationException("ShouldRename for a function could not determine the viability of a rename. This is a bug and you should file an issue.");
if(command.CommandElements[0]is not StringConstantExpressionAstfuncName)
302
+
{
303
+
thrownewInvalidOperationException("Command element should always have a string expresssion as its first item. This is a bug and you should report it.");
304
+
}
305
+
306
+
returnnewTextEdit()
307
+
{
308
+
NewText=newName,
309
+
Range=newScriptExtentAdapter(funcName.Extent)
310
+
};
311
+
}
312
+
313
+
thrownewInvalidOperationException("GetRenameFunctionEdit was not provided a FuncitonDefinition or a CommandAst");
314
+
}
315
+
}
316
+
211
317
publicclassRenameSymbolOptions
212
318
{
213
319
publicboolCreateAlias{get;set;}
320
+
321
+
214
322
}
215
323
216
324
@@ -274,6 +382,55 @@ public static class AstExtensions
0 commit comments