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
// Since LSP 3.16 we can simply basically return a DefaultBehavior true or null to signal to the client that the position is valid for rename and it should use its default selection criteria (which is probably the language semantic highlighting or grammar). For the current scope of the rename provider, this should be fine, but we have the option to supply the specific range in the future for special cases.
_ =>thrownewInvalidOperationException("This should not happen as PrepareRename should have already checked for viability. File an issue if you see this.")
@@ -114,24 +114,14 @@ or AssignmentStatementAst
114
114
115
115
// TODO: We can probably merge these two methods with Generic Type constraints since they are factored into overloading
if(targetis not (FunctionDefinitionAst or CommandAst))
120
-
{
121
-
thrownewHandlerErrorException($"Asked to rename a function but the target is not a viable function type: {target.GetType()}. This is a bug, file an issue if you see this.");
if(symbolis not (VariableExpressionAst or ParameterAst or CommandParameterAst or StringConstantExpressionAst))
131
-
{
132
-
thrownewHandlerErrorException($"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.");
??thrownewHandlerErrorException("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"),
312
+
??thrownewHandlerErrorException("The command to rename does not have a function definition. Renaming a function is only supported when the function is defined within an accessible scope"),
326
313
_ =>thrownewException($"Unsupported AST type {target.GetType()} encountered")
thrownewHandlerErrorException("The element to rename does not have a definition. Renaming an element is only supported when the element is defined within the same scope");
438
+
thrownewHandlerErrorException("The variable element to rename does not have a definition. Renaming an element is only supported when the variable element is defined within an accessible scope");
?thrownewException($"-{NewName} is not a valid command parameter name.")
488
+
:newTextEdit
489
+
{
490
+
NewText='-'+NewName,
491
+
Range=newScriptExtentAdapter(param.Extent)
492
+
},
482
493
_ =>thrownewInvalidOperationException($"GetRenameVariableEdit was called on an Ast that was not the target. This is a bug and you should file an issue.")
483
494
};
484
495
}
496
+
497
+
internalstaticboolIsValidVariableName(stringname)
498
+
{
499
+
// Allows us to supply $varname or varname and get a proper result
Copy file name to clipboardExpand all lines: test/PowerShellEditorServices.Test.Shared/Refactoring/RenameTestTarget.cs
+7-4Lines changed: 7 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -28,21 +28,24 @@ public class RenameTestTarget
28
28
publicstringNewName="Renamed";
29
29
30
30
publicboolShouldFail;
31
+
publicboolShouldThrow;
31
32
32
33
/// <param name="FileName">The test case file name e.g. testScript.ps1</param>
33
34
/// <param name="Line">The line where the cursor should be positioned for the rename</param>
34
35
/// <param name="Column">The column/character indent where ther cursor should be positioned for the rename</param>
35
36
/// <param name="NewName">What the target symbol represented by the line and column should be renamed to. Defaults to "Renamed" if not specified</param>
36
-
/// <param name="ShouldFail">This test case should not succeed and return either null or a handler error</param>
0 commit comments