44using OmniSharp . Extensions . LanguageServer . Client . Protocol ;
55using Xunit ;
66using Xunit . Abstractions ;
7+ using OmniSharp . Extensions . LanguageServer . Protocol . Serialization ;
8+ using OmniSharp . Extensions . LanguageServer . Protocol . Client . Capabilities ;
79
810namespace OmniSharp . Extensions . LanguageServerProtocol . Client . Tests
911{
@@ -35,7 +37,7 @@ public async Task Client_HandleEmptyNotification_Success()
3537 LspConnection clientConnection = await CreateClientConnection ( ) ;
3638 LspConnection serverConnection = await CreateServerConnection ( ) ;
3739
38- var serverDispatcher = new LspDispatcher ( ) ;
40+ var serverDispatcher = CreateDispatcher ( ) ;
3941 serverDispatcher . HandleEmptyNotification ( "test" , ( ) =>
4042 {
4143 Log . LogInformation ( "Got notification." ) ;
@@ -44,7 +46,7 @@ public async Task Client_HandleEmptyNotification_Success()
4446 } ) ;
4547 serverConnection . Connect ( serverDispatcher ) ;
4648
47- clientConnection . Connect ( new LspDispatcher ( ) ) ;
49+ clientConnection . Connect ( CreateDispatcher ( ) ) ;
4850 clientConnection . SendEmptyNotification ( "test" ) ;
4951
5052 await testCompletion . Task ;
@@ -66,7 +68,7 @@ public async Task Server_HandleEmptyNotification_Success()
6668 LspConnection clientConnection = await CreateClientConnection ( ) ;
6769 LspConnection serverConnection = await CreateServerConnection ( ) ;
6870
69- var clientDispatcher = new LspDispatcher ( ) ;
71+ var clientDispatcher = CreateDispatcher ( ) ;
7072 clientDispatcher . HandleEmptyNotification ( "test" , ( ) =>
7173 {
7274 Log . LogInformation ( "Got notification." ) ;
@@ -75,7 +77,7 @@ public async Task Server_HandleEmptyNotification_Success()
7577 } ) ;
7678 clientConnection . Connect ( clientDispatcher ) ;
7779
78- serverConnection . Connect ( new LspDispatcher ( ) ) ;
80+ serverConnection . Connect ( CreateDispatcher ( ) ) ;
7981 serverConnection . SendEmptyNotification ( "test" ) ;
8082
8183 await testCompletion . Task ;
@@ -95,7 +97,7 @@ public async Task Server_HandleRequest_Success()
9597 LspConnection clientConnection = await CreateClientConnection ( ) ;
9698 LspConnection serverConnection = await CreateServerConnection ( ) ;
9799
98- var clientDispatcher = new LspDispatcher ( ) ;
100+ var clientDispatcher = CreateDispatcher ( ) ;
99101 clientDispatcher . HandleRequest < TestRequest , TestResponse > ( "test" , ( request , cancellationToken ) =>
100102 {
101103 Log . LogInformation ( "Got request: {@Request}" , request ) ;
@@ -107,7 +109,7 @@ public async Task Server_HandleRequest_Success()
107109 } ) ;
108110 clientConnection . Connect ( clientDispatcher ) ;
109111
110- serverConnection . Connect ( new LspDispatcher ( ) ) ;
112+ serverConnection . Connect ( CreateDispatcher ( ) ) ;
111113 TestResponse response = await serverConnection . SendRequest < TestResponse > ( "test" , new TestRequest
112114 {
113115 Value = 1234
@@ -132,7 +134,7 @@ public async Task Client_HandleRequest_Success()
132134 LspConnection clientConnection = await CreateClientConnection ( ) ;
133135 LspConnection serverConnection = await CreateServerConnection ( ) ;
134136
135- var serverDispatcher = new LspDispatcher ( ) ;
137+ var serverDispatcher = CreateDispatcher ( ) ;
136138 serverDispatcher . HandleRequest < TestRequest , TestResponse > ( "test" , ( request , cancellationToken ) =>
137139 {
138140 Log . LogInformation ( "Got request: {@Request}" , request ) ;
@@ -144,7 +146,7 @@ public async Task Client_HandleRequest_Success()
144146 } ) ;
145147 serverConnection . Connect ( serverDispatcher ) ;
146148
147- clientConnection . Connect ( new LspDispatcher ( ) ) ;
149+ clientConnection . Connect ( CreateDispatcher ( ) ) ;
148150 TestResponse response = await clientConnection . SendRequest < TestResponse > ( "test" , new TestRequest
149151 {
150152 Value = 1234
@@ -169,7 +171,7 @@ public async Task Server_HandleCommandRequest_Success()
169171 LspConnection clientConnection = await CreateClientConnection ( ) ;
170172 LspConnection serverConnection = await CreateServerConnection ( ) ;
171173
172- var clientDispatcher = new LspDispatcher ( ) ;
174+ var clientDispatcher = CreateDispatcher ( ) ;
173175 clientDispatcher . HandleRequest < TestRequest > ( "test" , ( request , cancellationToken ) =>
174176 {
175177 Log . LogInformation ( "Got request: {@Request}" , request ) ;
@@ -180,7 +182,7 @@ public async Task Server_HandleCommandRequest_Success()
180182 } ) ;
181183 clientConnection . Connect ( clientDispatcher ) ;
182184
183- serverConnection . Connect ( new LspDispatcher ( ) ) ;
185+ serverConnection . Connect ( CreateDispatcher ( ) ) ;
184186 await serverConnection . SendRequest ( "test" , new TestRequest
185187 {
186188 Value = 1234
@@ -201,7 +203,7 @@ public async Task Client_HandleCommandRequest_Success()
201203 LspConnection clientConnection = await CreateClientConnection ( ) ;
202204 LspConnection serverConnection = await CreateServerConnection ( ) ;
203205
204- var serverDispatcher = new LspDispatcher ( ) ;
206+ var serverDispatcher = CreateDispatcher ( ) ;
205207 serverDispatcher . HandleRequest < TestRequest > ( "test" , ( request , cancellationToken ) =>
206208 {
207209 Log . LogInformation ( "Got request: {@Request}" , request ) ;
@@ -212,7 +214,7 @@ public async Task Client_HandleCommandRequest_Success()
212214 } ) ;
213215 serverConnection . Connect ( serverDispatcher ) ;
214216
215- clientConnection . Connect ( new LspDispatcher ( ) ) ;
217+ clientConnection . Connect ( CreateDispatcher ( ) ) ;
216218 await clientConnection . SendRequest ( "test" , new TestRequest
217219 {
218220 Value = 1234
@@ -223,5 +225,13 @@ public async Task Client_HandleCommandRequest_Success()
223225
224226 await Task . WhenAll ( clientConnection . HasHasDisconnected , serverConnection . HasHasDisconnected ) ;
225227 }
228+
229+ /// <summary>
230+ /// Create an <see cref="LspDispatcher"/> for use in tests.
231+ /// </summary>
232+ /// <returns>
233+ /// The <see cref="LspDispatcher"/>.
234+ /// </returns>
235+ LspDispatcher CreateDispatcher ( ) => new LspDispatcher ( new Serializer ( ClientVersion . Lsp3 ) ) ;
226236 }
227237}
0 commit comments