Skip to content

Commit 95c4138

Browse files
Porting over the minor breaking changes from the nullablity branch to be included in 0.18 (#335)
1 parent d3478d9 commit 95c4138

31 files changed

+224
-119
lines changed

src/Client/LanguageClient.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics.CodeAnalysis;
34
using System.Linq;
45
using System.Reactive.Disposables;
56
using System.Reactive.Linq;
@@ -381,7 +382,7 @@ private Supports<T> UseOrTryAndFindCapability<T>(Supports<T> supports) where T :
381382

382383
public IObservable<InitializeResult> Start => _initializeComplete.AsObservable();
383384

384-
(string method, TaskCompletionSource<JToken> pendingTask) IResponseRouter.GetRequest(long id) => _responseRouter.GetRequest(id);
385+
bool IResponseRouter.TryGetRequest(long id, [NotNullWhen(true)] out string method, [NotNullWhen(true)] out TaskCompletionSource<JToken> pendingTask) => _responseRouter.TryGetRequest(id, out method, out pendingTask);
385386

386387
public Task<InitializeResult> WasStarted => _initializeComplete.ToTask();
387388

src/Dap.Shared/DapResponseRouter.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Concurrent;
3+
using System.Diagnostics.CodeAnalysis;
34
using System.Threading;
45
using System.Threading.Tasks;
56
using MediatR;
@@ -51,10 +52,12 @@ public Task<TResponse> SendRequest<TResponse>(IRequest<TResponse> @params, Cance
5152

5253
public IResponseRouterReturns SendRequest<T>(string method, T @params) => new ResponseRouterReturnsImpl(this, method, @params);
5354

54-
public (string method, TaskCompletionSource<JToken> pendingTask) GetRequest(long id)
55+
public bool TryGetRequest(long id, [NotNullWhen(true)] out string method, [NotNullWhen(true)] out TaskCompletionSource<JToken> pendingTask)
5556
{
56-
Requests.TryGetValue(id, out var source);
57-
return source;
57+
var result = Requests.TryGetValue(id, out var source);
58+
method = source.method;
59+
pendingTask = source.pendingTask;
60+
return result;
5861
}
5962

6063
private string GetMethodName(Type type)

src/Dap.Shared/HandlerDescriptor.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,10 @@ public HandlerDescriptor(
3636
typeof(DelegatingNotification<>).IsAssignableFrom(@params.GetGenericTypeDefinition())
3737
);
3838

39-
IsNotification = typeof(IJsonRpcNotificationHandler).IsAssignableFrom(handlerInterface) || handlerInterface
40-
.GetInterfaces().Any(
41-
z =>
42-
z.IsGenericType && typeof(IJsonRpcNotificationHandler<>)
43-
.IsAssignableFrom(z.GetGenericTypeDefinition())
44-
);
39+
IsNotification = handlerInterface.GetInterfaces().Any(
40+
z => z.IsGenericType &&
41+
typeof(IJsonRpcNotificationHandler<>).IsAssignableFrom(z.GetGenericTypeDefinition())
42+
);
4543
IsRequest = !IsNotification;
4644
RequestProcessType = requestProcessType;
4745
}

src/JsonRpc/EmptyRequest.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/JsonRpc/HandlerInstance.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@ public HandlerInstance(
3333
typeof(DelegatingNotification<>).IsAssignableFrom(@params.GetGenericTypeDefinition())
3434
);
3535

36-
IsNotification = typeof(IJsonRpcNotificationHandler).IsAssignableFrom(handlerInterface) || handlerInterface
37-
.GetInterfaces().Any(
38-
z =>
39-
z.IsGenericType && typeof(IJsonRpcNotificationHandler<>)
40-
.IsAssignableFrom(z.GetGenericTypeDefinition())
41-
);
36+
IsNotification = handlerInterface.GetInterfaces().Any(
37+
z => z.IsGenericType &&
38+
typeof(IJsonRpcNotificationHandler<>).IsAssignableFrom(z.GetGenericTypeDefinition())
39+
);
4240
IsRequest = !IsNotification;
4341
RequestProcessType = requestProcessType;
4442
}

src/JsonRpc/HandlerTypeDescriptor.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,9 @@ public HandlerTypeDescriptor(Type handlerType)
3535
{
3636
ParamsType = InterfaceType.GetGenericArguments()[0];
3737
}
38-
else
39-
{
40-
ParamsType = typeof(EmptyRequest);
41-
}
4238

43-
HasParamsType = ParamsType != null && ParamsType != typeof(EmptyRequest);
44-
IsNotification = typeof(IJsonRpcNotificationHandler).IsAssignableFrom(handlerType) || handlerType
45-
.GetInterfaces().Any(
46-
z =>
47-
z.IsGenericType && typeof(IJsonRpcNotificationHandler<>).IsAssignableFrom(
48-
z.GetGenericTypeDefinition()
49-
)
50-
);
39+
HasParamsType = ParamsType != null;
40+
IsNotification = handlerType.GetInterfaces().Any(z => z.IsGenericType && typeof(IJsonRpcNotificationHandler<>).IsAssignableFrom(z.GetGenericTypeDefinition()));
5141
IsRequest = !IsNotification;
5242

5343
var requestInterface = ParamsType?

src/JsonRpc/HandlerTypeDescriptorProvider.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ internal static Type GetMethodType(Type type)
3333
}
3434

3535
private static readonly Type[] HandlerTypes = {
36-
typeof(IJsonRpcNotificationHandler),
3736
typeof(IJsonRpcNotificationHandler<>),
3837
typeof(IJsonRpcRequestHandler<>),
3938
typeof(IJsonRpcRequestHandler<,>),

src/JsonRpc/IJsonRpcNotificationHandler.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
namespace OmniSharp.Extensions.JsonRpc
44
{
5-
public interface IJsonRpcNotificationHandler : IRequestHandler<EmptyRequest>, IJsonRpcHandler
6-
{
7-
}
8-
95
public interface IJsonRpcNotificationHandler<in TNotification> : IRequestHandler<TNotification>, IJsonRpcHandler
106
where TNotification : IRequest
117
{

src/JsonRpc/IResponseRouter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Diagnostics.CodeAnalysis;
12
using System.Threading;
23
using System.Threading.Tasks;
34
using MediatR;
@@ -13,6 +14,6 @@ public interface IResponseRouter
1314
IResponseRouterReturns SendRequest<T>(string method, T @params);
1415
IResponseRouterReturns SendRequest(string method);
1516
Task<TResponse> SendRequest<TResponse>(IRequest<TResponse> request, CancellationToken cancellationToken);
16-
(string method, TaskCompletionSource<JToken> pendingTask) GetRequest(long id);
17+
bool TryGetRequest(long id, [NotNullWhen(true)] out string method, [NotNullWhen(true)] out TaskCompletionSource<JToken> pendingTask);
1718
}
1819
}

src/JsonRpc/InputHandler.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,7 @@ private void HandleRequest(in ReadOnlySequence<byte> request)
378378
continue;
379379
}
380380

381-
var (method, tcs) = _responseRouter.GetRequest(id);
382-
if (tcs is null)
381+
if (!_responseRouter.TryGetRequest(id, out var method, out var tcs))
383382
{
384383
// _logger.LogDebug("Request {ResponseId} was not found in the response router, unable to complete", response.Id);
385384
continue;

0 commit comments

Comments
 (0)