@@ -48,12 +48,12 @@ internal interface IRenameService
4848internal class RenameService (
4949 WorkspaceService workspaceService ,
5050 ILanguageServerFacade lsp ,
51- ILanguageServerConfiguration config ,
52- bool disclaimerDeclinedForSession = false ,
53- bool disclaimerAcceptedForSession = false ,
54- string configSection = "powershell.rename"
51+ ILanguageServerConfiguration config
5552) : IRenameService
5653{
54+ internal bool DisclaimerAcceptedForSession ; //This is exposed to allow testing non-interactively
55+ private bool DisclaimerDeclinedForSession ;
56+ private const string ConfigSection = "powershell.rename" ;
5757
5858 public async Task < RangeOrPlaceholderRange ? > PrepareRenameSymbol ( PrepareRenameParams request , CancellationToken cancellationToken )
5959 {
@@ -211,8 +211,10 @@ internal static ScriptExtentAdapter GetFunctionNameExtent(FunctionDefinitionAst
211211 /// <returns>true if accepted, false if rejected</returns>
212212 private async Task < bool > AcceptRenameDisclaimer ( bool acceptDisclaimerOption , CancellationToken cancellationToken )
213213 {
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 ; }
216218
217219 // TODO: Localization
218220 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
235237 }
236238 } ;
237239
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 )
240243 {
241244 const string renameDisabledNotice = "PowerShell Rename functionality will be disabled for this session and you will not be prompted again until restart." ;
242245
@@ -246,8 +249,8 @@ private async Task<bool> AcceptRenameDisclaimer(bool acceptDisclaimerOption, Can
246249 Type = MessageType . Info
247250 } ;
248251 lsp . SendNotification ( msgParams ) ;
249- disclaimerDeclinedForSession = true ;
250- return ! disclaimerDeclinedForSession ;
252+ DisclaimerDeclinedForSession = true ;
253+ throw new HandlerErrorException ( disclaimerDeclinedMessage ) ;
251254 }
252255 if ( result . Title == acceptAnswer )
253256 {
@@ -259,8 +262,8 @@ private async Task<bool> AcceptRenameDisclaimer(bool acceptDisclaimerOption, Can
259262 } ;
260263 lsp . SendNotification ( msgParams ) ;
261264
262- disclaimerAcceptedForSession = true ;
263- return disclaimerAcceptedForSession ;
265+ DisclaimerAcceptedForSession = true ;
266+ return DisclaimerAcceptedForSession ;
264267 }
265268 // if (result.Title == acceptWorkspaceAnswer)
266269 // {
@@ -279,7 +282,7 @@ private async Task<bool> AcceptRenameDisclaimer(bool acceptDisclaimerOption, Can
279282 private async Task < RenameServiceOptions > GetScopedSettings ( DocumentUri uri , CancellationToken cancellationToken = default )
280283 {
281284 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 ( ) ;
283286 }
284287}
285288
0 commit comments