forked from OmniSharp/omnisharp-roslyn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LSP: update OmniSharpCodeHandler so we support codeAction/resolve
This feature was introduced in LSP 3.16.0 https://microsoft.github.io/language-server-protocol/specification#codeAction_resolve and allows us to drop the hack where we were introducing a special "omnisharp/executeCodeAction" command to delay the resolution of code action changesets until user actually selets that code action: see OmniSharp#1814. Related to: - OmniSharp#2068 - OmniSharp#1814
- Loading branch information
1 parent
d52c76d
commit e143515
Showing
4 changed files
with
108 additions
and
56 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
src/OmniSharp.LanguageServerProtocol/Handlers/CodeActionCommandData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using OmniSharp.Extensions.LanguageServer.Protocol; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Models; | ||
|
||
namespace OmniSharp.LanguageServerProtocol.Handlers | ||
{ | ||
internal class CodeActionCommandData | ||
{ | ||
public DocumentUri Uri { get; set; } | ||
public string Identifier { get; set; } | ||
public string Name { get; set; } | ||
public Range Range { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpCodeActionResolveHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using OmniSharp.Extensions.JsonRpc; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Models; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Server; | ||
using OmniSharp.Models.V2.CodeActions; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Document; | ||
|
||
namespace OmniSharp.LanguageServerProtocol.Handlers | ||
{ | ||
internal sealed class OmniSharpCodeActionResolveHandler : CodeActionResolveHandlerBase | ||
{ | ||
public static IEnumerable<IJsonRpcHandler> Enumerate( | ||
RequestHandlers handlers, | ||
ILanguageServer mediator, | ||
DocumentVersions versions) | ||
{ | ||
foreach (var (_, runActionHandler) in handlers | ||
.OfType<Mef.IRequestHandler<RunCodeActionRequest, RunCodeActionResponse>>()) | ||
{ | ||
yield return new OmniSharpCodeActionResolveHandler(runActionHandler, mediator, versions); | ||
} | ||
} | ||
|
||
private readonly Mef.IRequestHandler<RunCodeActionRequest, RunCodeActionResponse> _runActionHandler; | ||
private readonly ILanguageServer _server; | ||
private readonly DocumentVersions _documentVersions; | ||
|
||
public OmniSharpCodeActionResolveHandler( | ||
Mef.IRequestHandler<RunCodeActionRequest, RunCodeActionResponse> runActionHandler, | ||
ILanguageServer server, | ||
DocumentVersions documentVersions) | ||
{ | ||
_runActionHandler = runActionHandler; | ||
_server = server; | ||
_documentVersions = documentVersions; | ||
} | ||
|
||
public override async Task<CodeAction> Handle(CodeAction request, CancellationToken cancellationToken) | ||
{ | ||
var data = request.Data.ToObject<CodeActionCommandData>(); | ||
|
||
var omnisharpCaRequest = new RunCodeActionRequest | ||
{ | ||
Identifier = data.Identifier, | ||
FileName = data.Uri.GetFileSystemPath(), | ||
Column = data.Range.Start.Character, | ||
Line = data.Range.Start.Line, | ||
Selection = Helpers.FromRange(data.Range), | ||
ApplyTextChanges = false, | ||
WantsTextChanges = true, | ||
WantsAllCodeActionOperations = true | ||
}; | ||
|
||
var omnisharpCaResponse = await _runActionHandler.Handle(omnisharpCaRequest); | ||
if (omnisharpCaResponse.Changes != null) | ||
{ | ||
var edit = Helpers.ToWorkspaceEdit( | ||
omnisharpCaResponse.Changes, | ||
_server.ClientSettings.Capabilities.Workspace!.WorkspaceEdit.Value, | ||
_documentVersions | ||
); | ||
|
||
return new CodeAction | ||
{ | ||
Edit = edit, | ||
}; | ||
} | ||
else | ||
{ | ||
return new CodeAction(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters