Skip to content

Commit

Permalink
Merge pull request #1807 from razzmatazz/lsp-omnisharp-client-find-re…
Browse files Browse the repository at this point in the history
…fs-command

LSP: expose omnisharp/client/findReferences custom command for code lenses
  • Loading branch information
david-driscoll authored May 24, 2020
2 parents a8d639f + d3f47ab commit 402cfbc
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -78,10 +80,23 @@ public async override Task<CodeLens> 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<Uri>(),
Range = request.Range,
},
jsonCamelCaseContract)
}),
};

return request;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<IJsonRpcHandler> Enumerate(RequestHandlers handlers)
{
yield return new OmniSharpExecuteCommandHandler();
}

public OmniSharpExecuteCommandHandler()
: base (new ExecuteCommandRegistrationOptions() {
Commands = new Container<string>(),
})
{
}

public override Task<Unit>
Handle(ExecuteCommandParams request, CancellationToken cancellationToken)
{
return Task.FromResult(Unit.Value);
}
}
}
1 change: 1 addition & 0 deletions src/OmniSharp.LanguageServerProtocol/LanguageServerHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 402cfbc

Please sign in to comment.