@@ -36,7 +36,8 @@ public void Should_AllowSupportedCapabilities(IJsonRpcHandler handler, object in
3636
3737 public static IEnumerable < object [ ] > AllowSupportedCapabilities ( )
3838 {
39- return GetItems ( Capabilities , type => {
39+ return GetItems ( Capabilities , type =>
40+ {
4041 var handlerTypes = GetHandlerTypes ( type ) ;
4142 var handler = Substitute . For ( handlerTypes . ToArray ( ) , new object [ 0 ] ) ;
4243 return new [ ] { handler , Activator . CreateInstance ( typeof ( Supports < > ) . MakeGenericType ( type ) , true , Activator . CreateInstance ( type ) ) } ;
@@ -56,7 +57,8 @@ public void Should_AllowUnsupportedCapabilities(IJsonRpcHandler handler, object
5657
5758 public static IEnumerable < object [ ] > AllowUnsupportedCapabilities ( )
5859 {
59- return GetItems ( Capabilities , type => {
60+ return GetItems ( Capabilities , type =>
61+ {
6062 var handlerTypes = GetHandlerTypes ( type ) ;
6163 var handler = Substitute . For ( handlerTypes . ToArray ( ) , new object [ 0 ] ) ;
6264 return new [ ] { handler , Activator . CreateInstance ( typeof ( Supports < > ) . MakeGenericType ( type ) , false ) } ;
@@ -104,7 +106,8 @@ public void Should_AllowNullSupportedCapabilities(IJsonRpcHandler handler, objec
104106
105107 public static IEnumerable < object [ ] > AllowNullSupportsCapabilities ( )
106108 {
107- return GetItems ( Capabilities , type => {
109+ return GetItems ( Capabilities , type =>
110+ {
108111 var handlerTypes = GetHandlerTypes ( type ) ;
109112 var handler = Substitute . For ( handlerTypes . ToArray ( ) , new object [ 0 ] ) ;
110113 return new [ ] { handler , Activator . CreateInstance ( typeof ( Supports < > ) . MakeGenericType ( type ) , true ) } ;
@@ -125,7 +128,8 @@ public void Should_DisallowDynamicSupportedCapabilities(IJsonRpcHandler handler,
125128
126129 public static IEnumerable < object [ ] > DisallowDynamicSupportsCapabilities ( )
127130 {
128- return GetItems ( Capabilities , type => {
131+ return GetItems ( Capabilities , type =>
132+ {
129133 var handlerTypes = GetHandlerTypes ( type ) ;
130134 var handler = Substitute . For ( handlerTypes . ToArray ( ) , new object [ 0 ] ) ;
131135 var capability = Activator . CreateInstance ( type ) ;
@@ -145,12 +149,16 @@ public void Should_Handle_Mixed_Capabilities()
145149
146150 var collection = new HandlerCollection ( SupportedCapabilitiesFixture . AlwaysTrue , new TextDocumentIdentifiers ( ) ) { textDocumentSyncHandler , codeActionHandler , definitionHandler , typeDefinitionHandler } ;
147151 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+ {
151158 DynamicRegistration = false ,
152159 } ) ,
153- TypeDefinition = new Supports < TypeDefinitionCapability > ( true , new TypeDefinitionCapability ( ) {
160+ TypeDefinition = new Supports < TypeDefinitionCapability > ( true , new TypeDefinitionCapability ( )
161+ {
154162 DynamicRegistration = true ,
155163 } )
156164 }
@@ -161,6 +169,57 @@ public void Should_Handle_Mixed_Capabilities()
161169 provider . HasStaticHandler ( capabilities . TextDocument . TypeDefinition ) . Should ( ) . BeFalse ( ) ;
162170 }
163171
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+
164223 private static bool HasHandler ( ClientCapabilityProvider provider , object instance )
165224 {
166225 return ( bool ) typeof ( ClientCapabilityProviderTests ) . GetTypeInfo ( )
0 commit comments