Skip to content

Commit 4df674a

Browse files
Updated to support mutliple handlers for a given handler type (which allows for mutliple files
1 parent 4bc2a15 commit 4df674a

File tree

5 files changed

+2692
-19
lines changed

5 files changed

+2692
-19
lines changed

src/Lsp/HandlerCollection.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public IDisposable Add(IJsonRpcHandler handler)
3232
.Where(x => !string.IsNullOrWhiteSpace(LspHelper.GetMethodName(x))))
3333
{
3434
var @interface = GetHandlerInterface(implementedInterface);
35+
if (@interface == null) continue;
3536
var registration = UnwrapGenericType(typeof(IRegistration<>), implementedInterface);
3637
var capability = UnwrapGenericType(typeof(ICapability<>), implementedInterface);
3738

@@ -50,12 +51,9 @@ public IDisposable Add(IJsonRpcHandler handler)
5051
capability,
5152
() => _handlers.RemoveWhere(instance => instance.Handler == handler));
5253

53-
handlers.Add(h);
54+
_handlers.Add(h);
5455
}
5556

56-
foreach (var a in handlers)
57-
_handlers.Add(a);
58-
5957
return new ImutableDisposable(handlers);
6058
}
6159

@@ -96,4 +94,4 @@ private Type UnwrapGenericType(Type genericType, Type type)
9694
?.GetGenericArguments()[0];
9795
}
9896
}
99-
}
97+
}

src/Lsp/HandlerDescriptor.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace OmniSharp.Extensions.LanguageServer
1010
class HandlerDescriptor : ILspHandlerDescriptor, IDisposable
1111
{
1212
private readonly Action _disposeAction;
13+
private readonly Guid _id = Guid.NewGuid();
1314

1415
public HandlerDescriptor(string method, IJsonRpcHandler handler, Type handlerType, Type @params, Type registrationType, Type capabilityType, Action disposeAction)
1516
{
@@ -94,14 +95,14 @@ public override bool Equals(object obj)
9495
{
9596
if (obj is HandlerDescriptor handler)
9697
{
97-
return handler.HandlerType == HandlerType;
98+
return handler._id == _id;
9899
}
99100
return false;
100101
}
101102

102103
public override int GetHashCode()
103104
{
104-
return HandlerType.GetHashCode();
105+
return _id.GetHashCode();
105106
}
106107
}
107-
}
108+
}

test/Lsp.Tests/HandlerResolverTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ public class HandlerResolverTests
1919
[Theory]
2020
[InlineData(typeof(IInitializeHandler), "initialize", 1)]
2121
[InlineData(typeof(IInitializedHandler), "initialized", 1)]
22-
[InlineData(typeof(ITextDocumentSyncHandler), "textDocument/didOpen", 4)]
23-
[InlineData(typeof(ITextDocumentSyncHandler), "textDocument/didChange", 4)]
24-
[InlineData(typeof(ITextDocumentSyncHandler), "textDocument/didClose", 4)]
25-
[InlineData(typeof(ITextDocumentSyncHandler), "textDocument/didSave", 4)]
22+
[InlineData(typeof(ITextDocumentSyncHandler), "textDocument/didOpen", 5)]
23+
[InlineData(typeof(ITextDocumentSyncHandler), "textDocument/didChange", 5)]
24+
[InlineData(typeof(ITextDocumentSyncHandler), "textDocument/didClose", 5)]
25+
[InlineData(typeof(ITextDocumentSyncHandler), "textDocument/didSave", 5)]
2626
public void Should_Contain_AllDefinedMethods(Type requestHandler, string key, int count)
2727
{
2828
var handler = new HandlerCollection();

0 commit comments

Comments
 (0)