77using Microsoft . PowerShell . EditorServices . Services . TextDocument ;
88using Microsoft . PowerShell . EditorServices . Test . Shared ;
99using OmniSharp . Extensions . LanguageServer . Protocol ;
10+ using OmniSharp . Extensions . LanguageServer . Protocol . Client . Capabilities ;
1011using OmniSharp . Extensions . LanguageServer . Protocol . Models ;
1112using static PowerShellEditorServices . Test . Refactoring . RefactorUtilities ;
1213using System . Linq ;
@@ -24,25 +25,25 @@ public class RenameHandlerTests
2425 private readonly WorkspaceService workspace = new ( NullLoggerFactory . Instance ) ;
2526
2627 private readonly RenameHandler testHandler ;
28+ private readonly PrepareRenameHandler testPrepareHandler ;
2729 public RenameHandlerTests ( )
2830 {
2931 workspace . WorkspaceFolders . Add ( new WorkspaceFolder
3032 {
3133 Uri = DocumentUri . FromFileSystemPath ( TestUtilities . GetSharedPath ( "Refactoring" ) )
3234 } ) ;
3335
34- testHandler = new
36+ RenameService renameService = new
3537 (
36- new RenameService
37- (
38- workspace ,
39- new FakeLspSendMessageRequestFacade ( "I Accept" ) ,
40- new EmptyConfiguration ( )
41- )
42- {
43- DisclaimerAcceptedForSession = true //Disables UI prompts
44- }
45- ) ;
38+ workspace ,
39+ new FakeLspSendMessageRequestFacade ( "I Accept" ) ,
40+ new EmptyConfiguration ( )
41+ )
42+ {
43+ DisclaimerAcceptedForSession = true //Disables UI prompts
44+ } ;
45+ testHandler = new ( renameService ) ;
46+ testPrepareHandler = new ( renameService ) ;
4647 }
4748
4849 // Decided to keep this DAMP instead of DRY due to memberdata boundaries, duplicates with PrepareRenameHandler
@@ -125,4 +126,50 @@ public async Task RenamedVariable(RenameTestTarget s)
125126
126127 Assert . Equal ( expected , actual ) ;
127128 }
129+
130+ [ Fact ]
131+ public void GetRegistrationOptionsDoesNotThrowWhenCapabilityIsNull ( )
132+ {
133+ // Acts: framework hands us null when client omits the capability.
134+ RenameRegistrationOptions opts = testHandler . GetRegistrationOptions (
135+ capability : null ,
136+ clientCapabilities : new ClientCapabilities ( ) ) ;
137+
138+ Assert . NotNull ( opts ) ;
139+ // Without PrepareSupport advertised, PrepareProvider should be false.
140+ Assert . False ( opts . PrepareProvider ) ;
141+ }
142+
143+ [ Fact ]
144+ public void GetRegistrationOptionsHonorsPrepareSupportWhenCapabilityProvided ( )
145+ {
146+ RenameRegistrationOptions opts = testHandler . GetRegistrationOptions (
147+ capability : new RenameCapability { PrepareSupport = true } ,
148+ clientCapabilities : new ClientCapabilities ( ) ) ;
149+
150+ Assert . NotNull ( opts ) ;
151+ Assert . True ( opts . PrepareProvider ) ;
152+ }
153+
154+ [ Fact ]
155+ public void PrepareGetRegistrationOptionsDoesNotThrowWhenCapabilityIsNull ( )
156+ {
157+ RenameRegistrationOptions opts = testPrepareHandler . GetRegistrationOptions (
158+ capability : null ,
159+ clientCapabilities : new ClientCapabilities ( ) ) ;
160+
161+ Assert . NotNull ( opts ) ;
162+ Assert . False ( opts . PrepareProvider ) ;
163+ }
164+
165+ [ Fact ]
166+ public void PrepareGetRegistrationOptionsHonorsPrepareSupportWhenCapabilityProvided ( )
167+ {
168+ RenameRegistrationOptions opts = testPrepareHandler . GetRegistrationOptions (
169+ capability : new RenameCapability { PrepareSupport = true } ,
170+ clientCapabilities : new ClientCapabilities ( ) ) ;
171+
172+ Assert . NotNull ( opts ) ;
173+ Assert . True ( opts . PrepareProvider ) ;
174+ }
128175}
0 commit comments