@@ -36,7 +36,8 @@ public void Should_AllowSupportedCapabilities(IJsonRpcHandler handler, object in
36
36
37
37
public static IEnumerable < object [ ] > AllowSupportedCapabilities ( )
38
38
{
39
- return GetItems ( Capabilities , type => {
39
+ return GetItems ( Capabilities , type =>
40
+ {
40
41
var handlerTypes = GetHandlerTypes ( type ) ;
41
42
var handler = Substitute . For ( handlerTypes . ToArray ( ) , new object [ 0 ] ) ;
42
43
return new [ ] { handler , Activator . CreateInstance ( typeof ( Supports < > ) . MakeGenericType ( type ) , true , Activator . CreateInstance ( type ) ) } ;
@@ -56,7 +57,8 @@ public void Should_AllowUnsupportedCapabilities(IJsonRpcHandler handler, object
56
57
57
58
public static IEnumerable < object [ ] > AllowUnsupportedCapabilities ( )
58
59
{
59
- return GetItems ( Capabilities , type => {
60
+ return GetItems ( Capabilities , type =>
61
+ {
60
62
var handlerTypes = GetHandlerTypes ( type ) ;
61
63
var handler = Substitute . For ( handlerTypes . ToArray ( ) , new object [ 0 ] ) ;
62
64
return new [ ] { handler , Activator . CreateInstance ( typeof ( Supports < > ) . MakeGenericType ( type ) , false ) } ;
@@ -104,7 +106,8 @@ public void Should_AllowNullSupportedCapabilities(IJsonRpcHandler handler, objec
104
106
105
107
public static IEnumerable < object [ ] > AllowNullSupportsCapabilities ( )
106
108
{
107
- return GetItems ( Capabilities , type => {
109
+ return GetItems ( Capabilities , type =>
110
+ {
108
111
var handlerTypes = GetHandlerTypes ( type ) ;
109
112
var handler = Substitute . For ( handlerTypes . ToArray ( ) , new object [ 0 ] ) ;
110
113
return new [ ] { handler , Activator . CreateInstance ( typeof ( Supports < > ) . MakeGenericType ( type ) , true ) } ;
@@ -125,7 +128,8 @@ public void Should_DisallowDynamicSupportedCapabilities(IJsonRpcHandler handler,
125
128
126
129
public static IEnumerable < object [ ] > DisallowDynamicSupportsCapabilities ( )
127
130
{
128
- return GetItems ( Capabilities , type => {
131
+ return GetItems ( Capabilities , type =>
132
+ {
129
133
var handlerTypes = GetHandlerTypes ( type ) ;
130
134
var handler = Substitute . For ( handlerTypes . ToArray ( ) , new object [ 0 ] ) ;
131
135
var capability = Activator . CreateInstance ( type ) ;
@@ -145,12 +149,16 @@ public void Should_Handle_Mixed_Capabilities()
145
149
146
150
var collection = new HandlerCollection ( SupportedCapabilitiesFixture . AlwaysTrue , new TextDocumentIdentifiers ( ) ) { textDocumentSyncHandler , codeActionHandler , definitionHandler , typeDefinitionHandler } ;
147
151
var provider = new ClientCapabilityProvider ( collection ) ;
148
- var capabilities = new ClientCapabilities ( ) {
149
- TextDocument = new TextDocumentClientCapabilities ( ) {
150
- CodeAction = new Supports < CodeActionCapability > ( true , new CodeActionCapability ( ) {
152
+ var capabilities = new ClientCapabilities ( )
153
+ {
154
+ TextDocument = new TextDocumentClientCapabilities ( )
155
+ {
156
+ CodeAction = new Supports < CodeActionCapability > ( true , new CodeActionCapability ( )
157
+ {
151
158
DynamicRegistration = false ,
152
159
} ) ,
153
- TypeDefinition = new Supports < TypeDefinitionCapability > ( true , new TypeDefinitionCapability ( ) {
160
+ TypeDefinition = new Supports < TypeDefinitionCapability > ( true , new TypeDefinitionCapability ( )
161
+ {
154
162
DynamicRegistration = true ,
155
163
} )
156
164
}
@@ -161,6 +169,57 @@ public void Should_Handle_Mixed_Capabilities()
161
169
provider . HasStaticHandler ( capabilities . TextDocument . TypeDefinition ) . Should ( ) . BeFalse ( ) ;
162
170
}
163
171
172
+ [ Fact ]
173
+ public void GH162_TextDocumentSync_Should_Work_Without_WillSave_Or_WillSaveWaitUntil ( )
174
+ {
175
+ var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions . With ( DocumentSelector . ForPattern ( "**/*.cs" ) , "csharp" ) ;
176
+
177
+ var collection = new HandlerCollection ( SupportedCapabilitiesFixture . AlwaysTrue , new TextDocumentIdentifiers ( ) ) { textDocumentSyncHandler } ;
178
+ var provider = new ClientCapabilityProvider ( collection ) ;
179
+ var capabilities = new ClientCapabilities ( )
180
+ {
181
+ TextDocument = new TextDocumentClientCapabilities ( )
182
+ {
183
+ Synchronization = new SynchronizationCapability ( )
184
+ {
185
+ DidSave = true ,
186
+ DynamicRegistration = false ,
187
+ WillSave = true ,
188
+ WillSaveWaitUntil = true
189
+ } ,
190
+ }
191
+ } ;
192
+
193
+ provider . HasStaticHandler ( capabilities . TextDocument . Synchronization ) . Should ( ) . BeTrue ( ) ;
194
+ }
195
+
196
+ [ Fact ]
197
+ public void GH162_TextDocumentSync_Should_Work_With_WillSave_Or_WillSaveWaitUntil ( )
198
+ {
199
+ var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions . With ( DocumentSelector . ForPattern ( "**/*.cs" ) , "csharp" ) ;
200
+ var willSaveTextDocumentHandler = Substitute . For < IWillSaveTextDocumentHandler > ( ) ;
201
+ var willSaveWaitUntilTextDocumentHandler = Substitute . For < IWillSaveWaitUntilTextDocumentHandler > ( ) ;
202
+ var didSaveTextDocumentHandler = Substitute . For < IDidSaveTextDocumentHandler > ( ) ;
203
+
204
+ var collection = new HandlerCollection ( SupportedCapabilitiesFixture . AlwaysTrue , new TextDocumentIdentifiers ( ) ) { textDocumentSyncHandler , willSaveTextDocumentHandler , willSaveWaitUntilTextDocumentHandler , didSaveTextDocumentHandler } ;
205
+ var provider = new ClientCapabilityProvider ( collection ) ;
206
+ var capabilities = new ClientCapabilities ( )
207
+ {
208
+ TextDocument = new TextDocumentClientCapabilities ( )
209
+ {
210
+ Synchronization = new SynchronizationCapability ( )
211
+ {
212
+ DidSave = true ,
213
+ DynamicRegistration = false ,
214
+ WillSave = true ,
215
+ WillSaveWaitUntil = true
216
+ } ,
217
+ }
218
+ } ;
219
+
220
+ provider . HasStaticHandler ( capabilities . TextDocument . Synchronization ) . Should ( ) . BeTrue ( ) ;
221
+ }
222
+
164
223
private static bool HasHandler ( ClientCapabilityProvider provider , object instance )
165
224
{
166
225
return ( bool ) typeof ( ClientCapabilityProviderTests ) . GetTypeInfo ( )
0 commit comments