Skip to content

Commit b1f0d7e

Browse files
Removed key, not needed, and use the text registration options
1 parent f453534 commit b1f0d7e

17 files changed

+96
-83
lines changed

sample/SampleServer/Program.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ public TextDocumentHandler(ILanguageServer router)
6565
OpenClose = true
6666
};
6767

68-
public string Key => (string)_documentSelector;
69-
7068
public Task Handle(DidChangeTextDocumentParams notification)
7169
{
7270
_router.LogMessage(new LogMessageParams()

src/JsonRpc/IJsonRpcHandler.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,5 @@
33
/// <summary>
44
/// A simple marker interface to use for storing handlings (which will be cast out later)
55
/// </summary>
6-
public interface IJsonRpcHandler
7-
{
8-
string Key { get; }
9-
}
6+
public interface IJsonRpcHandler { }
107
}

src/JsonRpc/IRequestRouter.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,5 @@ public interface IRequestRouter
88
{
99
void RouteNotification(Notification notification);
1010
Task<ErrorResponse> RouteRequest(Request request);
11-
12-
IDisposable Add(IJsonRpcHandler handler);
1311
}
14-
}
12+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace OmniSharp.Extensions.LanguageServer.Abstractions
22
{
3-
public interface IRegistration<TOptions>
3+
public interface IRegistration<out TOptions>
44
{
55
TOptions GetRegistrationOptions();
66
}
7-
}
7+
}

src/Lsp/HandlerCollection.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Reflection;
66
using OmniSharp.Extensions.JsonRpc;
77
using OmniSharp.Extensions.LanguageServer.Abstractions;
8+
using OmniSharp.Extensions.LanguageServer.Models;
89

910
namespace OmniSharp.Extensions.LanguageServer
1011
{
@@ -46,8 +47,16 @@ public IDisposable Add(IEnumerable<IJsonRpcHandler> handlers)
4647
@params = @interface.GetTypeInfo().GetGenericArguments()[0];
4748
}
4849

50+
var key = "default";
51+
if (handler is IRegistration<TextDocumentRegistrationOptions> textDocumentRegistration)
52+
{
53+
var options = textDocumentRegistration.GetRegistrationOptions();
54+
key = options.DocumentSelector;
55+
}
56+
4957
var h = new HandlerDescriptor(
5058
LspHelper.GetMethodName(implementedInterface),
59+
key,
5160
handler,
5261
@interface,
5362
@params,

src/Lsp/HandlerDescriptor.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ class HandlerDescriptor : ILspHandlerDescriptor, IDisposable
1111
{
1212
private readonly Action _disposeAction;
1313

14-
public HandlerDescriptor(string method, IJsonRpcHandler handler, Type handlerType, Type @params, Type registrationType, Type capabilityType, Action disposeAction)
14+
public HandlerDescriptor(string method, string key, IJsonRpcHandler handler, Type handlerType, Type @params, Type registrationType, Type capabilityType, Action disposeAction)
1515
{
1616
_disposeAction = disposeAction;
1717
Handler = handler;
1818
Method = method;
19+
Key = key;
1920
HandlerType = handlerType;
2021
Params = @params;
2122
RegistrationType = registrationType;
@@ -70,6 +71,7 @@ public void SetCapability(object instance)
7071
}
7172

7273
public string Method { get; }
74+
public string Key { get; }
7375
public Type Params { get; }
7476

7577
public bool IsDynamicCapability => typeof(DynamicCapability).GetTypeInfo().IsAssignableFrom(CapabilityType);
@@ -94,15 +96,14 @@ public override bool Equals(object obj)
9496
{
9597
if (obj is HandlerDescriptor handler)
9698
{
97-
return handler.HandlerType == HandlerType && handler.Handler.Key == Handler.Key;
99+
return handler.HandlerType == HandlerType && handler.Key == Key;
98100
}
99101
return false;
100102
}
101103

102104
public override int GetHashCode()
103105
{
104-
if (string.IsNullOrWhiteSpace(Handler.Key)) return HandlerType.GetHashCode();
105-
return Tuple.Create(HandlerType, Handler.Key).GetHashCode();
106+
return Tuple.Create(HandlerType, Key).GetHashCode();
106107
}
107108
}
108109
}

src/Lsp/Handlers/CancelRequestHandler.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ internal CancelRequestHandler(LspRequestRouter requestRouter)
1313
_requestRouter = requestRouter;
1414
}
1515

16-
public string Key => nameof(ICancelRequestHandler);
17-
1816
public Task Handle(CancelParams notification)
1917
{
2018
_requestRouter.CancelRequest(notification.Id);

src/Lsp/Handlers/ExitHandler.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ public ExitHandler(ShutdownHandler shutdownHandler)
1212
_shutdownHandler = shutdownHandler;
1313
}
1414

15-
public string Key => nameof(IExitHandler);
16-
1715
public Task Handle()
1816
{
1917
Exit?.Invoke(_shutdownHandler.ShutdownRequested ? 0 : 1);

src/Lsp/Handlers/ShutdownHandler.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ namespace OmniSharp.Extensions.LanguageServer.Handlers
66
{
77
public class ShutdownHandler : IShutdownHandler, IAwaitableTermination
88
{
9-
public string Key => nameof(IShutdownHandler);
10-
119
public Task Handle()
1210
{
1311
ShutdownRequested = true;

src/Lsp/LanguageServer.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@ public LanguageServer(Stream input, Stream output)
3838
{
3939
}
4040

41-
internal LanguageServer(
42-
Stream input,
43-
IOutputHandler output,
44-
LspReciever reciever,
45-
IRequestProcessIdentifier requestProcessIdentifier
46-
)
41+
internal LanguageServer(Stream input, IOutputHandler output, LspReciever reciever, IRequestProcessIdentifier requestProcessIdentifier)
4742
{
4843
_reciever = reciever;
4944
_requestRouter = new LspRequestRouter(_collection);
@@ -53,18 +48,13 @@ IRequestProcessIdentifier requestProcessIdentifier
5348
_exitHandler = new ExitHandler(_shutdownHandler);
5449

5550
_disposable.Add(
56-
AddHandler(this),
57-
AddHandler(_shutdownHandler),
58-
AddHandler(_exitHandler),
59-
AddHandler(new CancelRequestHandler(_requestRouter))
51+
AddHandlers(this, _shutdownHandler, _exitHandler, new CancelRequestHandler(_requestRouter))
6052
);
6153
}
6254

6355
public InitializeParams Client { get; private set; }
6456
public InitializeResult Server { get; private set; }
6557

66-
public string Key => nameof(ILanguageServer);
67-
6858
public IDisposable AddHandler(IJsonRpcHandler handler)
6959
{
7060
return AddHandler(handler);
@@ -91,7 +81,10 @@ public IDisposable AddHandlers(IEnumerable<IJsonRpcHandler> handlers)
9181
.Where(x => x != null))
9282
.ToArray();
9383

94-
Task.Run(() => this.UnregisterCapability(new UnregistrationParams() { Unregisterations = foundItems }));
84+
Task.Run(() => this.UnregisterCapability(new UnregistrationParams()
85+
{
86+
Unregisterations = foundItems
87+
}));
9588
}));
9689
}
9790

0 commit comments

Comments
 (0)