From bcf8207b23dd41e11224f94ab44db622a8fa3bb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saulius=20Menkevic=CC=8Cius?= Date: Fri, 22 May 2020 09:25:20 +0300 Subject: [PATCH 1/3] LSP: add (empty) handler for workspace/executeCommand --- .../OmniSharpExecuteCommandHandler.cs | 31 +++++++++++++++++++ .../LanguageServerHost.cs | 1 + 2 files changed, 32 insertions(+) create mode 100644 src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpExecuteCommandHandler.cs diff --git a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpExecuteCommandHandler.cs b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpExecuteCommandHandler.cs new file mode 100644 index 0000000000..bab4b1c4ae --- /dev/null +++ b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpExecuteCommandHandler.cs @@ -0,0 +1,31 @@ +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using MediatR; +using OmniSharp.Extensions.JsonRpc; +using OmniSharp.Extensions.LanguageServer.Protocol.Models; +using OmniSharp.Extensions.LanguageServer.Protocol.Server; + +namespace OmniSharp.LanguageServerProtocol.Handlers +{ + class OmniSharpExecuteCommandHandler : ExecuteCommandHandler + { + public static IEnumerable Enumerate(RequestHandlers handlers) + { + yield return new OmniSharpExecuteCommandHandler(); + } + + public OmniSharpExecuteCommandHandler() + : base (new ExecuteCommandRegistrationOptions() { + Commands = new Container(), + }) + { + } + + public override Task + Handle(ExecuteCommandParams request, CancellationToken cancellationToken) + { + return Task.FromResult(Unit.Value); + } + } +} diff --git a/src/OmniSharp.LanguageServerProtocol/LanguageServerHost.cs b/src/OmniSharp.LanguageServerProtocol/LanguageServerHost.cs index 536b83758d..368867c1d0 100644 --- a/src/OmniSharp.LanguageServerProtocol/LanguageServerHost.cs +++ b/src/OmniSharp.LanguageServerProtocol/LanguageServerHost.cs @@ -169,6 +169,7 @@ private Task Initialize(Extensions.LanguageServer.Server.ILanguageServer server, .Concat(OmniSharpCodeActionHandler.Enumerate(_handlers)) .Concat(OmniSharpDocumentFormattingHandler.Enumerate(_handlers)) .Concat(OmniSharpDocumentFormatRangeHandler.Enumerate(_handlers)) + .Concat(OmniSharpExecuteCommandHandler.Enumerate(_handlers)) .Concat(OmniSharpDocumentOnTypeFormatHandler.Enumerate(_handlers))) { server.AddHandlers(handler); From 718d3b4433bf5f2b810d3063944fcb7a0968e3a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saulius=20Menkevic=CC=8Cius?= Date: Fri, 22 May 2020 09:26:14 +0300 Subject: [PATCH 2/3] LSP: code lens -- hook up a custom 'omnisharp/client/findReferences' command This custom command is meant to be handled by LSP client to display references on a given Location. --- .../Handlers/OmniSharpCodeLensHandler.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpCodeLensHandler.cs b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpCodeLensHandler.cs index 9b79e8da0b..216164dcf1 100644 --- a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpCodeLensHandler.cs +++ b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpCodeLensHandler.cs @@ -3,7 +3,9 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Newtonsoft.Json.Serialization; using OmniSharp.Extensions.JsonRpc; using OmniSharp.Extensions.LanguageServer.Protocol; using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities; @@ -78,10 +80,23 @@ public async override Task Handle(CodeLens request, CancellationToken var length = omnisharpResponse?.QuickFixes?.Count() ?? 0; + var jsonCamelCaseContract = new JsonSerializer { + ContractResolver = new CamelCasePropertyNamesContractResolver() + }; + request.Command = new Command { - Title = length == 1 ? "1 reference" : $"{length} references" - // TODO: Hook up command. + Title = length == 1 ? "1 reference" : $"{length} references", + Name = "omnisharp/client/findReferences", + Arguments = new JArray( + new [] { + JObject.FromObject( + new Location { + Uri = request.Data.ToObject(), + Range = request.Range, + }, + jsonCamelCaseContract) + }), }; return request; From d3f47abde6f2914bf26471a7f851d2c2d36a2aac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saulius=20Menkevic=CC=8Cius?= Date: Fri, 22 May 2020 09:43:20 +0300 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8afa01207b..1fc2ece9d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All changes to the project will be documented in this file. ## [1.35.3] - not yet released * Added LSP handler for `textDocument/codeAction` request. (PR: [#1795](https://github.com/OmniSharp/omnisharp-roslyn/pull/1795)) +* Expose a custom LSP `omnisharp/client/findReferences` command via code lens (meant to be handled by LSP client). (PR: [#1807](https://github.com/OmniSharp/omnisharp-roslyn/pull/1807)) ## [1.35.2] - 2020-05-20 * Added support for `WarningsAsErrors` in csproj files (PR: [#1779](https://github.com/OmniSharp/omnisharp-roslyn/pull/1779))