@@ -48,12 +48,12 @@ internal interface IRenameService
48
48
internal class RenameService (
49
49
WorkspaceService workspaceService ,
50
50
ILanguageServerFacade lsp ,
51
- ILanguageServerConfiguration config ,
52
- bool disclaimerDeclinedForSession = false ,
53
- bool disclaimerAcceptedForSession = false ,
54
- string configSection = "powershell.rename"
51
+ ILanguageServerConfiguration config
55
52
) : IRenameService
56
53
{
54
+ internal bool DisclaimerAcceptedForSession ; //This is exposed to allow testing non-interactively
55
+ private bool DisclaimerDeclinedForSession ;
56
+ private const string ConfigSection = "powershell.rename" ;
57
57
58
58
public async Task < RangeOrPlaceholderRange ? > PrepareRenameSymbol ( PrepareRenameParams request , CancellationToken cancellationToken )
59
59
{
@@ -211,8 +211,10 @@ internal static ScriptExtentAdapter GetFunctionNameExtent(FunctionDefinitionAst
211
211
/// <returns>true if accepted, false if rejected</returns>
212
212
private async Task < bool > AcceptRenameDisclaimer ( bool acceptDisclaimerOption , CancellationToken cancellationToken )
213
213
{
214
- if ( disclaimerDeclinedForSession ) { return false ; }
215
- if ( acceptDisclaimerOption || disclaimerAcceptedForSession ) { return true ; }
214
+ const string disclaimerDeclinedMessage = "PowerShell rename has been disabled for this session as the disclaimer message was declined. Please restart the extension if you wish to use rename and accept the disclaimer." ;
215
+
216
+ if ( DisclaimerDeclinedForSession ) { throw new HandlerErrorException ( disclaimerDeclinedMessage ) ; }
217
+ if ( acceptDisclaimerOption || DisclaimerAcceptedForSession ) { return true ; }
216
218
217
219
// TODO: Localization
218
220
const string renameDisclaimer = "PowerShell rename functionality is only supported in a limited set of circumstances. [Please review the notice](https://github.com/PowerShell/PowerShellEditorServices?tab=readme-ov-file#rename-disclaimer) and accept the limitations and risks." ;
@@ -235,8 +237,9 @@ private async Task<bool> AcceptRenameDisclaimer(bool acceptDisclaimerOption, Can
235
237
}
236
238
} ;
237
239
238
- MessageActionItem result = await lsp . SendRequest ( reqParams , cancellationToken ) . ConfigureAwait ( false ) ;
239
- if ( result . Title == declineAnswer )
240
+ MessageActionItem ? result = await lsp . SendRequest ( reqParams , cancellationToken ) . ConfigureAwait ( false ) ;
241
+ // null happens if the user closes the dialog rather than making a selection.
242
+ if ( result is null || result . Title == declineAnswer )
240
243
{
241
244
const string renameDisabledNotice = "PowerShell Rename functionality will be disabled for this session and you will not be prompted again until restart." ;
242
245
@@ -246,8 +249,8 @@ private async Task<bool> AcceptRenameDisclaimer(bool acceptDisclaimerOption, Can
246
249
Type = MessageType . Info
247
250
} ;
248
251
lsp . SendNotification ( msgParams ) ;
249
- disclaimerDeclinedForSession = true ;
250
- return ! disclaimerDeclinedForSession ;
252
+ DisclaimerDeclinedForSession = true ;
253
+ throw new HandlerErrorException ( disclaimerDeclinedMessage ) ;
251
254
}
252
255
if ( result . Title == acceptAnswer )
253
256
{
@@ -259,8 +262,8 @@ private async Task<bool> AcceptRenameDisclaimer(bool acceptDisclaimerOption, Can
259
262
} ;
260
263
lsp . SendNotification ( msgParams ) ;
261
264
262
- disclaimerAcceptedForSession = true ;
263
- return disclaimerAcceptedForSession ;
265
+ DisclaimerAcceptedForSession = true ;
266
+ return DisclaimerAcceptedForSession ;
264
267
}
265
268
// if (result.Title == acceptWorkspaceAnswer)
266
269
// {
@@ -279,7 +282,7 @@ private async Task<bool> AcceptRenameDisclaimer(bool acceptDisclaimerOption, Can
279
282
private async Task < RenameServiceOptions > GetScopedSettings ( DocumentUri uri , CancellationToken cancellationToken = default )
280
283
{
281
284
IScopedConfiguration scopedConfig = await config . GetScopedConfiguration ( uri , cancellationToken ) . ConfigureAwait ( false ) ;
282
- return scopedConfig . GetSection ( configSection ) . Get < RenameServiceOptions > ( ) ?? new RenameServiceOptions ( ) ;
285
+ return scopedConfig . GetSection ( ConfigSection ) . Get < RenameServiceOptions > ( ) ?? new RenameServiceOptions ( ) ;
283
286
}
284
287
}
285
288
0 commit comments