8
8
using System . Management . Automation . Language ;
9
9
using OmniSharp . Extensions . JsonRpc ;
10
10
using Microsoft . PowerShell . EditorServices . Services ;
11
- using Microsoft . Extensions . Logging ;
12
11
using Microsoft . PowerShell . EditorServices . Services . TextDocument ;
13
12
using Microsoft . PowerShell . EditorServices . Refactoring ;
13
+ using System ;
14
14
namespace Microsoft . PowerShell . EditorServices . Handlers
15
15
{
16
16
[ Serial , Method ( "powerShell/renameSymbol" ) ]
17
17
internal interface IRenameSymbolHandler : IJsonRpcRequestHandler < RenameSymbolParams , RenameSymbolResult > { }
18
18
19
- public class RenameSymbolOptions {
19
+ public class RenameSymbolOptions
20
+ {
20
21
public bool CreateAlias { get ; set ; }
21
22
}
22
23
@@ -68,14 +69,10 @@ public class RenameSymbolResult
68
69
69
70
internal class RenameSymbolHandler : IRenameSymbolHandler
70
71
{
71
- private readonly ILogger _logger ;
72
72
private readonly WorkspaceService _workspaceService ;
73
73
74
- public RenameSymbolHandler ( ILoggerFactory loggerFactory , WorkspaceService workspaceService )
75
- {
76
- _logger = loggerFactory . CreateLogger < RenameSymbolHandler > ( ) ;
77
- _workspaceService = workspaceService ;
78
- }
74
+ public RenameSymbolHandler ( WorkspaceService workspaceService ) => _workspaceService = workspaceService ;
75
+
79
76
internal static ModifiedFileResponse RenameFunction ( Ast token , Ast scriptAst , RenameSymbolParams request )
80
77
{
81
78
string tokenName = "" ;
@@ -98,20 +95,20 @@ internal static ModifiedFileResponse RenameFunction(Ast token, Ast scriptAst, Re
98
95
Changes = visitor . Modifications
99
96
} ;
100
97
return FileModifications ;
101
-
102
-
103
-
104
98
}
99
+
105
100
internal static ModifiedFileResponse RenameVariable ( Ast symbol , Ast scriptAst , RenameSymbolParams request )
106
101
{
107
102
if ( symbol is VariableExpressionAst or ParameterAst or CommandParameterAst or StringConstantExpressionAst )
108
103
{
109
104
110
- IterativeVariableRename visitor = new ( request . RenameTo ,
111
- symbol . Extent . StartLineNumber ,
112
- symbol . Extent . StartColumnNumber ,
113
- scriptAst ,
114
- request . Options ?? null ) ;
105
+ IterativeVariableRename visitor = new (
106
+ request . RenameTo ,
107
+ symbol . Extent . StartLineNumber ,
108
+ symbol . Extent . StartColumnNumber ,
109
+ scriptAst ,
110
+ request . Options ?? null
111
+ ) ;
115
112
visitor . Visit ( scriptAst ) ;
116
113
ModifiedFileResponse FileModifications = new ( request . FileName )
117
114
{
@@ -121,21 +118,18 @@ internal static ModifiedFileResponse RenameVariable(Ast symbol, Ast scriptAst, R
121
118
122
119
}
123
120
return null ;
124
-
125
121
}
122
+
126
123
public async Task < RenameSymbolResult > Handle ( RenameSymbolParams request , CancellationToken cancellationToken )
127
124
{
128
125
if ( ! _workspaceService . TryGetFile ( request . FileName , out ScriptFile scriptFile ) )
129
126
{
130
- _logger . LogDebug ( "Failed to open file!" ) ;
131
- return await Task . FromResult < RenameSymbolResult > ( null ) . ConfigureAwait ( false ) ;
127
+ throw new InvalidOperationException ( "This should not happen as PrepareRename should have already checked for viability. File an issue if you see this." ) ;
132
128
}
133
129
134
130
return await Task . Run ( ( ) =>
135
131
{
136
-
137
132
Ast token = Utilities . GetAst ( request . Line + 1 , request . Column + 1 , scriptFile . ScriptAst ) ;
138
-
139
133
if ( token == null ) { return null ; }
140
134
141
135
ModifiedFileResponse FileModifications = ( token is FunctionDefinitionAst || token . Parent is CommandAst )
0 commit comments