Skip to content

Commit 223e42f

Browse files
readd setting of capabilities
1 parent 7cf0c0a commit 223e42f

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

src/Server/HandlerCollection.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ private HandlerDescriptor GetDescriptor(string method, Type handlerType, IJsonRp
135135

136136
if (_supportedCapabilities.AllowsDynamicRegistration(capabilityType))
137137
{
138-
registration = new Registration() {
138+
registration = new Registration()
139+
{
139140
Id = Guid.NewGuid().ToString(),
140141
Method = method,
141142
RegisterOptions = registrationOptions
@@ -162,7 +163,7 @@ private HandlerDescriptor GetDescriptor(string method, Type handlerType, IJsonRp
162163

163164
if (string.IsNullOrWhiteSpace(key)) key = "default";
164165

165-
return new HandlerDescriptor(
166+
var descriptor = new HandlerDescriptor(
166167
method,
167168
key,
168169
handler,
@@ -171,10 +172,15 @@ private HandlerDescriptor GetDescriptor(string method, Type handlerType, IJsonRp
171172
registrationType,
172173
registration,
173174
capabilityType,
174-
() => {
175-
_handlers.RemoveWhere(descriptor => descriptor.Handler == handler);
176-
_textDocumentIdentifiers.RemoveWhere(descriptor => descriptor.Handler == handler);
175+
() =>
176+
{
177+
_handlers.RemoveWhere(d => d.Handler == handler);
178+
_textDocumentIdentifiers.RemoveWhere(d => d.Handler == handler);
177179
});
180+
181+
LspHandlerDescriptorHelpers.InitializeHandler(descriptor, _supportedCapabilities, handler);
182+
183+
return descriptor;
178184
}
179185

180186
private Type UnwrapGenericType(Type genericType, Type type)

src/Server/ISupportedCapabilities.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using OmniSharp.Extensions.JsonRpc;
23
using OmniSharp.Extensions.LanguageServer.Server.Abstractions;
34

45
namespace OmniSharp.Extensions.LanguageServer.Server
@@ -7,5 +8,7 @@ public interface ISupportedCapabilities
78
{
89
bool AllowsDynamicRegistration(ILspHandlerDescriptor descriptor);
910
bool AllowsDynamicRegistration(Type capabilityType);
11+
void SetCapability(ILspHandlerDescriptor descriptor, IJsonRpcHandler handler);
1012
}
13+
1114
}

src/Server/LspHandlerDescriptorHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace OmniSharp.Extensions.LanguageServer.Server
1010
{
1111
static class LspHandlerDescriptorHelpers
1212
{
13-
public static IJsonRpcHandler InitializeHandler(ILspHandlerDescriptor descriptor, SupportedCapabilities supportedCapabilities, IJsonRpcHandler handler)
13+
public static IJsonRpcHandler InitializeHandler(ILspHandlerDescriptor descriptor, ISupportedCapabilities supportedCapabilities, IJsonRpcHandler handler)
1414
{
1515
supportedCapabilities.SetCapability(descriptor, handler);
1616
return handler;

test/Lsp.Tests/ClientCapabilityProviderFixture.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using NSubstitute;
3+
using OmniSharp.Extensions.JsonRpc;
34
using OmniSharp.Extensions.LanguageServer.Protocol;
45
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
56
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
@@ -18,7 +19,7 @@ public ClientCapabilityProviderFixture()
1819
var handler = Substitute.For<IExecuteCommandHandler>();
1920
handler.GetRegistrationOptions().Returns(new ExecuteCommandRegistrationOptions());
2021

21-
var handlerCollection = new HandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue) { handler };
22+
var handlerCollection = new OmniSharp.Extensions.LanguageServer.Server.HandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue) { handler };
2223
var capabilityProvider = new ClientCapabilityProvider(handlerCollection);
2324

2425
Provider = capabilityProvider;
@@ -40,13 +41,20 @@ class AlwaysTrueSupportedCapabilities : ISupportedCapabilities
4041

4142
public bool AllowsDynamicRegistration(Type capabilityType) => true;
4243

44+
public void SetCapability(ILspHandlerDescriptor descriptor, IJsonRpcHandler handler)
45+
{
46+
}
4347
}
4448

4549
class AlwaysFalseSupportedCapabilities : ISupportedCapabilities
4650
{
4751
public bool AllowsDynamicRegistration(ILspHandlerDescriptor descriptor) => false;
4852

4953
public bool AllowsDynamicRegistration(Type capabilityType) => false;
54+
55+
public void SetCapability(ILspHandlerDescriptor descriptor, IJsonRpcHandler handler)
56+
{
57+
}
5058
}
5159
}
5260
}

0 commit comments

Comments
 (0)