5
5
using System . Threading . Tasks ;
6
6
using Newtonsoft . Json . Linq ;
7
7
using Microsoft . Extensions . Logging ;
8
- using Newtonsoft . Json ;
9
8
using OmniSharp . Extensions . JsonRpc . Server ;
10
9
using OmniSharp . Extensions . JsonRpc . Server . Messages ;
11
10
@@ -72,7 +71,8 @@ private void ProcessInputStream()
72
71
// content is encoded in UTF-8
73
72
while ( true )
74
73
{
75
- try {
74
+ try
75
+ {
76
76
if ( _inputThread == null ) return ;
77
77
78
78
var buffer = new byte [ 300 ] ;
@@ -182,8 +182,7 @@ private void HandleRequest(string request)
182
182
_scheduler . Add (
183
183
type ,
184
184
item . Request . Method ,
185
- async ( ) =>
186
- {
185
+ async ( ) => {
187
186
try
188
187
{
189
188
var result = await _requestRouter . RouteRequest ( descriptor , item . Request , CancellationToken . None ) ;
@@ -202,26 +201,24 @@ private void HandleRequest(string request)
202
201
203
202
if ( item . IsNotification )
204
203
{
204
+
205
205
var descriptor = _requestRouter . GetDescriptor ( item . Notification ) ;
206
206
if ( descriptor is null ) continue ;
207
+
208
+ // We need to special case cancellation so that we can cancel any request that is currently in flight.
209
+ if ( descriptor . Method == JsonRpcNames . CancelRequest )
210
+ {
211
+ var cancelParams = item . Notification . Params ? . ToObject < CancelParams > ( ) ;
212
+ if ( cancelParams == null ) { continue ; }
213
+ _requestRouter . CancelRequest ( cancelParams . Id ) ;
214
+ continue ;
215
+ }
216
+
207
217
var type = _requestProcessIdentifier . Identify ( descriptor ) ;
208
218
_scheduler . Add (
209
219
type ,
210
220
item . Notification . Method ,
211
- async ( ) =>
212
- {
213
- try
214
- {
215
- await _requestRouter . RouteNotification ( descriptor , item . Notification , CancellationToken . None ) ;
216
- }
217
- catch ( Exception e )
218
- {
219
- _logger . LogCritical ( Events . UnhandledNotification , e , "Unhandled exception executing notification {Method}" , item . Notification . Method ) ;
220
- // TODO: Should we rethrow or swallow?
221
- // If an exception happens... the whole system could be in a bad state, hence this throwing currently.
222
- throw ;
223
- }
224
- }
221
+ DoNotification ( descriptor , item . Notification )
225
222
) ;
226
223
}
227
224
@@ -231,6 +228,23 @@ private void HandleRequest(string request)
231
228
_outputHandler . Send ( item . Error ) ;
232
229
}
233
230
}
231
+
232
+ Func < Task > DoNotification ( IHandlerDescriptor descriptor , Notification notification )
233
+ {
234
+ return async ( ) => {
235
+ try
236
+ {
237
+ await _requestRouter . RouteNotification ( descriptor , notification , CancellationToken . None ) ;
238
+ }
239
+ catch ( Exception e )
240
+ {
241
+ _logger . LogCritical ( Events . UnhandledNotification , e , "Unhandled exception executing notification {Method}" , notification . Method ) ;
242
+ // TODO: Should we rethrow or swallow?
243
+ // If an exception happens... the whole system could be in a bad state, hence this throwing currently.
244
+ throw ;
245
+ }
246
+ } ;
247
+ }
234
248
}
235
249
236
250
0 commit comments