From b94bfd5700554550611fd7dfaacbf5bfb45b0876 Mon Sep 17 00:00:00 2001 From: David Driscoll Date: Thu, 14 Mar 2019 08:42:58 -0400 Subject: [PATCH 1/5] fixes #124 --- src/Protocol/Models/DidChangeConfigurationParams.cs | 3 ++- test/Lsp.Tests/Models/DidChangeConfigurationParamsTests.cs | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Protocol/Models/DidChangeConfigurationParams.cs b/src/Protocol/Models/DidChangeConfigurationParams.cs index 36ea8d930..fd16d4f8a 100644 --- a/src/Protocol/Models/DidChangeConfigurationParams.cs +++ b/src/Protocol/Models/DidChangeConfigurationParams.cs @@ -2,6 +2,7 @@ using OmniSharp.Extensions.Embedded.MediatR; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; +using Newtonsoft.Json.Linq; namespace OmniSharp.Extensions.LanguageServer.Protocol.Models { @@ -10,6 +11,6 @@ public class DidChangeConfigurationParams : IRequest /// /// The actual changed settings /// - public IDictionary Settings { get; set; } = new Dictionary(); + public JToken Settings { get; set; } } } diff --git a/test/Lsp.Tests/Models/DidChangeConfigurationParamsTests.cs b/test/Lsp.Tests/Models/DidChangeConfigurationParamsTests.cs index 1fc777df1..c2b0a921b 100644 --- a/test/Lsp.Tests/Models/DidChangeConfigurationParamsTests.cs +++ b/test/Lsp.Tests/Models/DidChangeConfigurationParamsTests.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using FluentAssertions; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using OmniSharp.Extensions.LanguageServer.Protocol; using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities; using OmniSharp.Extensions.LanguageServer.Protocol.Models; @@ -16,11 +17,11 @@ public class DidChangeConfigurationParamsTests public void SimpleTest(string expected) { var model = new DidChangeConfigurationParams() { - Settings = new Dictionary() { + Settings = JObject.FromObject(new Dictionary() { { "abc", 1 }, { "def", "a" }, { "ghi", true }, - } + }) }; var result = Fixture.SerializeObject(model); From f942d26c102073c364b28e4f046542b00cf13961 Mon Sep 17 00:00:00 2001 From: David Driscoll Date: Thu, 14 Mar 2019 09:05:11 -0400 Subject: [PATCH 2/5] fixes #122 --- .../DocumentSymbolInformationContainer.cs | 14 ++--- ...cumentSymbolInformationOrDocumentSymbol.cs | 55 +++++-------------- src/Protocol/Models/ISymbolInformation.cs | 40 -------------- ...bolInformation.cs => SymbolInformation.cs} | 2 +- .../Models/SymbolInformationContainer.cs | 36 ++++++++++++ .../Models/WorkspaceSymbolInformation.cs | 34 ------------ .../WorkspaceSymbolInformationContainer.cs | 36 ------------ src/Protocol/Models/WorkspaceSymbolParams.cs | 2 +- ...olInformationOrDocumentSymbolConverter.cs} | 13 ++--- .../Client/WorkspaceSymbolsExtensions.cs | 4 +- .../Server/IWorkspaceSymbolsHandler.cs | 2 +- test/Lsp.Tests/DocumentSymbolKindTests.cs | 10 ++-- .../Models/DocumentSymbolInformationTests.cs | 4 +- .../Models/WorkspaceSymbolInformationTests.cs | 4 +- test/Lsp.Tests/WorkspaceSymbolKindTests.cs | 10 ++-- 15 files changed, 83 insertions(+), 183 deletions(-) delete mode 100644 src/Protocol/Models/ISymbolInformation.cs rename src/Protocol/Models/{DocumentSymbolInformation.cs => SymbolInformation.cs} (93%) create mode 100644 src/Protocol/Models/SymbolInformationContainer.cs delete mode 100644 src/Protocol/Models/WorkspaceSymbolInformation.cs delete mode 100644 src/Protocol/Models/WorkspaceSymbolInformationContainer.cs rename src/Protocol/Serialization/Converters/{DocumentSymbolInformationOrDocumentSymbolConverter.cs => SymbolInformationOrDocumentSymbolConverter.cs} (50%) diff --git a/src/Protocol/Models/DocumentSymbolInformationContainer.cs b/src/Protocol/Models/DocumentSymbolInformationContainer.cs index 4036d9205..c768af8a8 100644 --- a/src/Protocol/Models/DocumentSymbolInformationContainer.cs +++ b/src/Protocol/Models/DocumentSymbolInformationContainer.cs @@ -4,31 +4,31 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Models { - public class DocumentSymbolInformationContainer : Container + public class DocumentSymbolInformationContainer : Container { - public DocumentSymbolInformationContainer() : this(Enumerable.Empty()) + public DocumentSymbolInformationContainer() : this(Enumerable.Empty()) { } - public DocumentSymbolInformationContainer(IEnumerable items) : base(items) + public DocumentSymbolInformationContainer(IEnumerable items) : base(items) { } - public DocumentSymbolInformationContainer(params DocumentSymbolInformation[] items) : base(items) + public DocumentSymbolInformationContainer(params SymbolInformationOrDocumentSymbol[] items) : base(items) { } - public static implicit operator DocumentSymbolInformationContainer(DocumentSymbolInformation[] items) + public static implicit operator DocumentSymbolInformationContainer(SymbolInformationOrDocumentSymbol[] items) { return new DocumentSymbolInformationContainer(items); } - public static implicit operator DocumentSymbolInformationContainer(Collection items) + public static implicit operator DocumentSymbolInformationContainer(Collection items) { return new DocumentSymbolInformationContainer(items); } - public static implicit operator DocumentSymbolInformationContainer(List items) + public static implicit operator DocumentSymbolInformationContainer(List items) { return new DocumentSymbolInformationContainer(items); } diff --git a/src/Protocol/Models/DocumentSymbolInformationOrDocumentSymbol.cs b/src/Protocol/Models/DocumentSymbolInformationOrDocumentSymbol.cs index 44ee3af78..ab85095ca 100644 --- a/src/Protocol/Models/DocumentSymbolInformationOrDocumentSymbol.cs +++ b/src/Protocol/Models/DocumentSymbolInformationOrDocumentSymbol.cs @@ -1,59 +1,34 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Models { - public struct DocumentSymbolInformationOrDocumentSymbol + public struct SymbolInformationOrDocumentSymbol { private DocumentSymbol _documentSymbol; - private DocumentSymbolInformation _command; - public DocumentSymbolInformationOrDocumentSymbol(DocumentSymbol value) + private SymbolInformation _symbolInformation; + public SymbolInformationOrDocumentSymbol(DocumentSymbol documentSymbol) { - _documentSymbol = value; - _command = default; + _documentSymbol = documentSymbol; + _symbolInformation = default; } - public DocumentSymbolInformationOrDocumentSymbol(DocumentSymbolInformation value) + public SymbolInformationOrDocumentSymbol(SymbolInformation symbolInformation) { _documentSymbol = default; - _command = value; + _symbolInformation = symbolInformation; } - public bool IsDocumentSymbolInformation => this._command != null; - public DocumentSymbolInformation DocumentSymbolInformation - { - get { return this._command; } - set - { - this._command = value; - this._documentSymbol = null; - } - } + public bool IsDocumentSymbolInformation => _symbolInformation != null; + public SymbolInformation SymbolInformation => _symbolInformation; - public bool IsDocumentSymbol => this._documentSymbol != null; - public DocumentSymbol DocumentSymbol - { - get { return this._documentSymbol; } - set - { - this._command = default; - this._documentSymbol = value; - } - } - public object RawValue - { - get - { - if (IsDocumentSymbolInformation) return DocumentSymbolInformation; - if (IsDocumentSymbol) return DocumentSymbol; - return default; - } - } + public bool IsDocumentSymbol => _documentSymbol != null; + public DocumentSymbol DocumentSymbol => _documentSymbol; - public static implicit operator DocumentSymbolInformationOrDocumentSymbol(DocumentSymbolInformation value) + public static implicit operator SymbolInformationOrDocumentSymbol(SymbolInformation value) { - return new DocumentSymbolInformationOrDocumentSymbol(value); + return new SymbolInformationOrDocumentSymbol(value); } - public static implicit operator DocumentSymbolInformationOrDocumentSymbol(DocumentSymbol value) + public static implicit operator SymbolInformationOrDocumentSymbol(DocumentSymbol value) { - return new DocumentSymbolInformationOrDocumentSymbol(value); + return new SymbolInformationOrDocumentSymbol(value); } } } diff --git a/src/Protocol/Models/ISymbolInformation.cs b/src/Protocol/Models/ISymbolInformation.cs deleted file mode 100644 index 910b4d819..000000000 --- a/src/Protocol/Models/ISymbolInformation.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; -using OmniSharp.Extensions.LanguageServer.Protocol.Serialization; - -namespace OmniSharp.Extensions.LanguageServer.Protocol.Models -{ - /// - /// Represents information about programming constructs like variables, classes, - /// public classs etc. - /// - public interface ISymbolInformation - { - /// - /// The name of this symbol. - /// - string Name { get; set; } - - /// - /// The kind of this symbol. - /// - SymbolKind Kind { get; set; } - - /// - /// Indicates if this item is deprecated. - /// - [Optional] - bool Deprecated { get; set; } - - /// - /// The location of this symbol. - /// - Location Location { get; set; } - - /// - /// The name of the symbol containing this symbol. - /// - [Optional] - string ContainerName { get; set; } - } -} diff --git a/src/Protocol/Models/DocumentSymbolInformation.cs b/src/Protocol/Models/SymbolInformation.cs similarity index 93% rename from src/Protocol/Models/DocumentSymbolInformation.cs rename to src/Protocol/Models/SymbolInformation.cs index 19d24b048..b8f9e731d 100644 --- a/src/Protocol/Models/DocumentSymbolInformation.cs +++ b/src/Protocol/Models/SymbolInformation.cs @@ -2,7 +2,7 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Models { - public class DocumentSymbolInformation : ISymbolInformation + public class SymbolInformation { /// /// The name of this symbol. diff --git a/src/Protocol/Models/SymbolInformationContainer.cs b/src/Protocol/Models/SymbolInformationContainer.cs new file mode 100644 index 000000000..cb59f019b --- /dev/null +++ b/src/Protocol/Models/SymbolInformationContainer.cs @@ -0,0 +1,36 @@ +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; + +namespace OmniSharp.Extensions.LanguageServer.Protocol.Models +{ + public class SymbolInformationContainer : Container + { + public SymbolInformationContainer() : this(Enumerable.Empty()) + { + } + + public SymbolInformationContainer(IEnumerable items) : base(items) + { + } + + public SymbolInformationContainer(params SymbolInformation[] items) : base(items) + { + } + + public static implicit operator SymbolInformationContainer(SymbolInformation[] items) + { + return new SymbolInformationContainer(items); + } + + public static implicit operator SymbolInformationContainer(Collection items) + { + return new SymbolInformationContainer(items); + } + + public static implicit operator SymbolInformationContainer(List items) + { + return new SymbolInformationContainer(items); + } + } +} diff --git a/src/Protocol/Models/WorkspaceSymbolInformation.cs b/src/Protocol/Models/WorkspaceSymbolInformation.cs deleted file mode 100644 index 64a99b3a5..000000000 --- a/src/Protocol/Models/WorkspaceSymbolInformation.cs +++ /dev/null @@ -1,34 +0,0 @@ -using OmniSharp.Extensions.LanguageServer.Protocol.Serialization; - -namespace OmniSharp.Extensions.LanguageServer.Protocol.Models -{ - public class WorkspaceSymbolInformation : ISymbolInformation - { - /// - /// The name of this symbol. - /// - public string Name { get; set; } - - /// - /// The kind of this symbol. - /// - public SymbolKind Kind { get; set; } - - /// - /// Indicates if this item is deprecated. - /// - [Optional] - public bool Deprecated { get; set; } - - /// - /// The location of this symbol. - /// - public Location Location { get; set; } - - /// - /// The name of the symbol containing this symbol. - /// - [Optional] - public string ContainerName { get; set; } - } -} diff --git a/src/Protocol/Models/WorkspaceSymbolInformationContainer.cs b/src/Protocol/Models/WorkspaceSymbolInformationContainer.cs deleted file mode 100644 index b7016d711..000000000 --- a/src/Protocol/Models/WorkspaceSymbolInformationContainer.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; - -namespace OmniSharp.Extensions.LanguageServer.Protocol.Models -{ - public class WorkspaceSymbolInformationContainer : Container - { - public WorkspaceSymbolInformationContainer() : this(Enumerable.Empty()) - { - } - - public WorkspaceSymbolInformationContainer(IEnumerable items) : base(items) - { - } - - public WorkspaceSymbolInformationContainer(params WorkspaceSymbolInformation[] items) : base(items) - { - } - - public static implicit operator WorkspaceSymbolInformationContainer(WorkspaceSymbolInformation[] items) - { - return new WorkspaceSymbolInformationContainer(items); - } - - public static implicit operator WorkspaceSymbolInformationContainer(Collection items) - { - return new WorkspaceSymbolInformationContainer(items); - } - - public static implicit operator WorkspaceSymbolInformationContainer(List items) - { - return new WorkspaceSymbolInformationContainer(items); - } - } -} diff --git a/src/Protocol/Models/WorkspaceSymbolParams.cs b/src/Protocol/Models/WorkspaceSymbolParams.cs index bb7fe84aa..1204ee67c 100644 --- a/src/Protocol/Models/WorkspaceSymbolParams.cs +++ b/src/Protocol/Models/WorkspaceSymbolParams.cs @@ -7,7 +7,7 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Models /// /// The parameters of a Workspace Symbol Request. /// - public class WorkspaceSymbolParams : IRequest + public class WorkspaceSymbolParams : IRequest { /// /// A non-empty query string diff --git a/src/Protocol/Serialization/Converters/DocumentSymbolInformationOrDocumentSymbolConverter.cs b/src/Protocol/Serialization/Converters/SymbolInformationOrDocumentSymbolConverter.cs similarity index 50% rename from src/Protocol/Serialization/Converters/DocumentSymbolInformationOrDocumentSymbolConverter.cs rename to src/Protocol/Serialization/Converters/SymbolInformationOrDocumentSymbolConverter.cs index 5d8c06e25..53a3c807d 100644 --- a/src/Protocol/Serialization/Converters/DocumentSymbolInformationOrDocumentSymbolConverter.cs +++ b/src/Protocol/Serialization/Converters/SymbolInformationOrDocumentSymbolConverter.cs @@ -5,13 +5,13 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Serialization.Converters { - public class DocumentSymbolInformationOrDocumentSymbolConverter : JsonConverter + public class SymbolInformationOrDocumentSymbolConverter : JsonConverter { - public override void WriteJson(JsonWriter writer, DocumentSymbolInformationOrDocumentSymbol value, JsonSerializer serializer) + public override void WriteJson(JsonWriter writer, SymbolInformationOrDocumentSymbol value, JsonSerializer serializer) { if (value.IsDocumentSymbolInformation) { - serializer.Serialize(writer, value.DocumentSymbolInformation); + serializer.Serialize(writer, value.SymbolInformation); } else if (value.IsDocumentSymbol) { @@ -23,22 +23,21 @@ public override void WriteJson(JsonWriter writer, DocumentSymbolInformationOrDoc } } - public override DocumentSymbolInformationOrDocumentSymbol ReadJson(JsonReader reader, Type objectType, DocumentSymbolInformationOrDocumentSymbol existingValue, bool hasExistingValue, JsonSerializer serializer) + public override SymbolInformationOrDocumentSymbol ReadJson(JsonReader reader, Type objectType, SymbolInformationOrDocumentSymbol existingValue, bool hasExistingValue, JsonSerializer serializer) { var result = JObject.Load(reader); // Commands have a name, CodeActions do not if (result["location"].Type == JTokenType.Object) { - return new DocumentSymbolInformationOrDocumentSymbol(result.ToObject()); + return new SymbolInformationOrDocumentSymbol(result.ToObject()); } else { - return new DocumentSymbolInformationOrDocumentSymbol(result.ToObject()); + return new SymbolInformationOrDocumentSymbol(result.ToObject()); } } public override bool CanRead => true; } - //DocumentSymbolInformationOrDocumentSymbolConverter } diff --git a/src/Protocol/Workspace/Client/WorkspaceSymbolsExtensions.cs b/src/Protocol/Workspace/Client/WorkspaceSymbolsExtensions.cs index f0cd56e39..c58433380 100644 --- a/src/Protocol/Workspace/Client/WorkspaceSymbolsExtensions.cs +++ b/src/Protocol/Workspace/Client/WorkspaceSymbolsExtensions.cs @@ -7,9 +7,9 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Client { public static class WorkspaceSymbolsExtensions { - public static Task WorkspaceSymbol(this ILanguageClientWorkspace router, WorkspaceSymbolParams @params) + public static Task WorkspaceSymbol(this ILanguageClientWorkspace router, WorkspaceSymbolParams @params) { - return router.SendRequest(WorkspaceNames.WorkspaceSymbol, @params); + return router.SendRequest(WorkspaceNames.WorkspaceSymbol, @params); } } } diff --git a/src/Protocol/Workspace/Server/IWorkspaceSymbolsHandler.cs b/src/Protocol/Workspace/Server/IWorkspaceSymbolsHandler.cs index 4e89855f2..c3a8f7f7a 100644 --- a/src/Protocol/Workspace/Server/IWorkspaceSymbolsHandler.cs +++ b/src/Protocol/Workspace/Server/IWorkspaceSymbolsHandler.cs @@ -9,5 +9,5 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Server using static WorkspaceNames; [Parallel, Method(WorkspaceSymbol)] - public interface IWorkspaceSymbolsHandler : IJsonRpcRequestHandler, ICapability, IRegistration { } + public interface IWorkspaceSymbolsHandler : IJsonRpcRequestHandler, ICapability, IRegistration { } } diff --git a/test/Lsp.Tests/DocumentSymbolKindTests.cs b/test/Lsp.Tests/DocumentSymbolKindTests.cs index 313192287..7bc7a0cba 100644 --- a/test/Lsp.Tests/DocumentSymbolKindTests.cs +++ b/test/Lsp.Tests/DocumentSymbolKindTests.cs @@ -13,11 +13,11 @@ public class DocumentSymbolKindTests public void DefaultBehavior_Should_Only_Support_InitialKinds() { var serializer = new Serializer(); - var json = serializer.SerializeObject(new DocumentSymbolInformation() { + var json = serializer.SerializeObject(new SymbolInformation() { Kind = SymbolKind.Event }); - var result = serializer.DeserializeObject(json); + var result = serializer.DeserializeObject(json); result.Kind.Should().Be(SymbolKind.File); } @@ -36,12 +36,12 @@ public void CustomBehavior_When_Defined_By_Client() } }); - var json = serializer.SerializeObject(new DocumentSymbolInformation() { + var json = serializer.SerializeObject(new SymbolInformation() { Kind = SymbolKind.Event }); - var result = serializer.DeserializeObject(json); + var result = serializer.DeserializeObject(json); result.Kind.Should().Be(SymbolKind.Class); } } -} \ No newline at end of file +} diff --git a/test/Lsp.Tests/Models/DocumentSymbolInformationTests.cs b/test/Lsp.Tests/Models/DocumentSymbolInformationTests.cs index 5b6ecd0cc..b9e404618 100644 --- a/test/Lsp.Tests/Models/DocumentSymbolInformationTests.cs +++ b/test/Lsp.Tests/Models/DocumentSymbolInformationTests.cs @@ -14,7 +14,7 @@ public class DocumentSymbolInformationTests [Theory, JsonFixture] public void SimpleTest(string expected) { - var model = new DocumentSymbolInformation() { + var model = new SymbolInformation() { ContainerName = "abc", Kind = SymbolKind.Boolean, Location = new Location() { @@ -27,7 +27,7 @@ public void SimpleTest(string expected) result.Should().Be(expected); - var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject(expected); + var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject(expected); deresult.Should().BeEquivalentTo(model); } } diff --git a/test/Lsp.Tests/Models/WorkspaceSymbolInformationTests.cs b/test/Lsp.Tests/Models/WorkspaceSymbolInformationTests.cs index 208c3c907..895a05d30 100644 --- a/test/Lsp.Tests/Models/WorkspaceSymbolInformationTests.cs +++ b/test/Lsp.Tests/Models/WorkspaceSymbolInformationTests.cs @@ -13,7 +13,7 @@ public class WorkspaceSymbolInformationTests [Theory, JsonFixture] public void SimpleTest(string expected) { - var model = new WorkspaceSymbolInformation() { + var model = new SymbolInformation() { ContainerName = "abc", Kind = SymbolKind.Boolean, Location = new Location() { @@ -26,7 +26,7 @@ public void SimpleTest(string expected) result.Should().Be(expected); - var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject(expected); + var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject(expected); deresult.Should().BeEquivalentTo(model); } } diff --git a/test/Lsp.Tests/WorkspaceSymbolKindTests.cs b/test/Lsp.Tests/WorkspaceSymbolKindTests.cs index 9a2516ed9..38a928b85 100644 --- a/test/Lsp.Tests/WorkspaceSymbolKindTests.cs +++ b/test/Lsp.Tests/WorkspaceSymbolKindTests.cs @@ -13,11 +13,11 @@ public class WorkspaceSymbolKindTests public void DefaultBehavior_Should_Only_Support_InitialKinds() { var serializer = new Serializer(); - var json = serializer.SerializeObject(new WorkspaceSymbolInformation() { + var json = serializer.SerializeObject(new SymbolInformation() { Kind = SymbolKind.Event }); - var result = serializer.DeserializeObject(json); + var result = serializer.DeserializeObject(json); result.Kind.Should().Be(SymbolKind.File); } @@ -35,12 +35,12 @@ public void CustomBehavior_When_Defined_By_Client() }) } }); - var json = serializer.SerializeObject(new WorkspaceSymbolInformation() { + var json = serializer.SerializeObject(new SymbolInformation() { Kind = SymbolKind.Event }); - var result = serializer.DeserializeObject(json); + var result = serializer.DeserializeObject(json); result.Kind.Should().Be(SymbolKind.Class); } } -} \ No newline at end of file +} From fb3bdfcbfcaef6d03c8ce2b05bdf52c933cddbda Mon Sep 17 00:00:00 2001 From: David Driscoll Date: Thu, 14 Mar 2019 09:07:12 -0400 Subject: [PATCH 3/5] Added support for lsp version 3.14.0 --- language-server-protocol.sha.txt | 4 +- src/Client/LspErrorCodes.cs | 5 + src/JsonRpc/AsyncRequestHandler.cs | 27 +++++ src/JsonRpc/IBaseRequest.cs | 7 ++ ...nRequestHandlers.cs => MediatRHandlers.cs} | 0 src/JsonRpc/NotificationHandler.cs | 25 ++++ src/JsonRpc/RequestHandler.cs | 24 ++++ src/JsonRpc/RequestHandlerDelegate.cs | 11 ++ src/JsonRpc/ServiceFactoryExtensions.cs | 13 ++ .../Capabilities/DeclarationCapability.cs | 6 + .../Capabilities/DefinitionCapability.cs | 2 +- .../Capabilities/ImplementationCapability.cs | 2 +- .../Capabilities/LinkSupportCapability.cs | 10 ++ .../SignatureInformationCapability.cs | 5 +- ...SignatureParameterInformationCapability.cs | 14 +++ .../TextDocumentClientCapabilities.cs | 5 + .../Capabilities/TypeDefinitionCapability.cs | 2 +- .../Capabilities/WorkspaceEditCapability.cs | 13 ++ .../Document/Client/DeclarationExtensions.cs | 17 +++ .../Document/Client/DefinitionExtensions.cs | 4 +- .../Client/ImplementationExtensions.cs | 4 +- .../Client/TypeDefinitionExtensions.cs | 4 +- .../Document/Server/IDeclarationHandler.cs | 12 ++ .../Document/Server/IDefinitionHandler.cs | 2 +- ...onHandler.cs => IImplementationHandler.cs} | 2 +- .../Document/Server/ITypeDefinitionHandler.cs | 2 +- src/Protocol/DocumentNames.cs | 1 + src/Protocol/Models/BooleanNumberString.cs | 40 +++---- src/Protocol/Models/BooleanString.cs | 25 ++-- src/Protocol/Models/CodeActionKind.cs | 1 - src/Protocol/Models/CreateFile.cs | 24 ++++ src/Protocol/Models/CreateFileOptions.cs | 21 ++++ src/Protocol/Models/DeclarationParams.cs | 9 ++ src/Protocol/Models/DefinitionParams.cs | 4 +- src/Protocol/Models/DeleteFile.cs | 24 ++++ src/Protocol/Models/DeleteFileOptions.cs | 21 ++++ src/Protocol/Models/Diagnostic.cs | 4 +- src/Protocol/Models/DiagnosticCode.cs | 1 - src/Protocol/Models/FailureHandlingKind.cs | 28 +++++ src/Protocol/Models/IFile.cs | 7 ++ ...tions.cs => IStaticRegistrationOptions.cs} | 0 src/Protocol/Models/ImplementationParams.cs | 4 +- src/Protocol/Models/LocationLink.cs | 35 ++++++ src/Protocol/Models/LocationOrLocationLink.cs | 36 ++++++ .../Models/LocationOrLocationLinks.cs | 38 ++++++ src/Protocol/Models/LocationOrLocations.cs | 37 ------ .../Models/MarkedStringsOrMarkupContent.cs | 2 +- src/Protocol/Models/ParameterInformation.cs | 2 +- .../Models/ParameterInformationLabel.cs | 28 +++++ src/Protocol/Models/PrepareRenameParams.cs | 9 -- src/Protocol/Models/RenameFile.cs | 28 +++++ src/Protocol/Models/RenameFileOptions.cs | 21 ++++ src/Protocol/Models/ResourceOperationKind.cs | 26 ++++ src/Protocol/Models/TypeDefinitionParams.cs | 2 +- src/Protocol/Models/WorkspaceEdit.cs | 9 +- .../Models/WorkspaceEditDocumentChange.cs | 72 +++++++++++ .../Serialization/ContractResolver.cs | 4 +- .../BooleanNumberStringConverter.cs | 12 +- .../Converters/BooleanStringConverter.cs | 13 +- .../Converters/DiagnosticCodeConverter.cs | 14 +-- .../LocationOrLocationLinkConverter.cs | 33 +++++ ...cs => LocationOrLocationLinksConverter.cs} | 14 +-- .../ParameterInformationLabelConverter.cs | 34 ++++++ .../WorkspaceEditDocumentChangeConverter.cs | 63 ++++++++++ .../{ILspSerializer.cs => ISerializer.cs} | 0 src/Protocol/Serialization/Serializer.cs | 8 +- .../Client/ClientCapabilitiesTests.cs | 14 ++- .../ClientCapabilitiesTests_$SimpleTest.json | 13 ++ ...ntClientCapabilitiesTests_$SimpleTest.json | 1 + ...ceClientCapabilitiesTests_$SimpleTest.json | 4 +- .../ClientCapabilityProviderFixture.cs | 27 ----- test/Lsp.Tests/FluentAssertionsExtensions.cs | 1 + .../Models/ApplyWorkspaceEditParamsTests.cs | 35 +++++- ...eEditParamsTests_$DocumentChangesTest.json | 25 ++++ .../InitializeParamsTests_$SimpleTest.json | 1 + .../Models/LocationOrLocationLinksTests.cs | 113 ++++++++++++++++++ ...rLocationLinksTests_$LocationLinkTest.json | 35 ++++++ ...LocationLinksTests_$LocationLinksTest.json | 68 +++++++++++ ...ionOrLocationLinksTests_$LocationTest.json | 13 ++ ...onOrLocationLinksTests_$LocationsTest.json | 28 +++++ ...tionOrLocationLinksTests_$SimpleTest.json} | 0 .../Models/LocationOrLocationsTests.cs | 26 ---- .../Models/ParameterInformationTests.cs | 2 +- .../Models/SignatureInformationTests.cs | 24 ++++ ...atureInformationTests_$ParamRangeTest.json | 13 ++ test/Lsp.Tests/Models/WorkspaceEditTests.cs | 28 ++++- ...rkspaceEditTests_$DocumentChangesTest.json | 25 ++++ .../Lsp.Tests/SupportedCapabilitiesFixture.cs | 34 ++++++ 88 files changed, 1294 insertions(+), 212 deletions(-) create mode 100644 src/JsonRpc/AsyncRequestHandler.cs create mode 100644 src/JsonRpc/IBaseRequest.cs rename src/JsonRpc/{ReflectionRequestHandlers.cs => MediatRHandlers.cs} (100%) create mode 100644 src/JsonRpc/NotificationHandler.cs create mode 100644 src/JsonRpc/RequestHandler.cs create mode 100644 src/JsonRpc/RequestHandlerDelegate.cs create mode 100644 src/JsonRpc/ServiceFactoryExtensions.cs create mode 100644 src/Protocol/Client/Capabilities/DeclarationCapability.cs create mode 100644 src/Protocol/Client/Capabilities/LinkSupportCapability.cs create mode 100644 src/Protocol/Client/Capabilities/SignatureParameterInformationCapability.cs create mode 100644 src/Protocol/Document/Client/DeclarationExtensions.cs create mode 100644 src/Protocol/Document/Server/IDeclarationHandler.cs rename src/Protocol/Document/Server/{IImplementationDefinitionHandler.cs => IImplementationHandler.cs} (73%) create mode 100644 src/Protocol/Models/CreateFile.cs create mode 100644 src/Protocol/Models/CreateFileOptions.cs create mode 100644 src/Protocol/Models/DeclarationParams.cs create mode 100644 src/Protocol/Models/DeleteFile.cs create mode 100644 src/Protocol/Models/DeleteFileOptions.cs create mode 100644 src/Protocol/Models/FailureHandlingKind.cs create mode 100644 src/Protocol/Models/IFile.cs rename src/Protocol/Models/{StaticRegistrationOptions.cs => IStaticRegistrationOptions.cs} (100%) create mode 100644 src/Protocol/Models/LocationLink.cs create mode 100644 src/Protocol/Models/LocationOrLocationLink.cs create mode 100644 src/Protocol/Models/LocationOrLocationLinks.cs delete mode 100644 src/Protocol/Models/LocationOrLocations.cs create mode 100644 src/Protocol/Models/ParameterInformationLabel.cs create mode 100644 src/Protocol/Models/RenameFile.cs create mode 100644 src/Protocol/Models/RenameFileOptions.cs create mode 100644 src/Protocol/Models/ResourceOperationKind.cs create mode 100644 src/Protocol/Models/WorkspaceEditDocumentChange.cs create mode 100644 src/Protocol/Serialization/Converters/LocationOrLocationLinkConverter.cs rename src/Protocol/Serialization/Converters/{LocationOrLocationsConverter.cs => LocationOrLocationLinksConverter.cs} (54%) create mode 100644 src/Protocol/Serialization/Converters/ParameterInformationLabelConverter.cs create mode 100644 src/Protocol/Serialization/Converters/WorkspaceEditDocumentChangeConverter.cs rename src/Protocol/Serialization/{ILspSerializer.cs => ISerializer.cs} (100%) create mode 100644 test/Lsp.Tests/Models/LocationOrLocationLinksTests.cs create mode 100644 test/Lsp.Tests/Models/LocationOrLocationLinksTests_$LocationLinkTest.json create mode 100644 test/Lsp.Tests/Models/LocationOrLocationLinksTests_$LocationLinksTest.json create mode 100644 test/Lsp.Tests/Models/LocationOrLocationLinksTests_$LocationTest.json create mode 100644 test/Lsp.Tests/Models/LocationOrLocationLinksTests_$LocationsTest.json rename test/Lsp.Tests/Models/{LocationOrLocationsTests_$SimpleTest.json => LocationOrLocationLinksTests_$SimpleTest.json} (100%) delete mode 100644 test/Lsp.Tests/Models/LocationOrLocationsTests.cs create mode 100644 test/Lsp.Tests/Models/SignatureInformationTests_$ParamRangeTest.json create mode 100644 test/Lsp.Tests/SupportedCapabilitiesFixture.cs diff --git a/language-server-protocol.sha.txt b/language-server-protocol.sha.txt index eef6dae17..4c2971e67 100644 --- a/language-server-protocol.sha.txt +++ b/language-server-protocol.sha.txt @@ -1,2 +1,4 @@ -- This is the last commit we caught up with https://github.com/Microsoft/language-server-protocol/commits/gh-pages -9e2713d5f1618b8d5e05a91a4e2c637aa51e1ee0 +lastSha: 1a69f1270d59cccd7b85e0697450950abd5a0221 + +https://github.com/Microsoft/language-server-protocol/compare/.. diff --git a/src/Client/LspErrorCodes.cs b/src/Client/LspErrorCodes.cs index 26564a2a7..a1be78995 100644 --- a/src/Client/LspErrorCodes.cs +++ b/src/Client/LspErrorCodes.cs @@ -44,5 +44,10 @@ public static class LspErrorCodes /// Request was cancelled. /// public const int RequestCancelled = -32800; + + /// + /// Request was cancelled. + /// + public const int ContentModified = -32801; } } diff --git a/src/JsonRpc/AsyncRequestHandler.cs b/src/JsonRpc/AsyncRequestHandler.cs new file mode 100644 index 000000000..ce3a18eed --- /dev/null +++ b/src/JsonRpc/AsyncRequestHandler.cs @@ -0,0 +1,27 @@ +using System.Threading; +using System.Threading.Tasks; + +namespace OmniSharp.Extensions.Embedded.MediatR +{ + /// + /// Wrapper class for a handler that asynchronously handles a request and does not return a response + /// + /// The type of request being handled + public abstract class AsyncRequestHandler : IRequestHandler + where TRequest : IRequest + { + async Task IRequestHandler.Handle(TRequest request, CancellationToken cancellationToken) + { + await Handle(request, cancellationToken).ConfigureAwait(false); + return Unit.Value; + } + + /// + /// Override in a derived class for the handler logic + /// + /// Request + /// + /// Response + protected abstract Task Handle(TRequest request, CancellationToken cancellationToken); + } +} \ No newline at end of file diff --git a/src/JsonRpc/IBaseRequest.cs b/src/JsonRpc/IBaseRequest.cs new file mode 100644 index 000000000..5fe2b1f96 --- /dev/null +++ b/src/JsonRpc/IBaseRequest.cs @@ -0,0 +1,7 @@ +namespace OmniSharp.Extensions.Embedded.MediatR +{ + /// + /// Allows for generic type constraints of objects implementing IRequest or IRequest{TResponse} + /// + public interface IBaseRequest { } +} \ No newline at end of file diff --git a/src/JsonRpc/ReflectionRequestHandlers.cs b/src/JsonRpc/MediatRHandlers.cs similarity index 100% rename from src/JsonRpc/ReflectionRequestHandlers.cs rename to src/JsonRpc/MediatRHandlers.cs diff --git a/src/JsonRpc/NotificationHandler.cs b/src/JsonRpc/NotificationHandler.cs new file mode 100644 index 000000000..05e80be5c --- /dev/null +++ b/src/JsonRpc/NotificationHandler.cs @@ -0,0 +1,25 @@ +using System.Threading; +using System.Threading.Tasks; + +namespace OmniSharp.Extensions.Embedded.MediatR +{ + /// + /// Wrapper class for a synchronous notification handler + /// + /// The notification type + public abstract class NotificationHandler : INotificationHandler + where TNotification : INotification + { + Task INotificationHandler.Handle(TNotification notification, CancellationToken cancellationToken) + { + Handle(notification); + return Unit.Task; + } + + /// + /// Override in a derived class for the handler logic + /// + /// Notification + protected abstract void Handle(TNotification notification); + } +} \ No newline at end of file diff --git a/src/JsonRpc/RequestHandler.cs b/src/JsonRpc/RequestHandler.cs new file mode 100644 index 000000000..bd0287621 --- /dev/null +++ b/src/JsonRpc/RequestHandler.cs @@ -0,0 +1,24 @@ +using System.Threading; +using System.Threading.Tasks; + +namespace OmniSharp.Extensions.Embedded.MediatR +{ + /// + /// Wrapper class for a handler that synchronously handles a request and returns a response + /// + /// The type of request being handled + /// The type of response from the handler + public abstract class RequestHandler : IRequestHandler + where TRequest : IRequest + { + Task IRequestHandler.Handle(TRequest request, CancellationToken cancellationToken) + => Task.FromResult(Handle(request)); + + /// + /// Override in a derived class for the handler logic + /// + /// Request + /// Response + protected abstract TResponse Handle(TRequest request); + } +} \ No newline at end of file diff --git a/src/JsonRpc/RequestHandlerDelegate.cs b/src/JsonRpc/RequestHandlerDelegate.cs new file mode 100644 index 000000000..5f8d314af --- /dev/null +++ b/src/JsonRpc/RequestHandlerDelegate.cs @@ -0,0 +1,11 @@ +using System.Threading.Tasks; + +namespace OmniSharp.Extensions.Embedded.MediatR +{ + /// + /// Represents an async continuation for the next task to execute in the pipeline + /// + /// Response type + /// Awaitable task returning a + public delegate Task RequestHandlerDelegate(); +} \ No newline at end of file diff --git a/src/JsonRpc/ServiceFactoryExtensions.cs b/src/JsonRpc/ServiceFactoryExtensions.cs new file mode 100644 index 000000000..fe031d608 --- /dev/null +++ b/src/JsonRpc/ServiceFactoryExtensions.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; + +namespace OmniSharp.Extensions.Embedded.MediatR +{ + public static class ServiceFactoryExtensions + { + public static T GetInstance(this ServiceFactory factory) + => (T) factory(typeof(T)); + + public static IEnumerable GetInstances(this ServiceFactory factory) + => (IEnumerable) factory(typeof(IEnumerable)); + } +} \ No newline at end of file diff --git a/src/Protocol/Client/Capabilities/DeclarationCapability.cs b/src/Protocol/Client/Capabilities/DeclarationCapability.cs new file mode 100644 index 000000000..708cb784c --- /dev/null +++ b/src/Protocol/Client/Capabilities/DeclarationCapability.cs @@ -0,0 +1,6 @@ +using OmniSharp.Extensions.LanguageServer.Protocol.Server; + +namespace OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities +{ + public class DeclarationCapability : LinkSupportCapability, ConnectedCapability { } +} diff --git a/src/Protocol/Client/Capabilities/DefinitionCapability.cs b/src/Protocol/Client/Capabilities/DefinitionCapability.cs index c9bf1794d..63ca3d82d 100644 --- a/src/Protocol/Client/Capabilities/DefinitionCapability.cs +++ b/src/Protocol/Client/Capabilities/DefinitionCapability.cs @@ -2,5 +2,5 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities { - public class DefinitionCapability : DynamicCapability, ConnectedCapability { } + public class DefinitionCapability : LinkSupportCapability, ConnectedCapability { } } diff --git a/src/Protocol/Client/Capabilities/ImplementationCapability.cs b/src/Protocol/Client/Capabilities/ImplementationCapability.cs index 1a738f293..4e39ab4c1 100644 --- a/src/Protocol/Client/Capabilities/ImplementationCapability.cs +++ b/src/Protocol/Client/Capabilities/ImplementationCapability.cs @@ -2,5 +2,5 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities { - public class ImplementationCapability : DynamicCapability, ConnectedCapability {} + public class ImplementationCapability : LinkSupportCapability, ConnectedCapability {} } diff --git a/src/Protocol/Client/Capabilities/LinkSupportCapability.cs b/src/Protocol/Client/Capabilities/LinkSupportCapability.cs new file mode 100644 index 000000000..7bdb8d16b --- /dev/null +++ b/src/Protocol/Client/Capabilities/LinkSupportCapability.cs @@ -0,0 +1,10 @@ +using OmniSharp.Extensions.LanguageServer.Protocol.Serialization; + +namespace OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities +{ + public abstract class LinkSupportCapability : DynamicCapability + { + [Optional] + public bool LinkSupport { get; set; } + } +} diff --git a/src/Protocol/Client/Capabilities/SignatureInformationCapability.cs b/src/Protocol/Client/Capabilities/SignatureInformationCapability.cs index 2e999b06a..f71467dfa 100644 --- a/src/Protocol/Client/Capabilities/SignatureInformationCapability.cs +++ b/src/Protocol/Client/Capabilities/SignatureInformationCapability.cs @@ -10,6 +10,9 @@ public class SignatureInformationCapability /// Client supports the follow content formats for the content property. The order describes the preferred format of the client. /// [Optional] - public Container ContentFormat { get; set; } + public Container DocumentationFormat { get; set; } + + [Optional] + public SignatureParameterInformationCapability ParameterInformation { get; set; } } } diff --git a/src/Protocol/Client/Capabilities/SignatureParameterInformationCapability.cs b/src/Protocol/Client/Capabilities/SignatureParameterInformationCapability.cs new file mode 100644 index 000000000..90f598927 --- /dev/null +++ b/src/Protocol/Client/Capabilities/SignatureParameterInformationCapability.cs @@ -0,0 +1,14 @@ +using OmniSharp.Extensions.LanguageServer.Protocol.Serialization; + +namespace OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities +{ + public class SignatureParameterInformationCapability + { + /// + /// The client supports processing label offsets instead of a + /// simple label string. + /// + [Optional] + public bool LabelOffsetSupport { get; set; } + } +} diff --git a/src/Protocol/Client/Capabilities/TextDocumentClientCapabilities.cs b/src/Protocol/Client/Capabilities/TextDocumentClientCapabilities.cs index 0b7cddee5..2f0e1c3ab 100644 --- a/src/Protocol/Client/Capabilities/TextDocumentClientCapabilities.cs +++ b/src/Protocol/Client/Capabilities/TextDocumentClientCapabilities.cs @@ -58,6 +58,11 @@ public class TextDocumentClientCapabilities /// public Supports Definition { get; set; } + /// + /// Capabilities specific to the `textDocument/declaration` + /// + public Supports Declaration { get; set; } + /// /// Capabilities specific to the `textDocument/codeAction` /// diff --git a/src/Protocol/Client/Capabilities/TypeDefinitionCapability.cs b/src/Protocol/Client/Capabilities/TypeDefinitionCapability.cs index eb13ea117..fc505bb25 100644 --- a/src/Protocol/Client/Capabilities/TypeDefinitionCapability.cs +++ b/src/Protocol/Client/Capabilities/TypeDefinitionCapability.cs @@ -2,5 +2,5 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities { - public class TypeDefinitionCapability : DynamicCapability, ConnectedCapability {} + public class TypeDefinitionCapability : LinkSupportCapability, ConnectedCapability {} } diff --git a/src/Protocol/Client/Capabilities/WorkspaceEditCapability.cs b/src/Protocol/Client/Capabilities/WorkspaceEditCapability.cs index bbcf92dbe..767856e3e 100644 --- a/src/Protocol/Client/Capabilities/WorkspaceEditCapability.cs +++ b/src/Protocol/Client/Capabilities/WorkspaceEditCapability.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json; using Newtonsoft.Json.Serialization; +using OmniSharp.Extensions.LanguageServer.Protocol.Models; using OmniSharp.Extensions.LanguageServer.Protocol.Serialization; namespace OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities @@ -11,5 +12,17 @@ public class WorkspaceEditCapability /// [Optional] public bool DocumentChanges { get; set; } + /// + /// The resource operations the client supports. Clients should at least + /// support 'create', 'rename' and 'delete' files and folders. + /// + [Optional] + public ResourceOperationKind[] ResourceOperations { get; set; } + /// + /// The failure handling strategy of a client if applying the workspace edit + /// fails. + /// + [Optional] + public FailureHandlingKind? FailureHandling { get; set; } } } diff --git a/src/Protocol/Document/Client/DeclarationExtensions.cs b/src/Protocol/Document/Client/DeclarationExtensions.cs new file mode 100644 index 000000000..0767ba02b --- /dev/null +++ b/src/Protocol/Document/Client/DeclarationExtensions.cs @@ -0,0 +1,17 @@ +using System.Threading.Tasks; +using OmniSharp.Extensions.JsonRpc; +using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities; +using OmniSharp.Extensions.LanguageServer.Protocol.Models; + +// ReSharper disable CheckNamespace + +namespace OmniSharp.Extensions.LanguageServer.Protocol.Client +{ + public static class DeclarationExtensions + { + public static Task Declaration(this ILanguageClientDocument mediator, DeclarationParams @params) + { + return mediator.SendRequest(DocumentNames.Declaration, @params); + } + } +} diff --git a/src/Protocol/Document/Client/DefinitionExtensions.cs b/src/Protocol/Document/Client/DefinitionExtensions.cs index 114b036f9..615111139 100644 --- a/src/Protocol/Document/Client/DefinitionExtensions.cs +++ b/src/Protocol/Document/Client/DefinitionExtensions.cs @@ -9,9 +9,9 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Client { public static class DefinitionExtensions { - public static Task Definition(this ILanguageClientDocument mediator, DefinitionParams @params) + public static Task Definition(this ILanguageClientDocument mediator, DefinitionParams @params) { - return mediator.SendRequest(DocumentNames.Definition, @params); + return mediator.SendRequest(DocumentNames.Definition, @params); } } } diff --git a/src/Protocol/Document/Client/ImplementationExtensions.cs b/src/Protocol/Document/Client/ImplementationExtensions.cs index 07481460f..8ceb29c81 100644 --- a/src/Protocol/Document/Client/ImplementationExtensions.cs +++ b/src/Protocol/Document/Client/ImplementationExtensions.cs @@ -9,9 +9,9 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Client { public static class ImplementationExtensions { - public static Task Implementation(this ILanguageClientDocument mediator, ImplementationParams @params) + public static Task Implementation(this ILanguageClientDocument mediator, ImplementationParams @params) { - return mediator.SendRequest(DocumentNames.Implementation, @params); + return mediator.SendRequest(DocumentNames.Implementation, @params); } } } diff --git a/src/Protocol/Document/Client/TypeDefinitionExtensions.cs b/src/Protocol/Document/Client/TypeDefinitionExtensions.cs index f2c450349..2ae31c0d0 100644 --- a/src/Protocol/Document/Client/TypeDefinitionExtensions.cs +++ b/src/Protocol/Document/Client/TypeDefinitionExtensions.cs @@ -9,9 +9,9 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Client { public static class TypeDefinitionExtensions { - public static Task TypeDefinition(this ILanguageClientDocument mediator, TypeDefinitionParams @params) + public static Task TypeDefinition(this ILanguageClientDocument mediator, TypeDefinitionParams @params) { - return mediator.SendRequest(DocumentNames.TypeDefinition, @params); + return mediator.SendRequest(DocumentNames.TypeDefinition, @params); } } } diff --git a/src/Protocol/Document/Server/IDeclarationHandler.cs b/src/Protocol/Document/Server/IDeclarationHandler.cs new file mode 100644 index 000000000..6773026f6 --- /dev/null +++ b/src/Protocol/Document/Server/IDeclarationHandler.cs @@ -0,0 +1,12 @@ +using OmniSharp.Extensions.JsonRpc; +using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities; +using OmniSharp.Extensions.LanguageServer.Protocol.Models; + +// ReSharper disable CheckNamespace + +namespace OmniSharp.Extensions.LanguageServer.Protocol.Server +{ + using static DocumentNames; + [Parallel, Method(Declaration)] + public interface IDeclarationHandler : IJsonRpcRequestHandler, IRegistration, ICapability { } +} diff --git a/src/Protocol/Document/Server/IDefinitionHandler.cs b/src/Protocol/Document/Server/IDefinitionHandler.cs index 75465faaf..bd35d37b4 100644 --- a/src/Protocol/Document/Server/IDefinitionHandler.cs +++ b/src/Protocol/Document/Server/IDefinitionHandler.cs @@ -8,5 +8,5 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Server { using static DocumentNames; [Parallel, Method(Definition)] - public interface IDefinitionHandler : IJsonRpcRequestHandler, IRegistration, ICapability { } + public interface IDefinitionHandler : IJsonRpcRequestHandler, IRegistration, ICapability { } } diff --git a/src/Protocol/Document/Server/IImplementationDefinitionHandler.cs b/src/Protocol/Document/Server/IImplementationHandler.cs similarity index 73% rename from src/Protocol/Document/Server/IImplementationDefinitionHandler.cs rename to src/Protocol/Document/Server/IImplementationHandler.cs index bc69d9492..5a65b256f 100644 --- a/src/Protocol/Document/Server/IImplementationDefinitionHandler.cs +++ b/src/Protocol/Document/Server/IImplementationHandler.cs @@ -8,5 +8,5 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Server { using static DocumentNames; [Parallel, Method(Implementation)] - public interface IImplementationHandler : IJsonRpcRequestHandler, IRegistration, ICapability { } + public interface IImplementationHandler : IJsonRpcRequestHandler, IRegistration, ICapability { } } diff --git a/src/Protocol/Document/Server/ITypeDefinitionHandler.cs b/src/Protocol/Document/Server/ITypeDefinitionHandler.cs index e004972bd..da2cba558 100644 --- a/src/Protocol/Document/Server/ITypeDefinitionHandler.cs +++ b/src/Protocol/Document/Server/ITypeDefinitionHandler.cs @@ -8,5 +8,5 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Server { using static DocumentNames; [Parallel, Method(TypeDefinition)] - public interface ITypeDefinitionHandler : IJsonRpcRequestHandler, IRegistration, ICapability { } + public interface ITypeDefinitionHandler : IJsonRpcRequestHandler, IRegistration, ICapability { } } diff --git a/src/Protocol/DocumentNames.cs b/src/Protocol/DocumentNames.cs index ec7b249db..d62cc7701 100644 --- a/src/Protocol/DocumentNames.cs +++ b/src/Protocol/DocumentNames.cs @@ -9,6 +9,7 @@ public static class DocumentNames public const string Completion = "textDocument/completion"; public const string CompletionResolve = "completionItem/resolve"; public const string Definition = "textDocument/definition"; + public const string Declaration = "textDocument/declaration"; public const string DidChange = "textDocument/didChange"; public const string DidClose = "textDocument/didClose"; public const string DidOpen = "textDocument/didOpen"; diff --git a/src/Protocol/Models/BooleanNumberString.cs b/src/Protocol/Models/BooleanNumberString.cs index 14aa6534d..aee1bde58 100644 --- a/src/Protocol/Models/BooleanNumberString.cs +++ b/src/Protocol/Models/BooleanNumberString.cs @@ -27,49 +27,39 @@ public BooleanNumberString(bool value) _bool = value; } - public bool IsLong => this._long.HasValue; + public bool IsLong => _long.HasValue; public long Long { - get { return _long ?? 0; } + get => _long ?? 0; set { - this.String = null; - this._long = value; - this._bool = null; + String = null; + _long = value; + _bool = null; } } - public bool IsString => this._string != null; + public bool IsString => _string != null; public string String { - get { return this._string; } + get => _string; set { - this._string = value; - this._long = null; - this._bool = null; + _string = value; + _long = null; + _bool = null; } } - public bool IsBool => this._bool.HasValue; + public bool IsBool => _bool.HasValue; public bool Bool { - get { return this._bool.HasValue && this._bool.Value; } + get => _bool.HasValue && _bool.Value; set { - this.String = null; - this._long = null; - this._bool = value; - } - } - public object Value - { - get - { - if (IsBool) return Bool; - if (IsLong) return Long; - if (IsString) return String; - return null; + String = null; + _long = null; + _bool = value; } } diff --git a/src/Protocol/Models/BooleanString.cs b/src/Protocol/Models/BooleanString.cs index cb86b25af..327ef9f17 100644 --- a/src/Protocol/Models/BooleanString.cs +++ b/src/Protocol/Models/BooleanString.cs @@ -15,34 +15,25 @@ public BooleanString(bool value) _bool = value; } - public bool IsString => this._string != null; + public bool IsString => _string != null; public string String { - get { return this._string; } + get => _string; set { - this._string = value; - this._bool = null; + _string = value; + _bool = null; } } - public bool IsBool => this._bool.HasValue; + public bool IsBool => _bool.HasValue; public bool Bool { - get { return this._bool.HasValue && this._bool.Value; } + get => _bool.HasValue && _bool.Value; set { - this.String = null; - this._bool = value; - } - } - public object Value - { - get - { - if (IsBool) return Bool; - if (IsString) return String; - return null; + String = null; + _bool = value; } } diff --git a/src/Protocol/Models/CodeActionKind.cs b/src/Protocol/Models/CodeActionKind.cs index 61cf6bfba..6a6f6dada 100644 --- a/src/Protocol/Models/CodeActionKind.cs +++ b/src/Protocol/Models/CodeActionKind.cs @@ -76,6 +76,5 @@ public CodeActionKind(string kind) } public string Kind { get; } - } } diff --git a/src/Protocol/Models/CreateFile.cs b/src/Protocol/Models/CreateFile.cs new file mode 100644 index 000000000..1225c1f99 --- /dev/null +++ b/src/Protocol/Models/CreateFile.cs @@ -0,0 +1,24 @@ +using OmniSharp.Extensions.LanguageServer.Protocol.Serialization; + +namespace OmniSharp.Extensions.LanguageServer.Protocol.Models +{ + /// + /// Create file operation + /// + public class CreateFile : IFile + { + /// + /// A create + /// + public ResourceOperationKind Kind { get; } = ResourceOperationKind.Create; + /// + /// The resource to create. + /// + public string Uri { get; set; } + /// + /// Additional Options + /// + [Optional] + public CreateFileOptions Options { get; set; } + } +} diff --git a/src/Protocol/Models/CreateFileOptions.cs b/src/Protocol/Models/CreateFileOptions.cs new file mode 100644 index 000000000..2661cd28b --- /dev/null +++ b/src/Protocol/Models/CreateFileOptions.cs @@ -0,0 +1,21 @@ +using OmniSharp.Extensions.LanguageServer.Protocol.Serialization; + +namespace OmniSharp.Extensions.LanguageServer.Protocol.Models +{ + /// + /// Options to create a file. + /// + public class CreateFileOptions + { + /// + /// Overwrite existing file. Overwrite wins over `ignoreIfExists` + /// + [Optional] + public bool Overwrite { get; set; } + /// + /// Ignore if exists. + /// + [Optional] + public bool IgnoreIfExists { get; set; } + } +} diff --git a/src/Protocol/Models/DeclarationParams.cs b/src/Protocol/Models/DeclarationParams.cs new file mode 100644 index 000000000..fbd4e9b35 --- /dev/null +++ b/src/Protocol/Models/DeclarationParams.cs @@ -0,0 +1,9 @@ +using OmniSharp.Extensions.Embedded.MediatR; + +namespace OmniSharp.Extensions.LanguageServer.Protocol.Models +{ + public class DeclarationParams : TextDocumentPositionParams, IRequest + { + + } +} diff --git a/src/Protocol/Models/DefinitionParams.cs b/src/Protocol/Models/DefinitionParams.cs index 5d86f3440..a3364358f 100644 --- a/src/Protocol/Models/DefinitionParams.cs +++ b/src/Protocol/Models/DefinitionParams.cs @@ -2,8 +2,8 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Models { - public class DefinitionParams : TextDocumentPositionParams, IRequest + public class DefinitionParams : TextDocumentPositionParams, IRequest { } -} \ No newline at end of file +} diff --git a/src/Protocol/Models/DeleteFile.cs b/src/Protocol/Models/DeleteFile.cs new file mode 100644 index 000000000..d6a0ad261 --- /dev/null +++ b/src/Protocol/Models/DeleteFile.cs @@ -0,0 +1,24 @@ +using OmniSharp.Extensions.LanguageServer.Protocol.Serialization; + +namespace OmniSharp.Extensions.LanguageServer.Protocol.Models +{ + /// + /// Delete file operation + /// + public class DeleteFile : IFile + { + /// + /// A delete + /// + public ResourceOperationKind Kind { get; } = ResourceOperationKind.Delete; + /// + /// The file to delete. + /// + public string Uri { get; set; } + /// + /// Delete Options. + /// + [Optional] + public DeleteFileOptions Options { get; set; } + } +} diff --git a/src/Protocol/Models/DeleteFileOptions.cs b/src/Protocol/Models/DeleteFileOptions.cs new file mode 100644 index 000000000..8348381e0 --- /dev/null +++ b/src/Protocol/Models/DeleteFileOptions.cs @@ -0,0 +1,21 @@ +using OmniSharp.Extensions.LanguageServer.Protocol.Serialization; + +namespace OmniSharp.Extensions.LanguageServer.Protocol.Models +{ + /// + /// Delete file Options + /// + public class DeleteFileOptions + { + /// + /// Delete the content recursively if a folder is denoted. + /// + [Optional] + public bool Recursive { get; set; } + /// + /// Ignore the operation if the file doesn't exist. + /// + [Optional] + public bool IgnoreIfNotExists { get; set; } + } +} diff --git a/src/Protocol/Models/Diagnostic.cs b/src/Protocol/Models/Diagnostic.cs index 3dff51451..12a9c6f44 100644 --- a/src/Protocol/Models/Diagnostic.cs +++ b/src/Protocol/Models/Diagnostic.cs @@ -1,10 +1,10 @@ -using Newtonsoft.Json; +using System; +using Newtonsoft.Json; using Newtonsoft.Json.Serialization; using OmniSharp.Extensions.LanguageServer.Protocol.Serialization; namespace OmniSharp.Extensions.LanguageServer.Protocol.Models { - public class Diagnostic { /// diff --git a/src/Protocol/Models/DiagnosticCode.cs b/src/Protocol/Models/DiagnosticCode.cs index 88b73792d..7a8add842 100644 --- a/src/Protocol/Models/DiagnosticCode.cs +++ b/src/Protocol/Models/DiagnosticCode.cs @@ -18,7 +18,6 @@ public DiagnosticCode(string value) public long Long { get; set; } public bool IsString => this.String != null; public string String { get; set; } - public object Value => String ?? (object)Long; public static implicit operator DiagnosticCode(long value) { diff --git a/src/Protocol/Models/FailureHandlingKind.cs b/src/Protocol/Models/FailureHandlingKind.cs new file mode 100644 index 000000000..f341d51a5 --- /dev/null +++ b/src/Protocol/Models/FailureHandlingKind.cs @@ -0,0 +1,28 @@ +using System.Runtime.Serialization; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace OmniSharp.Extensions.LanguageServer.Protocol.Models +{ + [JsonConverter(typeof(StringEnumConverter))] + public enum FailureHandlingKind + { + /// + /// All operations are executed transactional. That means they either all + /// succeed or no changes at all are applied to the workspace. + /// + [EnumMember(Value = "abort")] + Abort, + /// + /// All operations are executed transactional. That means they either all + /// succeed or no changes at all are applied to the workspace. + /// + [EnumMember(Value = "transactional")] + Transactional, + /// + ///Supports deleting existing files and folders. + /// + [EnumMember(Value = "delete")] + Delete, + } +} diff --git a/src/Protocol/Models/IFile.cs b/src/Protocol/Models/IFile.cs new file mode 100644 index 000000000..4aa1df1cb --- /dev/null +++ b/src/Protocol/Models/IFile.cs @@ -0,0 +1,7 @@ +namespace OmniSharp.Extensions.LanguageServer.Protocol.Models +{ + public interface IFile + { + ResourceOperationKind Kind { get; } + } +} diff --git a/src/Protocol/Models/StaticRegistrationOptions.cs b/src/Protocol/Models/IStaticRegistrationOptions.cs similarity index 100% rename from src/Protocol/Models/StaticRegistrationOptions.cs rename to src/Protocol/Models/IStaticRegistrationOptions.cs diff --git a/src/Protocol/Models/ImplementationParams.cs b/src/Protocol/Models/ImplementationParams.cs index 3946f9f91..50c0d2372 100644 --- a/src/Protocol/Models/ImplementationParams.cs +++ b/src/Protocol/Models/ImplementationParams.cs @@ -2,8 +2,8 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Models { - public class ImplementationParams : TextDocumentPositionParams, IRequest + public class ImplementationParams : TextDocumentPositionParams, IRequest { } -} \ No newline at end of file +} diff --git a/src/Protocol/Models/LocationLink.cs b/src/Protocol/Models/LocationLink.cs new file mode 100644 index 000000000..60389252f --- /dev/null +++ b/src/Protocol/Models/LocationLink.cs @@ -0,0 +1,35 @@ +using System; +using OmniSharp.Extensions.LanguageServer.Protocol.Serialization; + +namespace OmniSharp.Extensions.LanguageServer.Protocol.Models +{ + public class LocationLink + { + /// + /// Span of the origin of this link. + /// + /// Used as the underlined span for mouse interaction. Defaults to the word range at + /// the mouse position. + /// + [Optional] + public Range OriginSelectionRange { get; set; } + + /// + /// The target resource identifier of this link. + /// + public Uri TargetUri { get; set; } + + /// + /// The full target range of this link. If the target for example is a symbol then target range is the + /// range enclosing this symbol not including leading/trailing whitespace but everything else + /// like comments. This information is typically used to highlight the range in the editor. + /// + public Range TargetRange { get; set; } + + /// + /// The range that should be selected and revealed when this link is being followed, e.g the name of a function. + /// Must be contained by the the `targetRange`. See also `DocumentSymbol#range` + /// + public Range TargetSelectionRange { get; set; } + } +} \ No newline at end of file diff --git a/src/Protocol/Models/LocationOrLocationLink.cs b/src/Protocol/Models/LocationOrLocationLink.cs new file mode 100644 index 000000000..c6e7536bd --- /dev/null +++ b/src/Protocol/Models/LocationOrLocationLink.cs @@ -0,0 +1,36 @@ +using Newtonsoft.Json; +using OmniSharp.Extensions.LanguageServer.Protocol.Serialization.Converters; + +namespace OmniSharp.Extensions.LanguageServer.Protocol.Models +{ + public struct LocationOrLocationLink { + + public LocationOrLocationLink(Location location) + { + Location = location; + LocationLink = null; + } + + public LocationOrLocationLink(LocationLink locationLink) + { + Location = null; + LocationLink = locationLink; + } + + public bool IsLocation => Location != null; + public Location Location { get; } + + public bool IsLocationLink => LocationLink != null; + public LocationLink LocationLink { get; } + + public static implicit operator LocationOrLocationLink(Location location) + { + return new LocationOrLocationLink(location); + } + + public static implicit operator LocationOrLocationLink(LocationLink locationLink) + { + return new LocationOrLocationLink(locationLink); + } + } +} diff --git a/src/Protocol/Models/LocationOrLocationLinks.cs b/src/Protocol/Models/LocationOrLocationLinks.cs new file mode 100644 index 000000000..a80338fd5 --- /dev/null +++ b/src/Protocol/Models/LocationOrLocationLinks.cs @@ -0,0 +1,38 @@ +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using Newtonsoft.Json; +using OmniSharp.Extensions.LanguageServer.Protocol.Serialization.Converters; + +namespace OmniSharp.Extensions.LanguageServer.Protocol.Models +{ + public class LocationOrLocationLinks : ContainerBase + { + public LocationOrLocationLinks() : this(Enumerable.Empty()) + { + } + + public LocationOrLocationLinks(IEnumerable items) : base(items) + { + } + + public LocationOrLocationLinks(params LocationOrLocationLink[] items) : base(items) + { + } + + public static implicit operator LocationOrLocationLinks(LocationOrLocationLink[] items) + { + return new LocationOrLocationLinks(items); + } + + public static implicit operator LocationOrLocationLinks(Collection items) + { + return new LocationOrLocationLinks(items); + } + + public static implicit operator LocationOrLocationLinks(List items) + { + return new LocationOrLocationLinks(items); + } + } +} diff --git a/src/Protocol/Models/LocationOrLocations.cs b/src/Protocol/Models/LocationOrLocations.cs deleted file mode 100644 index e7633e931..000000000 --- a/src/Protocol/Models/LocationOrLocations.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using Newtonsoft.Json; - -namespace OmniSharp.Extensions.LanguageServer.Protocol.Models -{ - public class LocationOrLocations : ContainerBase - { - public LocationOrLocations() : this(Enumerable.Empty()) - { - } - - public LocationOrLocations(IEnumerable items) : base(items) - { - } - - public LocationOrLocations(params Location[] items) : base(items) - { - } - - public static implicit operator LocationOrLocations(Location[] items) - { - return new LocationOrLocations(items); - } - - public static implicit operator LocationOrLocations(Collection items) - { - return new LocationOrLocations(items); - } - - public static implicit operator LocationOrLocations(List items) - { - return new LocationOrLocations(items); - } - } -} diff --git a/src/Protocol/Models/MarkedStringsOrMarkupContent.cs b/src/Protocol/Models/MarkedStringsOrMarkupContent.cs index d4e4847ea..8ed1f3d34 100644 --- a/src/Protocol/Models/MarkedStringsOrMarkupContent.cs +++ b/src/Protocol/Models/MarkedStringsOrMarkupContent.cs @@ -21,7 +21,7 @@ public MarkedStringsOrMarkupContent(MarkupContent markupContent) } public MarkedStringContainer MarkedStrings { get; } - public bool HasMarkedStrings => this.MarkupContent == null; + public bool HasMarkedStrings => MarkupContent == null; public MarkupContent MarkupContent { get; } public bool HasMarkupContent => MarkedStrings == null; } diff --git a/src/Protocol/Models/ParameterInformation.cs b/src/Protocol/Models/ParameterInformation.cs index de27bce5b..9ba8a7b54 100644 --- a/src/Protocol/Models/ParameterInformation.cs +++ b/src/Protocol/Models/ParameterInformation.cs @@ -14,7 +14,7 @@ public class ParameterInformation /// The label of this parameter. Will be shown in /// the UI. /// - public string Label { get; set; } + public ParameterInformationLabel Label { get; set; } /// /// The human-readable doc-comment of this parameter. Will be shown diff --git a/src/Protocol/Models/ParameterInformationLabel.cs b/src/Protocol/Models/ParameterInformationLabel.cs new file mode 100644 index 000000000..98cd4ebeb --- /dev/null +++ b/src/Protocol/Models/ParameterInformationLabel.cs @@ -0,0 +1,28 @@ +namespace OmniSharp.Extensions.LanguageServer.Protocol.Models +{ + public class ParameterInformationLabel + { + public ParameterInformationLabel((long start, long end) range) + { + Range = range; + } + + public ParameterInformationLabel(string label) + { + Label = label; + } + + public (long start, long end) Range { get; } + public bool IsRange => Label == null; + public string Label { get; } + public bool IsLabel => Label != null; + + public static implicit operator ParameterInformationLabel(string label) { + return new ParameterInformationLabel(label); + } + + public static implicit operator ParameterInformationLabel((long start, long end) range) { + return new ParameterInformationLabel(range); + } + } +} diff --git a/src/Protocol/Models/PrepareRenameParams.cs b/src/Protocol/Models/PrepareRenameParams.cs index 1e52c73eb..d124facf2 100644 --- a/src/Protocol/Models/PrepareRenameParams.cs +++ b/src/Protocol/Models/PrepareRenameParams.cs @@ -4,14 +4,5 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Models { public class PrepareRenameParams : TextDocumentPositionParams, IRequest { - /// - /// The text document. - /// - public TextDocumentIdentifier TextDocument { get; set; } - - /// - /// The position inside the text document. - /// - public Position Position { get; set; } } } diff --git a/src/Protocol/Models/RenameFile.cs b/src/Protocol/Models/RenameFile.cs new file mode 100644 index 000000000..5f3f1176c --- /dev/null +++ b/src/Protocol/Models/RenameFile.cs @@ -0,0 +1,28 @@ +using OmniSharp.Extensions.LanguageServer.Protocol.Serialization; + +namespace OmniSharp.Extensions.LanguageServer.Protocol.Models +{ + /// + /// Rename file operation + /// + public class RenameFile : IFile + { + /// + /// A rename + /// + public ResourceOperationKind Kind { get; } = ResourceOperationKind.Rename; + /// + /// The old (existing) location. + /// + public string OldUri { get; set; } + /// + /// The new location. + /// + public string NewUri { get; set; } + /// + /// Rename Options. + /// + [Optional] + public RenameFileOptions Options { get; set; } + } +} diff --git a/src/Protocol/Models/RenameFileOptions.cs b/src/Protocol/Models/RenameFileOptions.cs new file mode 100644 index 000000000..7f86d458f --- /dev/null +++ b/src/Protocol/Models/RenameFileOptions.cs @@ -0,0 +1,21 @@ +using OmniSharp.Extensions.LanguageServer.Protocol.Serialization; + +namespace OmniSharp.Extensions.LanguageServer.Protocol.Models +{ + /// + /// Rename file Options + /// + public class RenameFileOptions + { + /// + /// Overwrite target if existing. Overwrite wins over `ignoreIfExists` + /// + [Optional] + public bool Overwrite { get; set; } + /// + /// Ignores if target exists. + /// + [Optional] + public bool IgnoreIfExists { get; set; } + } +} diff --git a/src/Protocol/Models/ResourceOperationKind.cs b/src/Protocol/Models/ResourceOperationKind.cs new file mode 100644 index 000000000..4319f902a --- /dev/null +++ b/src/Protocol/Models/ResourceOperationKind.cs @@ -0,0 +1,26 @@ +using System.Runtime.Serialization; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace OmniSharp.Extensions.LanguageServer.Protocol.Models +{ + [JsonConverter(typeof(StringEnumConverter))] + public enum ResourceOperationKind + { + /// + ///Supports creating new files and folders. + /// + [EnumMember(Value = "create")] + Create, + /// + ///Supports renaming existing files and folders. + /// + [EnumMember(Value = "rename")] + Rename, + /// + ///Supports deleting existing files and folders. + /// + [EnumMember(Value = "delete")] + Delete, + } +} diff --git a/src/Protocol/Models/TypeDefinitionParams.cs b/src/Protocol/Models/TypeDefinitionParams.cs index 11e7aafa4..ebc2e337f 100644 --- a/src/Protocol/Models/TypeDefinitionParams.cs +++ b/src/Protocol/Models/TypeDefinitionParams.cs @@ -2,7 +2,7 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Models { - public class TypeDefinitionParams : TextDocumentPositionParams, IRequest + public class TypeDefinitionParams : TextDocumentPositionParams, IRequest { } diff --git a/src/Protocol/Models/WorkspaceEdit.cs b/src/Protocol/Models/WorkspaceEdit.cs index 54e3b794e..4af14fb66 100644 --- a/src/Protocol/Models/WorkspaceEdit.cs +++ b/src/Protocol/Models/WorkspaceEdit.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using Newtonsoft.Json; using Newtonsoft.Json.Serialization; using OmniSharp.Extensions.LanguageServer.Protocol.Serialization; @@ -16,10 +15,16 @@ public class WorkspaceEdit /// /// An array of `TextDocumentEdit`s to express changes to n different text documents /// where each text document edit addresses a specific version of a text document. + /// where each text document edit addresses a specific version of a text document. Or it can contain + /// above `TextDocumentEdit`s mixed with create, rename and delete file / folder operations. + /// /// Whether a client supports versioned document edits is expressed via /// `WorkspaceClientCapabilities.workspaceEdit.documentChanges`. + /// + /// If a client neither supports `documentChanges` nor `workspace.workspaceEdit.resourceOperations` then + /// only plain `TextEdit`s using the `changes` property are supported. /// [Optional] - public Container DocumentChanges { get; set; } + public Container DocumentChanges { get; set; } } } diff --git a/src/Protocol/Models/WorkspaceEditDocumentChange.cs b/src/Protocol/Models/WorkspaceEditDocumentChange.cs new file mode 100644 index 000000000..5467b2c77 --- /dev/null +++ b/src/Protocol/Models/WorkspaceEditDocumentChange.cs @@ -0,0 +1,72 @@ +using Newtonsoft.Json; +using OmniSharp.Extensions.LanguageServer.Protocol.Serialization.Converters; + +namespace OmniSharp.Extensions.LanguageServer.Protocol.Models +{ + public struct WorkspaceEditDocumentChange + { + public WorkspaceEditDocumentChange(TextDocumentEdit textDocumentEdit) + { + TextDocumentEdit = textDocumentEdit; + CreateFile = null; + RenameFile = null; + DeleteFile = null; + } + + public WorkspaceEditDocumentChange(CreateFile createFile) + { + TextDocumentEdit = null; + CreateFile = createFile; + RenameFile = null; + DeleteFile = null; + } + + public WorkspaceEditDocumentChange(RenameFile renameFile) + { + TextDocumentEdit = null; + CreateFile = null; + RenameFile = renameFile; + DeleteFile = null; + } + + public WorkspaceEditDocumentChange(DeleteFile deleteFile) + { + TextDocumentEdit = null; + CreateFile = null; + RenameFile = null; + DeleteFile = deleteFile; + } + + public bool IsTextDocumentEdit => TextDocumentEdit != null; + public TextDocumentEdit TextDocumentEdit { get; } + + public bool IsCreateFile => CreateFile != null; + public CreateFile CreateFile { get; } + + public bool IsRenameFile => RenameFile != null; + public RenameFile RenameFile { get; } + + public bool IsDeleteFile => DeleteFile != null; + public DeleteFile DeleteFile { get; } + + public static implicit operator WorkspaceEditDocumentChange(TextDocumentEdit textDocumentEdit) + { + return new WorkspaceEditDocumentChange(textDocumentEdit); + } + + public static implicit operator WorkspaceEditDocumentChange(CreateFile createFile) + { + return new WorkspaceEditDocumentChange(createFile); + } + + public static implicit operator WorkspaceEditDocumentChange(RenameFile renameFile) + { + return new WorkspaceEditDocumentChange(renameFile); + } + + public static implicit operator WorkspaceEditDocumentChange(DeleteFile deleteFile) + { + return new WorkspaceEditDocumentChange(deleteFile); + } + } +} diff --git a/src/Protocol/Serialization/ContractResolver.cs b/src/Protocol/Serialization/ContractResolver.cs index 3c40056cf..f501bdce4 100644 --- a/src/Protocol/Serialization/ContractResolver.cs +++ b/src/Protocol/Serialization/ContractResolver.cs @@ -63,12 +63,12 @@ protected override JsonProperty CreateProperty(MemberInfo member, MemberSerializ property.ValueProvider = new RangeValueProvider(property.ValueProvider, _completionItemKinds); } - if (property.DeclaringType == typeof(DocumentSymbolInformation) && property.PropertyType == typeof(SymbolKind)) + if (property.DeclaringType == typeof(SymbolInformation) && property.PropertyType == typeof(SymbolKind)) { property.ValueProvider = new RangeValueProvider(property.ValueProvider, _documentSymbolKinds); } - if (property.DeclaringType == typeof(WorkspaceSymbolInformation) && property.PropertyType == typeof(SymbolKind)) + if (property.DeclaringType == typeof(SymbolInformation) && property.PropertyType == typeof(SymbolKind)) { property.ValueProvider = new RangeValueProvider(property.ValueProvider, _workspaceSymbolKinds); } diff --git a/src/Protocol/Serialization/Converters/BooleanNumberStringConverter.cs b/src/Protocol/Serialization/Converters/BooleanNumberStringConverter.cs index acac7d697..1f7931e3d 100644 --- a/src/Protocol/Serialization/Converters/BooleanNumberStringConverter.cs +++ b/src/Protocol/Serialization/Converters/BooleanNumberStringConverter.cs @@ -9,7 +9,10 @@ class BooleanNumberStringConverter : JsonConverter { public override void WriteJson(JsonWriter writer, BooleanNumberString value, JsonSerializer serializer) { - new JValue(value.Value).WriteTo(writer); + if (value.IsBool) serializer.Serialize(writer, value.Bool); + else if (value.IsLong) serializer.Serialize(writer, value.Long); + else if (value.IsString) serializer.Serialize(writer, value.String); + else writer.WriteNull(); } public override BooleanNumberString ReadJson(JsonReader reader, Type objectType, BooleanNumberString existingValue, bool hasExistingValue, JsonSerializer serializer) @@ -18,14 +21,17 @@ public override BooleanNumberString ReadJson(JsonReader reader, Type objectType, { return new BooleanNumberString((long)reader.Value); } - else if (reader.TokenType == JsonToken.String) + + if (reader.TokenType == JsonToken.String) { return new BooleanNumberString((string)reader.Value); } - else if (reader.TokenType == JsonToken.Boolean) + + if (reader.TokenType == JsonToken.Boolean) { return new BooleanNumberString((bool)reader.Value); } + return new BooleanNumberString(); } diff --git a/src/Protocol/Serialization/Converters/BooleanStringConverter.cs b/src/Protocol/Serialization/Converters/BooleanStringConverter.cs index eb17ba03d..da8a017ab 100644 --- a/src/Protocol/Serialization/Converters/BooleanStringConverter.cs +++ b/src/Protocol/Serialization/Converters/BooleanStringConverter.cs @@ -1,4 +1,4 @@ -using System; +using System; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using OmniSharp.Extensions.LanguageServer.Protocol.Models; @@ -9,15 +9,8 @@ class BooleanStringConverter : JsonConverter { public override void WriteJson(JsonWriter writer, BooleanString value, JsonSerializer serializer) { - var v = value as BooleanString?; - if (v.HasValue) - { - new JValue(value.Value).WriteTo(writer); - } - else - { - writer.WriteNull(); - } + if (value.IsBool) serializer.Serialize(writer, value.Bool); + if (value.IsString) serializer.Serialize(writer, value.String); } public override BooleanString ReadJson(JsonReader reader, Type objectType, BooleanString existingValue, bool hasExistingValue, JsonSerializer serializer) diff --git a/src/Protocol/Serialization/Converters/DiagnosticCodeConverter.cs b/src/Protocol/Serialization/Converters/DiagnosticCodeConverter.cs index 6fc1bff80..b2548a8ae 100644 --- a/src/Protocol/Serialization/Converters/DiagnosticCodeConverter.cs +++ b/src/Protocol/Serialization/Converters/DiagnosticCodeConverter.cs @@ -1,4 +1,4 @@ -using System; +using System; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using OmniSharp.Extensions.LanguageServer.Protocol.Models; @@ -9,16 +9,8 @@ class DiagnosticCodeConverter : JsonConverter { public override void WriteJson(JsonWriter writer, DiagnosticCode value, JsonSerializer serializer) { - var v = value as DiagnosticCode?; - - if (v.HasValue) - { - new JValue(v.Value.Value).WriteTo(writer); - } - else - { - writer.WriteNull(); - } + if (value.IsLong) serializer.Serialize(writer, value.Long); + if (value.IsString) serializer.Serialize(writer, value.String); } public override DiagnosticCode ReadJson(JsonReader reader, Type objectType, DiagnosticCode existingValue, bool hasExistingValue, JsonSerializer serializer) diff --git a/src/Protocol/Serialization/Converters/LocationOrLocationLinkConverter.cs b/src/Protocol/Serialization/Converters/LocationOrLocationLinkConverter.cs new file mode 100644 index 000000000..660741faa --- /dev/null +++ b/src/Protocol/Serialization/Converters/LocationOrLocationLinkConverter.cs @@ -0,0 +1,33 @@ +using System; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using OmniSharp.Extensions.LanguageServer.Protocol.Models; + +namespace OmniSharp.Extensions.LanguageServer.Protocol.Serialization.Converters +{ + public class LocationOrLocationLinkConverter : JsonConverter + { + public override void WriteJson(JsonWriter writer, LocationOrLocationLink value, JsonSerializer serializer) + { + if (value.IsLocation) + serializer.Serialize(writer, value.Location); + if (value.IsLocationLink) + serializer.Serialize(writer, value.LocationLink); + } + + public override LocationOrLocationLink ReadJson(JsonReader reader, Type objectType, LocationOrLocationLink existingValue, bool hasExistingValue, JsonSerializer serializer) + { + var obj = JObject.Load(reader); + if (obj.ContainsKey("uri")) + { + return new LocationOrLocationLink(obj.ToObject()); + } + else + { + return new LocationOrLocationLink(obj.ToObject()); + } + } + + public override bool CanRead => true; + } +} diff --git a/src/Protocol/Serialization/Converters/LocationOrLocationsConverter.cs b/src/Protocol/Serialization/Converters/LocationOrLocationLinksConverter.cs similarity index 54% rename from src/Protocol/Serialization/Converters/LocationOrLocationsConverter.cs rename to src/Protocol/Serialization/Converters/LocationOrLocationLinksConverter.cs index 51896de35..c0d1cb3cc 100644 --- a/src/Protocol/Serialization/Converters/LocationOrLocationsConverter.cs +++ b/src/Protocol/Serialization/Converters/LocationOrLocationLinksConverter.cs @@ -7,12 +7,12 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Serialization.Converters { - class LocationOrLocationsConverter : JsonConverter + class LocationOrLocationLinksConverter : JsonConverter { - public override void WriteJson(JsonWriter writer, LocationOrLocations value, JsonSerializer serializer) + public override void WriteJson(JsonWriter writer, LocationOrLocationLinks value, JsonSerializer serializer) { var v = value.ToArray(); - if (v.Length == 1) + if (v.Length == 1 && v[0].IsLocation) { serializer.Serialize(writer, v[0]); return; @@ -21,18 +21,18 @@ public override void WriteJson(JsonWriter writer, LocationOrLocations value, Jso serializer.Serialize(writer, v); } - public override LocationOrLocations ReadJson(JsonReader reader, Type objectType, LocationOrLocations existingValue, bool hasExistingValue, JsonSerializer serializer) + public override LocationOrLocationLinks ReadJson(JsonReader reader, Type objectType, LocationOrLocationLinks existingValue, bool hasExistingValue, JsonSerializer serializer) { if (reader.TokenType == JsonToken.StartArray) { - return new LocationOrLocations(JArray.Load(reader).ToObject>(serializer)); + return new LocationOrLocationLinks(JArray.Load(reader).ToObject>(serializer)); } else if (reader.TokenType == JsonToken.StartObject) { - return new LocationOrLocations(JObject.Load(reader).ToObject(serializer)); + return new LocationOrLocationLinks(JObject.Load(reader).ToObject(serializer)); } - return new LocationOrLocations(); + return new LocationOrLocationLinks(); } public override bool CanRead => true; diff --git a/src/Protocol/Serialization/Converters/ParameterInformationLabelConverter.cs b/src/Protocol/Serialization/Converters/ParameterInformationLabelConverter.cs new file mode 100644 index 000000000..d151ed2c2 --- /dev/null +++ b/src/Protocol/Serialization/Converters/ParameterInformationLabelConverter.cs @@ -0,0 +1,34 @@ +using System; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using OmniSharp.Extensions.LanguageServer.Protocol.Models; + +namespace OmniSharp.Extensions.LanguageServer.Protocol.Serialization.Converters +{ + public class ParameterInformationLabelConverter : JsonConverter + { + public override void WriteJson(JsonWriter writer, ParameterInformationLabel value, JsonSerializer serializer) + { + if (value.IsLabel) + serializer.Serialize(writer, value.Label); + if (value.IsRange) + serializer.Serialize(writer, value.Range); + } + + public override ParameterInformationLabel ReadJson(JsonReader reader, Type objectType, ParameterInformationLabel existingValue, bool hasExistingValue, JsonSerializer serializer) + { + if (reader.TokenType == JsonToken.String) + { + return new ParameterInformationLabel((string)reader.Value); + } + if (reader.TokenType == JsonToken.StartArray) + { + var a = JArray.Load(reader); + return new ParameterInformationLabel((a[0].ToObject(), a[1].ToObject())); + } + throw new NotSupportedException(); + } + + public override bool CanRead => true; + } +} diff --git a/src/Protocol/Serialization/Converters/WorkspaceEditDocumentChangeConverter.cs b/src/Protocol/Serialization/Converters/WorkspaceEditDocumentChangeConverter.cs new file mode 100644 index 000000000..bfbc5f84c --- /dev/null +++ b/src/Protocol/Serialization/Converters/WorkspaceEditDocumentChangeConverter.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Runtime.CompilerServices; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Newtonsoft.Json.Serialization; +using OmniSharp.Extensions.LanguageServer.Protocol.Models; + +namespace OmniSharp.Extensions.LanguageServer.Protocol.Serialization.Converters +{ + public class WorkspaceEditDocumentChangeConverter : JsonConverter + { + public override void WriteJson(JsonWriter writer, WorkspaceEditDocumentChange value, JsonSerializer serializer) + { + if (value.IsCreateFile) serializer.Serialize(writer, value.CreateFile); + if (value.IsDeleteFile) serializer.Serialize(writer, value.DeleteFile); + if (value.IsRenameFile) serializer.Serialize(writer, value.RenameFile); + if (value.IsTextDocumentEdit) serializer.Serialize(writer, value.TextDocumentEdit); + } + + public override WorkspaceEditDocumentChange ReadJson(JsonReader reader, Type objectType, WorkspaceEditDocumentChange existingValue, bool hasExistingValue, JsonSerializer serializer) + { + var obj = JObject.Load(reader); + if (obj.ContainsKey("kind")) + { + var kind = obj["kind"].ToString(); + switch (kind) + { + case "create": + return new WorkspaceEditDocumentChange(obj.ToObject()); + case "rename": + return new WorkspaceEditDocumentChange(obj.ToObject()); + case "delete": + return new WorkspaceEditDocumentChange(obj.ToObject()); + default: + throw new NotSupportedException("Object with " + kind + " is not supported"); + } + } + else + { + return new WorkspaceEditDocumentChange(obj.ToObject()); + } + } + + public override bool CanRead => true; + } + + class ValueTupleContractResolver : JsonConverter> + { + public override void WriteJson(JsonWriter writer, (T1, T2) value, JsonSerializer serializer) + { + serializer.Serialize(writer, new object[] { value.Item1, value.Item2 }); + } + + public override (T1, T2) ReadJson(JsonReader reader, Type objectType, (T1, T2) existingValue, bool hasExistingValue, JsonSerializer serializer) + { + var a = JArray.Load(reader); + return (a.ToObject(), a.ToObject()); + } + } +} diff --git a/src/Protocol/Serialization/ILspSerializer.cs b/src/Protocol/Serialization/ISerializer.cs similarity index 100% rename from src/Protocol/Serialization/ILspSerializer.cs rename to src/Protocol/Serialization/ISerializer.cs diff --git a/src/Protocol/Serialization/Serializer.cs b/src/Protocol/Serialization/Serializer.cs index 74e8b0aac..c1550bf01 100644 --- a/src/Protocol/Serialization/Serializer.cs +++ b/src/Protocol/Serialization/Serializer.cs @@ -60,7 +60,7 @@ private static void AddOrReplaceConverters(ICollection converters ReplaceConverter(converters, new SupportsConverter()); ReplaceConverter(converters, new CompletionListConverter()); ReplaceConverter(converters, new DiagnosticCodeConverter()); - ReplaceConverter(converters, new LocationOrLocationsConverter()); + ReplaceConverter(converters, new LocationOrLocationLinksConverter()); ReplaceConverter(converters, new MarkedStringCollectionConverter()); ReplaceConverter(converters, new MarkedStringConverter()); ReplaceConverter(converters, new StringOrMarkupContentConverter()); @@ -70,7 +70,11 @@ private static void AddOrReplaceConverters(ICollection converters ReplaceConverter(converters, new BooleanOrConverter()); ReplaceConverter(converters, new MarkedStringsOrMarkupContentConverter()); ReplaceConverter(converters, new CommandOrCodeActionConverter()); - ReplaceConverter(converters, new DocumentSymbolInformationOrDocumentSymbolConverter()); + ReplaceConverter(converters, new SymbolInformationOrDocumentSymbolConverter()); + ReplaceConverter(converters, new LocationOrLocationLinkConverter()); + ReplaceConverter(converters, new WorkspaceEditDocumentChangeConverter()); + ReplaceConverter(converters, new ParameterInformationLabelConverter()); + ReplaceConverter(converters, new ValueTupleContractResolver()); } private static void ReplaceConverter(ICollection converters, T item) diff --git a/test/Lsp.Tests/Capabilities/Client/ClientCapabilitiesTests.cs b/test/Lsp.Tests/Capabilities/Client/ClientCapabilitiesTests.cs index 5173ddd3d..9890bff75 100644 --- a/test/Lsp.Tests/Capabilities/Client/ClientCapabilitiesTests.cs +++ b/test/Lsp.Tests/Capabilities/Client/ClientCapabilitiesTests.cs @@ -30,7 +30,8 @@ public void SimpleTest(string expected) TextDocument = new TextDocumentClientCapabilities() { CodeAction = new CodeActionCapability() { DynamicRegistration = true }, CodeLens = new CodeLensCapability() { DynamicRegistration = true }, - Definition = new DefinitionCapability() { DynamicRegistration = true }, + Definition = new DefinitionCapability() { DynamicRegistration = true, LinkSupport = true }, + Declaration = new DeclarationCapability() { DynamicRegistration = true, LinkSupport = true }, DocumentHighlight = new DocumentHighlightCapability() { DynamicRegistration = true }, DocumentLink = new DocumentLinkCapability() { DynamicRegistration = true }, DocumentSymbol = new DocumentSymbolCapability() { DynamicRegistration = true }, @@ -47,6 +48,14 @@ public void SimpleTest(string expected) SnippetSupport = true } }, + Implementation = new ImplementationCapability() { + DynamicRegistration = true, + LinkSupport = true + }, + TypeDefinition = new TypeDefinitionCapability() { + DynamicRegistration = true, + LinkSupport = true + }, Synchronization = new SynchronizationCapability() { DynamicRegistration = true, WillSave = true, @@ -68,7 +77,8 @@ public void SimpleTest(string expected) result.Should().Be(expected); var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject(expected); - deresult.Should().BeEquivalentTo(model, o => o.ConfigureForSupports(Logger)); + deresult.Should().BeEquivalentTo(model, o => o + .ConfigureForSupports(Logger)); } [Theory, JsonFixture] diff --git a/test/Lsp.Tests/Capabilities/Client/ClientCapabilitiesTests_$SimpleTest.json b/test/Lsp.Tests/Capabilities/Client/ClientCapabilitiesTests_$SimpleTest.json index 01f82feb4..ef1ab50ea 100644 --- a/test/Lsp.Tests/Capabilities/Client/ClientCapabilitiesTests_$SimpleTest.json +++ b/test/Lsp.Tests/Capabilities/Client/ClientCapabilitiesTests_$SimpleTest.json @@ -59,6 +59,11 @@ "dynamicRegistration": true }, "definition": { + "linkSupport": true, + "dynamicRegistration": true + }, + "declaration": { + "linkSupport": true, "dynamicRegistration": true }, "codeAction": { @@ -73,6 +78,14 @@ "rename": { "prepareSupport": false, "dynamicRegistration": true + }, + "typeDefinition": { + "linkSupport": true, + "dynamicRegistration": true + }, + "implementation": { + "linkSupport": true, + "dynamicRegistration": true } }, "experimental": { diff --git a/test/Lsp.Tests/Capabilities/Client/TextDocumentClientCapabilitiesTests_$SimpleTest.json b/test/Lsp.Tests/Capabilities/Client/TextDocumentClientCapabilitiesTests_$SimpleTest.json index 8272b0810..10bb517a5 100644 --- a/test/Lsp.Tests/Capabilities/Client/TextDocumentClientCapabilitiesTests_$SimpleTest.json +++ b/test/Lsp.Tests/Capabilities/Client/TextDocumentClientCapabilitiesTests_$SimpleTest.json @@ -40,6 +40,7 @@ "dynamicRegistration": true }, "definition": { + "linkSupport": false, "dynamicRegistration": true }, "codeAction": { diff --git a/test/Lsp.Tests/Capabilities/Client/WorkspaceClientCapabilitiesTests_$SimpleTest.json b/test/Lsp.Tests/Capabilities/Client/WorkspaceClientCapabilitiesTests_$SimpleTest.json index 8cce0e20a..30d691678 100644 --- a/test/Lsp.Tests/Capabilities/Client/WorkspaceClientCapabilitiesTests_$SimpleTest.json +++ b/test/Lsp.Tests/Capabilities/Client/WorkspaceClientCapabilitiesTests_$SimpleTest.json @@ -1,4 +1,4 @@ -{ +{ "applyEdit": true, "workspaceEdit": { "documentChanges": true @@ -15,4 +15,4 @@ "executeCommand": { "dynamicRegistration": true } -} \ No newline at end of file +} diff --git a/test/Lsp.Tests/ClientCapabilityProviderFixture.cs b/test/Lsp.Tests/ClientCapabilityProviderFixture.cs index 6dc4edadd..0150f6e12 100644 --- a/test/Lsp.Tests/ClientCapabilityProviderFixture.cs +++ b/test/Lsp.Tests/ClientCapabilityProviderFixture.cs @@ -30,31 +30,4 @@ public ClientCapabilityProvider.IOptionsGetter GetStaticOptions() return Provider.GetStaticOptions(new Supports(true, new ExecuteCommandCapability { DynamicRegistration = false })); } } - - public class SupportedCapabilitiesFixture - { - public static readonly ISupportedCapabilities AlwaysTrue = new AlwaysTrueSupportedCapabilities(); - public static readonly ISupportedCapabilities AlwaysFalse = new AlwaysFalseSupportedCapabilities(); - class AlwaysTrueSupportedCapabilities : ISupportedCapabilities - { - public bool AllowsDynamicRegistration(ILspHandlerDescriptor descriptor) => true; - - public bool AllowsDynamicRegistration(Type capabilityType) => true; - - public void SetCapability(ILspHandlerDescriptor descriptor, IJsonRpcHandler handler) - { - } - } - - class AlwaysFalseSupportedCapabilities : ISupportedCapabilities - { - public bool AllowsDynamicRegistration(ILspHandlerDescriptor descriptor) => false; - - public bool AllowsDynamicRegistration(Type capabilityType) => false; - - public void SetCapability(ILspHandlerDescriptor descriptor, IJsonRpcHandler handler) - { - } - } - } } diff --git a/test/Lsp.Tests/FluentAssertionsExtensions.cs b/test/Lsp.Tests/FluentAssertionsExtensions.cs index 39fdba99d..a152e7919 100644 --- a/test/Lsp.Tests/FluentAssertionsExtensions.cs +++ b/test/Lsp.Tests/FluentAssertionsExtensions.cs @@ -18,6 +18,7 @@ public static EquivalencyAssertionOptions ConfigureForSupports(this Equiva .ComparingByMembers>() .ComparingByMembers>() .ComparingByMembers>() + .ComparingByMembers>() .ComparingByMembers>() .ComparingByMembers>() .ComparingByMembers>() diff --git a/test/Lsp.Tests/Models/ApplyWorkspaceEditParamsTests.cs b/test/Lsp.Tests/Models/ApplyWorkspaceEditParamsTests.cs index c54eb69e9..8ae497816 100644 --- a/test/Lsp.Tests/Models/ApplyWorkspaceEditParamsTests.cs +++ b/test/Lsp.Tests/Models/ApplyWorkspaceEditParamsTests.cs @@ -50,7 +50,7 @@ public void DocumentChangesTest(string expected) { Edit = new WorkspaceEdit() { - DocumentChanges = new Container( + DocumentChanges = new Container( new TextDocumentEdit() { TextDocument = new VersionedTextDocumentIdentifier() @@ -86,6 +86,28 @@ public void DocumentChangesTest(string expected) Range = new Range(new Position(3, 3), new Position(4,4)) } } + }, + new CreateFile() { + Uri = "file:///abc/123/b.cs", + Options = new CreateFileOptions() { + IgnoreIfExists = true, + Overwrite = true + } + }, + new RenameFile() { + OldUri = "file:///abc/123/b.cs", + NewUri = "file:///abc/123/c.cs", + Options = new RenameFileOptions() { + IgnoreIfExists = true, + Overwrite = true + } + }, + new DeleteFile() { + Uri = "file:///abc/123/c.cs", + Options = new DeleteFileOptions() { + IgnoreIfNotExists = true, + Recursive = false + } } ) } @@ -95,7 +117,16 @@ public void DocumentChangesTest(string expected) result.Should().Be(expected); var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject(expected); - deresult.Should().BeEquivalentTo(model); + deresult.Should().BeEquivalentTo(model, x => x + .ComparingByMembers() + //.ComparingByMembers() + //.ComparingByMembers() + //.ComparingByMembers() + //.ComparingByMembers() + //.ComparingByMembers() + //.ComparingByMembers() + //.ComparingByMembers() + ); } } } diff --git a/test/Lsp.Tests/Models/ApplyWorkspaceEditParamsTests_$DocumentChangesTest.json b/test/Lsp.Tests/Models/ApplyWorkspaceEditParamsTests_$DocumentChangesTest.json index befee93e3..05fa0918e 100644 --- a/test/Lsp.Tests/Models/ApplyWorkspaceEditParamsTests_$DocumentChangesTest.json +++ b/test/Lsp.Tests/Models/ApplyWorkspaceEditParamsTests_$DocumentChangesTest.json @@ -68,6 +68,31 @@ "newText": "new text3" } ] + }, + { + "kind": "create", + "uri": "file:///abc/123/b.cs", + "options": { + "overwrite": true, + "ignoreIfExists": true + } + }, + { + "kind": "rename", + "oldUri": "file:///abc/123/b.cs", + "newUri": "file:///abc/123/c.cs", + "options": { + "overwrite": true, + "ignoreIfExists": true + } + }, + { + "kind": "delete", + "uri": "file:///abc/123/c.cs", + "options": { + "recursive": false, + "ignoreIfNotExists": true + } } ] } diff --git a/test/Lsp.Tests/Models/InitializeParamsTests_$SimpleTest.json b/test/Lsp.Tests/Models/InitializeParamsTests_$SimpleTest.json index 4d966221a..2d7c76ca0 100644 --- a/test/Lsp.Tests/Models/InitializeParamsTests_$SimpleTest.json +++ b/test/Lsp.Tests/Models/InitializeParamsTests_$SimpleTest.json @@ -61,6 +61,7 @@ "dynamicRegistration": true }, "definition": { + "linkSupport": false, "dynamicRegistration": true }, "codeAction": { diff --git a/test/Lsp.Tests/Models/LocationOrLocationLinksTests.cs b/test/Lsp.Tests/Models/LocationOrLocationLinksTests.cs new file mode 100644 index 000000000..c26e46333 --- /dev/null +++ b/test/Lsp.Tests/Models/LocationOrLocationLinksTests.cs @@ -0,0 +1,113 @@ +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 LocationOrLocationLinksTests + { + [Theory, JsonFixture] + public void SimpleTest(string expected) + { + var model = new LocationOrLocationLinks(); + var result = Fixture.SerializeObject(model); + + result.Should().Be(expected); + + var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject(expected); + deresult.Should().BeEquivalentTo(model); + } + + [Theory, JsonFixture] + public void LocationTest(string expected) + { + var model = new LocationOrLocationLinks(new Location() + { + Range = new Range(new Position(1, 1), new Position(3, 3)), + + }); + var result = Fixture.SerializeObject(model); + + result.Should().Be(expected); + + var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject(expected); + deresult.Should().BeEquivalentTo(model); + } + + [Theory, JsonFixture] + public void LocationsTest(string expected) + { + var model = new LocationOrLocationLinks(new Location() + { + Range = new Range(new Position(1, 1), new Position(3, 3)), + + }, new Location() + { + Range = new Range(new Position(1, 1), new Position(3, 3)), + + }); + var result = Fixture.SerializeObject(model); + + result.Should().Be(expected); + + var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject(expected); + deresult.Should().BeEquivalentTo(model); + } + + [Theory, JsonFixture] + public void LocationLinkTest(string expected) + { + var model = new LocationOrLocationLinks(new LocationLink() + { + TargetSelectionRange = new Range(new Position(1, 1), new Position(3, 3)), + TargetRange = new Range(new Position(1, 1), new Position(3, 3)), + TargetUri = new Uri("file://asdfasdf/a.tst"), + OriginSelectionRange = new Range(new Position(1, 1), new Position(3, 3)), + }); + var result = Fixture.SerializeObject(model); + + result.Should().Be(expected); + + var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject(expected); + deresult.Should().BeEquivalentTo(model, x => x + .ComparingByMembers() + ); + } + + [Theory, JsonFixture] + public void LocationLinksTest(string expected) + { + var model = new LocationOrLocationLinks(new LocationLink() + { + TargetSelectionRange = new Range(new Position(1, 1), new Position(3, 3)), + TargetRange = new Range(new Position(1, 1), new Position(3, 3)), + TargetUri = new Uri("file://asdfasdf/a.tst"), + OriginSelectionRange = new Range(new Position(1, 1), new Position(3, 3)), + + }, + new LocationLink() + { + TargetSelectionRange = new Range(new Position(1, 1), new Position(3, 3)), + TargetRange = new Range(new Position(1, 1), new Position(3, 3)), + TargetUri = new Uri("file://asdfasdf/a.tst"), + OriginSelectionRange = new Range(new Position(1, 1), new Position(3, 3)), + + }); + var result = Fixture.SerializeObject(model); + + result.Should().Be(expected); + + var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject(expected); + deresult.Should().BeEquivalentTo(model, x => x + .ComparingByMembers() + .ComparingByMembers() + .ComparingByMembers() + ); + } + } +} diff --git a/test/Lsp.Tests/Models/LocationOrLocationLinksTests_$LocationLinkTest.json b/test/Lsp.Tests/Models/LocationOrLocationLinksTests_$LocationLinkTest.json new file mode 100644 index 000000000..ddec12069 --- /dev/null +++ b/test/Lsp.Tests/Models/LocationOrLocationLinksTests_$LocationLinkTest.json @@ -0,0 +1,35 @@ +[ + { + "originSelectionRange": { + "start": { + "line": 1, + "character": 1 + }, + "end": { + "line": 3, + "character": 3 + } + }, + "targetUri": "file://asdfasdf/a.tst", + "targetRange": { + "start": { + "line": 1, + "character": 1 + }, + "end": { + "line": 3, + "character": 3 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 1 + }, + "end": { + "line": 3, + "character": 3 + } + } + } +] diff --git a/test/Lsp.Tests/Models/LocationOrLocationLinksTests_$LocationLinksTest.json b/test/Lsp.Tests/Models/LocationOrLocationLinksTests_$LocationLinksTest.json new file mode 100644 index 000000000..4a3df6049 --- /dev/null +++ b/test/Lsp.Tests/Models/LocationOrLocationLinksTests_$LocationLinksTest.json @@ -0,0 +1,68 @@ +[ + { + "originSelectionRange": { + "start": { + "line": 1, + "character": 1 + }, + "end": { + "line": 3, + "character": 3 + } + }, + "targetUri": "file://asdfasdf/a.tst", + "targetRange": { + "start": { + "line": 1, + "character": 1 + }, + "end": { + "line": 3, + "character": 3 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 1 + }, + "end": { + "line": 3, + "character": 3 + } + } + }, + { + "originSelectionRange": { + "start": { + "line": 1, + "character": 1 + }, + "end": { + "line": 3, + "character": 3 + } + }, + "targetUri": "file://asdfasdf/a.tst", + "targetRange": { + "start": { + "line": 1, + "character": 1 + }, + "end": { + "line": 3, + "character": 3 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 1 + }, + "end": { + "line": 3, + "character": 3 + } + } + } +] diff --git a/test/Lsp.Tests/Models/LocationOrLocationLinksTests_$LocationTest.json b/test/Lsp.Tests/Models/LocationOrLocationLinksTests_$LocationTest.json new file mode 100644 index 000000000..927aa092a --- /dev/null +++ b/test/Lsp.Tests/Models/LocationOrLocationLinksTests_$LocationTest.json @@ -0,0 +1,13 @@ +{ + "uri": null, + "range": { + "start": { + "line": 1, + "character": 1 + }, + "end": { + "line": 3, + "character": 3 + } + } +} diff --git a/test/Lsp.Tests/Models/LocationOrLocationLinksTests_$LocationsTest.json b/test/Lsp.Tests/Models/LocationOrLocationLinksTests_$LocationsTest.json new file mode 100644 index 000000000..2b92b20c3 --- /dev/null +++ b/test/Lsp.Tests/Models/LocationOrLocationLinksTests_$LocationsTest.json @@ -0,0 +1,28 @@ +[ + { + "uri": null, + "range": { + "start": { + "line": 1, + "character": 1 + }, + "end": { + "line": 3, + "character": 3 + } + } + }, + { + "uri": null, + "range": { + "start": { + "line": 1, + "character": 1 + }, + "end": { + "line": 3, + "character": 3 + } + } + } +] diff --git a/test/Lsp.Tests/Models/LocationOrLocationsTests_$SimpleTest.json b/test/Lsp.Tests/Models/LocationOrLocationLinksTests_$SimpleTest.json similarity index 100% rename from test/Lsp.Tests/Models/LocationOrLocationsTests_$SimpleTest.json rename to test/Lsp.Tests/Models/LocationOrLocationLinksTests_$SimpleTest.json diff --git a/test/Lsp.Tests/Models/LocationOrLocationsTests.cs b/test/Lsp.Tests/Models/LocationOrLocationsTests.cs deleted file mode 100644 index 4b6ea2366..000000000 --- a/test/Lsp.Tests/Models/LocationOrLocationsTests.cs +++ /dev/null @@ -1,26 +0,0 @@ -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 LocationOrLocationsTests - { - [Theory, JsonFixture] - public void SimpleTest(string expected) - { - var model = new LocationOrLocations(); - var result = Fixture.SerializeObject(model); - - result.Should().Be(expected); - - var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject(expected); - deresult.Should().BeEquivalentTo(model); - } - } -} diff --git a/test/Lsp.Tests/Models/ParameterInformationTests.cs b/test/Lsp.Tests/Models/ParameterInformationTests.cs index 29a8ae6f1..2a9b82d3e 100644 --- a/test/Lsp.Tests/Models/ParameterInformationTests.cs +++ b/test/Lsp.Tests/Models/ParameterInformationTests.cs @@ -12,7 +12,7 @@ namespace Lsp.Tests.Models public class ParameterInformationTests { [Theory, JsonFixture] - public void SimpleTest(string expected) + public void SimpleTest(string expected) { var model = new ParameterInformation() { Documentation = "docs", diff --git a/test/Lsp.Tests/Models/SignatureInformationTests.cs b/test/Lsp.Tests/Models/SignatureInformationTests.cs index 986dead7e..3418bcfa0 100644 --- a/test/Lsp.Tests/Models/SignatureInformationTests.cs +++ b/test/Lsp.Tests/Models/SignatureInformationTests.cs @@ -30,6 +30,30 @@ public void SimpleTest(string expected) deresult.Should().BeEquivalentTo(model); } + [Theory, JsonFixture] + public void ParamRangeTest(string expected) + { + var model = new SignatureInformation() { + Documentation = "ab", + Label = "ab", + Parameters = new[] { new ParameterInformation() { + Documentation = "param", + Label = (1, 2) + } } + }; + var result = Fixture.SerializeObject(model); + + result.Should().Be(expected); + + var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject(expected); + deresult.Should().BeEquivalentTo(model, x => x + .ComparingByMembers>() + .ComparingByMembers() + .ComparingByMembers() + .ComparingByMembers() + ); + } + [Theory, JsonFixture] public void MarkupContentTest(string expected) { diff --git a/test/Lsp.Tests/Models/SignatureInformationTests_$ParamRangeTest.json b/test/Lsp.Tests/Models/SignatureInformationTests_$ParamRangeTest.json new file mode 100644 index 000000000..2bd79eba3 --- /dev/null +++ b/test/Lsp.Tests/Models/SignatureInformationTests_$ParamRangeTest.json @@ -0,0 +1,13 @@ +{ + "label": "ab", + "documentation": "ab", + "parameters": [ + { + "label": [ + 1, + 2 + ], + "documentation": "param" + } + ] +} diff --git a/test/Lsp.Tests/Models/WorkspaceEditTests.cs b/test/Lsp.Tests/Models/WorkspaceEditTests.cs index 7362c5d8f..64fccc5f4 100644 --- a/test/Lsp.Tests/Models/WorkspaceEditTests.cs +++ b/test/Lsp.Tests/Models/WorkspaceEditTests.cs @@ -45,7 +45,7 @@ public void DocumentChangesTest(string expected) { var model = new WorkspaceEdit() { - DocumentChanges = new Container( + DocumentChanges = new Container( new TextDocumentEdit() { TextDocument = new VersionedTextDocumentIdentifier() @@ -81,6 +81,28 @@ public void DocumentChangesTest(string expected) Range = new Range(new Position(3, 3), new Position(4,4)) } } + }, + new CreateFile() { + Uri = "file:///abc/123/b.cs", + Options = new CreateFileOptions() { + IgnoreIfExists = true, + Overwrite = true + } + }, + new RenameFile() { + OldUri = "file:///abc/123/b.cs", + NewUri = "file:///abc/123/c.cs", + Options = new RenameFileOptions() { + IgnoreIfExists = true, + Overwrite = true + } + }, + new DeleteFile() { + Uri = "file:///abc/123/c.cs", + Options = new DeleteFileOptions() { + IgnoreIfNotExists = true, + Recursive = false + } } ) }; @@ -89,7 +111,9 @@ public void DocumentChangesTest(string expected) result.Should().Be(expected); var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject(expected); - deresult.Should().BeEquivalentTo(model); + deresult.Should().BeEquivalentTo(model, x => x + .ComparingByMembers() + ); } } } diff --git a/test/Lsp.Tests/Models/WorkspaceEditTests_$DocumentChangesTest.json b/test/Lsp.Tests/Models/WorkspaceEditTests_$DocumentChangesTest.json index d8c33c411..6961c0421 100644 --- a/test/Lsp.Tests/Models/WorkspaceEditTests_$DocumentChangesTest.json +++ b/test/Lsp.Tests/Models/WorkspaceEditTests_$DocumentChangesTest.json @@ -67,6 +67,31 @@ "newText": "new text3" } ] + }, + { + "kind": "create", + "uri": "file:///abc/123/b.cs", + "options": { + "overwrite": true, + "ignoreIfExists": true + } + }, + { + "kind": "rename", + "oldUri": "file:///abc/123/b.cs", + "newUri": "file:///abc/123/c.cs", + "options": { + "overwrite": true, + "ignoreIfExists": true + } + }, + { + "kind": "delete", + "uri": "file:///abc/123/c.cs", + "options": { + "recursive": false, + "ignoreIfNotExists": true + } } ] } diff --git a/test/Lsp.Tests/SupportedCapabilitiesFixture.cs b/test/Lsp.Tests/SupportedCapabilitiesFixture.cs new file mode 100644 index 000000000..d3a737d0a --- /dev/null +++ b/test/Lsp.Tests/SupportedCapabilitiesFixture.cs @@ -0,0 +1,34 @@ +using System; +using OmniSharp.Extensions.JsonRpc; +using OmniSharp.Extensions.LanguageServer.Server; +using OmniSharp.Extensions.LanguageServer.Server.Abstractions; + +namespace Lsp.Tests +{ + public class SupportedCapabilitiesFixture + { + public static readonly ISupportedCapabilities AlwaysTrue = new AlwaysTrueSupportedCapabilities(); + public static readonly ISupportedCapabilities AlwaysFalse = new AlwaysFalseSupportedCapabilities(); + class AlwaysTrueSupportedCapabilities : ISupportedCapabilities + { + public bool AllowsDynamicRegistration(ILspHandlerDescriptor descriptor) => true; + + public bool AllowsDynamicRegistration(Type capabilityType) => true; + + public void SetCapability(ILspHandlerDescriptor descriptor, IJsonRpcHandler handler) + { + } + } + + class AlwaysFalseSupportedCapabilities : ISupportedCapabilities + { + public bool AllowsDynamicRegistration(ILspHandlerDescriptor descriptor) => false; + + public bool AllowsDynamicRegistration(Type capabilityType) => false; + + public void SetCapability(ILspHandlerDescriptor descriptor, IJsonRpcHandler handler) + { + } + } + } +} \ No newline at end of file From fa32c0c7c69058f10d8d017e13913af78fedbc54 Mon Sep 17 00:00:00 2001 From: David Driscoll Date: Thu, 14 Mar 2019 09:24:14 -0400 Subject: [PATCH 4/5] merged with latest changes, renamed DocumentSymbolInformationOrDocumentSymbol --- .../Client/DocumentSymbolExtensions.cs | 4 +-- .../Document/Server/IDocumentSymbolHandler.cs | 2 +- ...bolInformationOrDocumentSymbolContainer.cs | 36 ------------------- src/Protocol/Models/DocumentSymbolParams.cs | 2 +- ...s => SymbolInformationOrDocumentSymbol.cs} | 0 ...bolInformationOrDocumentSymbolContainer.cs | 36 +++++++++++++++++++ .../CommandOrCodeActionConverter.cs | 1 - 7 files changed, 40 insertions(+), 41 deletions(-) delete mode 100644 src/Protocol/Models/DocumentSymbolInformationOrDocumentSymbolContainer.cs rename src/Protocol/Models/{DocumentSymbolInformationOrDocumentSymbol.cs => SymbolInformationOrDocumentSymbol.cs} (100%) create mode 100644 src/Protocol/Models/SymbolInformationOrDocumentSymbolContainer.cs diff --git a/src/Protocol/Document/Client/DocumentSymbolExtensions.cs b/src/Protocol/Document/Client/DocumentSymbolExtensions.cs index a93380cdc..bd7ff82f8 100644 --- a/src/Protocol/Document/Client/DocumentSymbolExtensions.cs +++ b/src/Protocol/Document/Client/DocumentSymbolExtensions.cs @@ -9,9 +9,9 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Client { public static class DocumentSymbolExtensions { - public static Task DocumentSymbol(this ILanguageClientDocument mediator, DocumentSymbolParams @params) + public static Task DocumentSymbol(this ILanguageClientDocument mediator, DocumentSymbolParams @params) { - return mediator.SendRequest(DocumentNames.DocumentSymbol, @params); + return mediator.SendRequest(DocumentNames.DocumentSymbol, @params); } } } diff --git a/src/Protocol/Document/Server/IDocumentSymbolHandler.cs b/src/Protocol/Document/Server/IDocumentSymbolHandler.cs index 953a34b02..a14ac846b 100644 --- a/src/Protocol/Document/Server/IDocumentSymbolHandler.cs +++ b/src/Protocol/Document/Server/IDocumentSymbolHandler.cs @@ -8,5 +8,5 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Server { using static DocumentNames; [Parallel, Method(DocumentSymbol)] - public interface IDocumentSymbolHandler : IJsonRpcRequestHandler, IRegistration, ICapability { } + public interface IDocumentSymbolHandler : IJsonRpcRequestHandler, IRegistration, ICapability { } } diff --git a/src/Protocol/Models/DocumentSymbolInformationOrDocumentSymbolContainer.cs b/src/Protocol/Models/DocumentSymbolInformationOrDocumentSymbolContainer.cs deleted file mode 100644 index 3d16371ec..000000000 --- a/src/Protocol/Models/DocumentSymbolInformationOrDocumentSymbolContainer.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; - -namespace OmniSharp.Extensions.LanguageServer.Protocol.Models -{ - public class DocumentSymbolInformationOrDocumentSymbolContainer : Container - { - public DocumentSymbolInformationOrDocumentSymbolContainer() : this(Enumerable.Empty()) - { - } - - public DocumentSymbolInformationOrDocumentSymbolContainer(IEnumerable items) : base(items) - { - } - - public DocumentSymbolInformationOrDocumentSymbolContainer(params DocumentSymbolInformationOrDocumentSymbol[] items) : base(items) - { - } - - public static implicit operator DocumentSymbolInformationOrDocumentSymbolContainer(DocumentSymbolInformationOrDocumentSymbol[] items) - { - return new DocumentSymbolInformationOrDocumentSymbolContainer(items); - } - - public static implicit operator DocumentSymbolInformationOrDocumentSymbolContainer(Collection items) - { - return new DocumentSymbolInformationOrDocumentSymbolContainer(items); - } - - public static implicit operator DocumentSymbolInformationOrDocumentSymbolContainer(List items) - { - return new DocumentSymbolInformationOrDocumentSymbolContainer(items); - } - } -} diff --git a/src/Protocol/Models/DocumentSymbolParams.cs b/src/Protocol/Models/DocumentSymbolParams.cs index a7c0f50e1..21b0b16eb 100644 --- a/src/Protocol/Models/DocumentSymbolParams.cs +++ b/src/Protocol/Models/DocumentSymbolParams.cs @@ -4,7 +4,7 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Models { - public class DocumentSymbolParams : ITextDocumentIdentifierParams, IRequest + public class DocumentSymbolParams : ITextDocumentIdentifierParams, IRequest { /// /// The text document. diff --git a/src/Protocol/Models/DocumentSymbolInformationOrDocumentSymbol.cs b/src/Protocol/Models/SymbolInformationOrDocumentSymbol.cs similarity index 100% rename from src/Protocol/Models/DocumentSymbolInformationOrDocumentSymbol.cs rename to src/Protocol/Models/SymbolInformationOrDocumentSymbol.cs diff --git a/src/Protocol/Models/SymbolInformationOrDocumentSymbolContainer.cs b/src/Protocol/Models/SymbolInformationOrDocumentSymbolContainer.cs new file mode 100644 index 000000000..43dbab5fb --- /dev/null +++ b/src/Protocol/Models/SymbolInformationOrDocumentSymbolContainer.cs @@ -0,0 +1,36 @@ +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; + +namespace OmniSharp.Extensions.LanguageServer.Protocol.Models +{ + public class SymbolInformationOrDocumentSymbolContainer : Container + { + public SymbolInformationOrDocumentSymbolContainer() : this(Enumerable.Empty()) + { + } + + public SymbolInformationOrDocumentSymbolContainer(IEnumerable items) : base(items) + { + } + + public SymbolInformationOrDocumentSymbolContainer(params SymbolInformationOrDocumentSymbol[] items) : base(items) + { + } + + public static implicit operator SymbolInformationOrDocumentSymbolContainer(SymbolInformationOrDocumentSymbol[] items) + { + return new SymbolInformationOrDocumentSymbolContainer(items); + } + + public static implicit operator SymbolInformationOrDocumentSymbolContainer(Collection items) + { + return new SymbolInformationOrDocumentSymbolContainer(items); + } + + public static implicit operator SymbolInformationOrDocumentSymbolContainer(List items) + { + return new SymbolInformationOrDocumentSymbolContainer(items); + } + } +} diff --git a/src/Protocol/Serialization/Converters/CommandOrCodeActionConverter.cs b/src/Protocol/Serialization/Converters/CommandOrCodeActionConverter.cs index 91c00683c..d0f304583 100644 --- a/src/Protocol/Serialization/Converters/CommandOrCodeActionConverter.cs +++ b/src/Protocol/Serialization/Converters/CommandOrCodeActionConverter.cs @@ -40,5 +40,4 @@ public override CommandOrCodeAction ReadJson(JsonReader reader, Type objectType, public override bool CanRead => true; } - //DocumentSymbolInformationOrDocumentSymbolConverter } From 705f295d5366aa09a3fabfe5128bf41b97754f89 Mon Sep 17 00:00:00 2001 From: David Driscoll Date: Thu, 14 Mar 2019 09:38:24 -0400 Subject: [PATCH 5/5] Resharper strikes again --- src/JsonRpc/AsyncRequestHandler.cs | 27 ------------------------- src/JsonRpc/IBaseRequest.cs | 7 ------- src/JsonRpc/NotificationHandler.cs | 25 ----------------------- src/JsonRpc/RequestHandler.cs | 24 ---------------------- src/JsonRpc/RequestHandlerDelegate.cs | 11 ---------- src/JsonRpc/ServiceFactoryExtensions.cs | 13 ------------ 6 files changed, 107 deletions(-) delete mode 100644 src/JsonRpc/AsyncRequestHandler.cs delete mode 100644 src/JsonRpc/IBaseRequest.cs delete mode 100644 src/JsonRpc/NotificationHandler.cs delete mode 100644 src/JsonRpc/RequestHandler.cs delete mode 100644 src/JsonRpc/RequestHandlerDelegate.cs delete mode 100644 src/JsonRpc/ServiceFactoryExtensions.cs diff --git a/src/JsonRpc/AsyncRequestHandler.cs b/src/JsonRpc/AsyncRequestHandler.cs deleted file mode 100644 index ce3a18eed..000000000 --- a/src/JsonRpc/AsyncRequestHandler.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Threading; -using System.Threading.Tasks; - -namespace OmniSharp.Extensions.Embedded.MediatR -{ - /// - /// Wrapper class for a handler that asynchronously handles a request and does not return a response - /// - /// The type of request being handled - public abstract class AsyncRequestHandler : IRequestHandler - where TRequest : IRequest - { - async Task IRequestHandler.Handle(TRequest request, CancellationToken cancellationToken) - { - await Handle(request, cancellationToken).ConfigureAwait(false); - return Unit.Value; - } - - /// - /// Override in a derived class for the handler logic - /// - /// Request - /// - /// Response - protected abstract Task Handle(TRequest request, CancellationToken cancellationToken); - } -} \ No newline at end of file diff --git a/src/JsonRpc/IBaseRequest.cs b/src/JsonRpc/IBaseRequest.cs deleted file mode 100644 index 5fe2b1f96..000000000 --- a/src/JsonRpc/IBaseRequest.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace OmniSharp.Extensions.Embedded.MediatR -{ - /// - /// Allows for generic type constraints of objects implementing IRequest or IRequest{TResponse} - /// - public interface IBaseRequest { } -} \ No newline at end of file diff --git a/src/JsonRpc/NotificationHandler.cs b/src/JsonRpc/NotificationHandler.cs deleted file mode 100644 index 05e80be5c..000000000 --- a/src/JsonRpc/NotificationHandler.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Threading; -using System.Threading.Tasks; - -namespace OmniSharp.Extensions.Embedded.MediatR -{ - /// - /// Wrapper class for a synchronous notification handler - /// - /// The notification type - public abstract class NotificationHandler : INotificationHandler - where TNotification : INotification - { - Task INotificationHandler.Handle(TNotification notification, CancellationToken cancellationToken) - { - Handle(notification); - return Unit.Task; - } - - /// - /// Override in a derived class for the handler logic - /// - /// Notification - protected abstract void Handle(TNotification notification); - } -} \ No newline at end of file diff --git a/src/JsonRpc/RequestHandler.cs b/src/JsonRpc/RequestHandler.cs deleted file mode 100644 index bd0287621..000000000 --- a/src/JsonRpc/RequestHandler.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Threading; -using System.Threading.Tasks; - -namespace OmniSharp.Extensions.Embedded.MediatR -{ - /// - /// Wrapper class for a handler that synchronously handles a request and returns a response - /// - /// The type of request being handled - /// The type of response from the handler - public abstract class RequestHandler : IRequestHandler - where TRequest : IRequest - { - Task IRequestHandler.Handle(TRequest request, CancellationToken cancellationToken) - => Task.FromResult(Handle(request)); - - /// - /// Override in a derived class for the handler logic - /// - /// Request - /// Response - protected abstract TResponse Handle(TRequest request); - } -} \ No newline at end of file diff --git a/src/JsonRpc/RequestHandlerDelegate.cs b/src/JsonRpc/RequestHandlerDelegate.cs deleted file mode 100644 index 5f8d314af..000000000 --- a/src/JsonRpc/RequestHandlerDelegate.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Threading.Tasks; - -namespace OmniSharp.Extensions.Embedded.MediatR -{ - /// - /// Represents an async continuation for the next task to execute in the pipeline - /// - /// Response type - /// Awaitable task returning a - public delegate Task RequestHandlerDelegate(); -} \ No newline at end of file diff --git a/src/JsonRpc/ServiceFactoryExtensions.cs b/src/JsonRpc/ServiceFactoryExtensions.cs deleted file mode 100644 index fe031d608..000000000 --- a/src/JsonRpc/ServiceFactoryExtensions.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Collections.Generic; - -namespace OmniSharp.Extensions.Embedded.MediatR -{ - public static class ServiceFactoryExtensions - { - public static T GetInstance(this ServiceFactory factory) - => (T) factory(typeof(T)); - - public static IEnumerable GetInstances(this ServiceFactory factory) - => (IEnumerable) factory(typeof(IEnumerable)); - } -} \ No newline at end of file