Skip to content

Commit

Permalink
Merge pull request #137 from gep13/issue-136
Browse files Browse the repository at this point in the history
(GH-136) Corrected IRegistration definition
  • Loading branch information
david-driscoll authored Apr 5, 2019
2 parents 35106df + 3380e61 commit 9ba6da8
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Protocol/Document/Server/ICodeActionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Server
{
using static DocumentNames;
[Parallel, Method(CodeAction)]
public interface ICodeActionHandler : IJsonRpcRequestHandler<CodeActionParams, CommandOrCodeActionContainer>, IRegistration<TextDocumentRegistrationOptions>, ICapability<CodeActionCapability> { }
public interface ICodeActionHandler : IJsonRpcRequestHandler<CodeActionParams, CommandOrCodeActionContainer>, IRegistration<CodeActionRegistrationOptions>, ICapability<CodeActionCapability> { }
}
6 changes: 3 additions & 3 deletions test/Lsp.Tests/LspRequestRouterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public async Task ShouldRouteToCorrect_Request()
textDocumentSyncHandler.Handle(Arg.Any<DidSaveTextDocumentParams>(), Arg.Any<CancellationToken>()).Returns(Unit.Value);

var codeActionHandler = Substitute.For<ICodeActionHandler>();
codeActionHandler.GetRegistrationOptions().Returns(new TextDocumentRegistrationOptions() { DocumentSelector = DocumentSelector.ForPattern("**/*.cs") });
codeActionHandler.GetRegistrationOptions().Returns(new CodeActionRegistrationOptions() { DocumentSelector = DocumentSelector.ForPattern("**/*.cs") });
codeActionHandler
.Handle(Arg.Any<CodeActionParams>(), Arg.Any<CancellationToken>())
.Returns(new CommandOrCodeActionContainer());
Expand Down Expand Up @@ -126,13 +126,13 @@ public async Task ShouldRouteToCorrect_Request_WithManyHandlers()
textDocumentSyncHandler2.Handle(Arg.Any<DidSaveTextDocumentParams>(), Arg.Any<CancellationToken>()).Returns(Unit.Value);

var codeActionHandler = Substitute.For<ICodeActionHandler>();
codeActionHandler.GetRegistrationOptions().Returns(new TextDocumentRegistrationOptions() { DocumentSelector = DocumentSelector.ForPattern("**/*.cs") });
codeActionHandler.GetRegistrationOptions().Returns(new CodeActionRegistrationOptions() { DocumentSelector = DocumentSelector.ForPattern("**/*.cs") });
codeActionHandler
.Handle(Arg.Any<CodeActionParams>(), Arg.Any<CancellationToken>())
.Returns(new CommandOrCodeActionContainer());

var codeActionHandler2 = Substitute.For<ICodeActionHandler>();
codeActionHandler2.GetRegistrationOptions().Returns(new TextDocumentRegistrationOptions() { DocumentSelector = DocumentSelector.ForPattern("**/*.cake") });
codeActionHandler2.GetRegistrationOptions().Returns(new CodeActionRegistrationOptions() { DocumentSelector = DocumentSelector.ForPattern("**/*.cake") });
codeActionHandler2
.Handle(Arg.Any<CodeActionParams>(), Arg.Any<CancellationToken>())
.Returns(new CommandOrCodeActionContainer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task RequestsCancellation()
textDocumentSyncHandler.Handle(Arg.Any<DidSaveTextDocumentParams>(), Arg.Any<CancellationToken>()).Returns(Unit.Value);

var codeActionHandler = Substitute.For<ICodeActionHandler>();
codeActionHandler.GetRegistrationOptions().Returns(new TextDocumentRegistrationOptions() { DocumentSelector = DocumentSelector.ForPattern("**/*.cs") });
codeActionHandler.GetRegistrationOptions().Returns(new CodeActionRegistrationOptions() { DocumentSelector = DocumentSelector.ForPattern("**/*.cs") });
codeActionHandler
.Handle(Arg.Any<CodeActionParams>(), Arg.Any<CancellationToken>())
.Returns(async (c) => {
Expand Down
45 changes: 45 additions & 0 deletions test/Lsp.Tests/Models/CodeActionRegistrationOptionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using FluentAssertions;
using Newtonsoft.Json;
using OmniSharp.Extensions.LanguageServer.Protocol;
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;
using Xunit;

namespace Lsp.Tests.Models
{
public class CodeActionRegistrationOptionsTests
{
[Theory, JsonFixture]
public void SimpleTest(string expected)
{
var model = new CodeActionRegistrationOptions() {
DocumentSelector = new DocumentSelector(new[] { new DocumentFilter(){
Language = "csharp",
Pattern = "pattern",
Scheme = "scheme"
}, new DocumentFilter(){
Language = "vb",
Pattern = "pattern",
Scheme = "scheme"
} }),
CodeActionKinds = new[] {
CodeActionKind.QuickFix,
CodeActionKind.Refactor,
CodeActionKind.RefactorExtract,
CodeActionKind.RefactorInline,
CodeActionKind.RefactorRewrite,
CodeActionKind.Source,
CodeActionKind.SourceOrganizeImports
}
};
var result = Fixture.SerializeObject(model);

result.Should().Be(expected);

var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject<CodeActionRegistrationOptions>(expected);
deresult.Should().BeEquivalentTo(model);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"codeActionKinds": [
"quickfix",
"refactor",
"refactor.extract",
"refactor.inline",
"refactor.rewrite",
"source",
"source.organizeImports"
],
"documentSelector": [
{
"language": "csharp",
"scheme": "scheme",
"pattern": "pattern"
},
{
"language": "vb",
"scheme": "scheme",
"pattern": "pattern"
}
]
}

0 comments on commit 9ba6da8

Please sign in to comment.