Skip to content

Commit f128b27

Browse files
Breaking change: changed HandleNotification to return a task instead of void. This allows operations that handle notifiactions to wait
1 parent 69b540b commit f128b27

File tree

8 files changed

+21
-22
lines changed

8 files changed

+21
-22
lines changed

src/JsonRpc/IRequestRouter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
using System;
1+
using System;
22
using System.Threading.Tasks;
33
using OmniSharp.Extensions.JsonRpc.Server;
44

55
namespace OmniSharp.Extensions.JsonRpc
66
{
77
public interface IRequestRouter
88
{
9-
void RouteNotification(Notification notification);
9+
Task RouteNotification(Notification notification);
1010
Task<ErrorResponse> RouteRequest(Request request);
1111
}
1212
}

src/JsonRpc/InputHandler.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@ private void HandleRequest(string request)
190190
_scheduler.Add(
191191
type,
192192
item.Notification.Method,
193-
() => {
193+
async () => {
194194
try
195195
{
196-
_requestRouter.RouteNotification(item.Notification);
196+
await _requestRouter.RouteNotification(item.Notification);
197197
}
198198
catch (Exception e)
199199
{
@@ -202,7 +202,6 @@ private void HandleRequest(string request)
202202
// If an exception happens... the whole system could be in a bad state, hence this throwing currently.
203203
throw;
204204
}
205-
return Task.CompletedTask;
206205
}
207206
);
208207
}

src/JsonRpc/RequestRouter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public IDisposable Add(IJsonRpcHandler handler)
2222
return _collection.Add(handler);
2323
}
2424

25-
public async void RouteNotification(Notification notification)
25+
public async Task RouteNotification(Notification notification)
2626
{
2727
var handler = _collection.FirstOrDefault(x => x.Method == notification.Method);
2828

src/Lsp/LspRequestRouter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private ILspHandlerDescriptor GetHandler(string method, TextDocumentAttributes a
125125
return null;
126126
}
127127

128-
public async void RouteNotification(Notification notification)
128+
public async Task RouteNotification(Notification notification)
129129
{
130130
var handler = FindDescriptor(notification.Method, notification.Params);
131131
if (handler is null) { return; }

test/JsonRpc.Tests/InputHandlerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public void ShouldHandleError()
206206
}
207207

208208
[Fact]
209-
public void ShouldHandleNotification()
209+
public async Task ShouldHandleNotification()
210210
{
211211
var inputStream = new MemoryStream(Encoding.ASCII.GetBytes("Content-Length: 2\r\n\r\n{}"));
212212
var outputHandler = Substitute.For<IOutputHandler>();
@@ -234,7 +234,7 @@ public void ShouldHandleNotification()
234234
});
235235
}))
236236
{
237-
incomingRequestRouter.Received().RouteNotification(notification);
237+
await incomingRequestRouter.Received().RouteNotification(notification);
238238
}
239239
}
240240

test/JsonRpc.Tests/MediatorTestsNotificationHandler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Reflection;
33
using System.Threading.Tasks;
44
using NSubstitute;
@@ -23,10 +23,10 @@ public async Task ExecutesHandler()
2323

2424
var notification = new Notification("exit", null);
2525

26-
mediator.RouteNotification(notification);
26+
await mediator.RouteNotification(notification);
2727

2828
await exitHandler.Received(1).Handle();
2929
}
3030

3131
}
32-
}
32+
}

test/JsonRpc.Tests/MediatorTestsNotificationHandlerOfT.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Reflection;
33
using System.Threading.Tasks;
44
using Newtonsoft.Json;
@@ -33,10 +33,10 @@ public async Task ExecutesHandler()
3333
var @params = new CancelParams() { Id = Guid.NewGuid() };
3434
var notification = new Notification("$/cancelRequest", JObject.Parse(JsonConvert.SerializeObject(@params)));
3535

36-
mediator.RouteNotification(notification);
36+
await mediator.RouteNotification(notification);
3737

3838
await cancelRequestHandler.Received(1).Handle(Arg.Any<CancelParams>());
3939
}
4040

4141
}
42-
}
42+
}

test/Lsp.Tests/LspRequestRouterTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public LspRequestRouterTests(ITestOutputHelper testOutputHelper)
3030
}
3131

3232
[Fact]
33-
public void ShouldRouteToCorrect_Notification()
33+
public async Task ShouldRouteToCorrect_Notification()
3434
{
3535
var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs"));
3636
textDocumentSyncHandler.Handle(Arg.Any<DidSaveTextDocumentParams>()).Returns(Task.CompletedTask);
@@ -44,13 +44,13 @@ public void ShouldRouteToCorrect_Notification()
4444

4545
var request = new Notification("textDocument/didSave", JObject.Parse(JsonConvert.SerializeObject(@params)));
4646

47-
mediator.RouteNotification(request);
47+
await mediator.RouteNotification(request);
4848

49-
textDocumentSyncHandler.Received(1).Handle(Arg.Any<DidSaveTextDocumentParams>());
49+
await textDocumentSyncHandler.Received(1).Handle(Arg.Any<DidSaveTextDocumentParams>());
5050
}
5151

5252
[Fact]
53-
public void ShouldRouteToCorrect_Notification_WithManyHandlers()
53+
public async Task ShouldRouteToCorrect_Notification_WithManyHandlers()
5454
{
5555
var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs"));
5656
var textDocumentSyncHandler2 = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cake"));
@@ -66,10 +66,10 @@ public void ShouldRouteToCorrect_Notification_WithManyHandlers()
6666

6767
var request = new Notification("textDocument/didSave", JObject.Parse(JsonConvert.SerializeObject(@params)));
6868

69-
mediator.RouteNotification(request);
69+
await mediator.RouteNotification(request);
7070

71-
textDocumentSyncHandler.Received(0).Handle(Arg.Any<DidSaveTextDocumentParams>());
72-
textDocumentSyncHandler2.Received(1).Handle(Arg.Any<DidSaveTextDocumentParams>());
71+
await textDocumentSyncHandler.Received(0).Handle(Arg.Any<DidSaveTextDocumentParams>());
72+
await textDocumentSyncHandler2.Received(1).Handle(Arg.Any<DidSaveTextDocumentParams>());
7373
}
7474

7575
[Fact]

0 commit comments

Comments
 (0)