Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LSP: expose omnisharp/client/findReferences custom command for code lenses #1807

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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