Skip to content

Commit 017b1ca

Browse files
committed
Convert PsesCodeActionHandler to inherit CodeActionHandlerBase
1 parent c8fac5d commit 017b1ca

File tree

1 file changed

+16
-25
lines changed

1 file changed

+16
-25
lines changed

src/PowerShellEditorServices/Services/TextDocument/Handlers/CodeActionHandler.cs

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,46 +19,37 @@
1919

2020
namespace Microsoft.PowerShell.EditorServices.Handlers
2121
{
22-
internal class PsesCodeActionHandler : ICodeActionHandler
22+
internal class PsesCodeActionHandler : CodeActionHandlerBase
2323
{
24-
private static readonly CodeActionKind[] s_supportedCodeActions = new[]
25-
{
26-
CodeActionKind.QuickFix
27-
};
28-
29-
private readonly CodeActionRegistrationOptions _registrationOptions;
30-
3124
private readonly ILogger _logger;
32-
3325
private readonly AnalysisService _analysisService;
34-
3526
private readonly WorkspaceService _workspaceService;
3627

37-
private CodeActionCapability _capability;
38-
3928
public PsesCodeActionHandler(ILoggerFactory factory, AnalysisService analysisService, WorkspaceService workspaceService)
4029
{
4130
_logger = factory.CreateLogger<PsesCodeActionHandler>();
4231
_analysisService = analysisService;
4332
_workspaceService = workspaceService;
44-
_registrationOptions = new CodeActionRegistrationOptions
45-
{
46-
DocumentSelector = LspUtils.PowerShellDocumentSelector,
47-
CodeActionKinds = s_supportedCodeActions
48-
};
4933
}
5034

51-
public CodeActionRegistrationOptions GetRegistrationOptions()
52-
{
53-
return _registrationOptions;
54-
}
35+
protected override CodeActionRegistrationOptions CreateRegistrationOptions(CodeActionCapability capability, ClientCapabilities clientCapabilities) => new CodeActionRegistrationOptions
36+
{
37+
// TODO: What do we do with the arguments?
38+
DocumentSelector = LspUtils.PowerShellDocumentSelector,
39+
CodeActionKinds = new CodeActionKind[] { CodeActionKind.QuickFix }
40+
};
5541

56-
public void SetCapability(CodeActionCapability capability)
42+
public override async Task<CodeAction> Handle(CodeAction request, CancellationToken cancellationToken)
5743
{
58-
_capability = capability;
44+
// TODO: How on earth do we handle a CodeAction? This is new...
45+
if (cancellationToken.IsCancellationRequested)
46+
{
47+
_logger.LogDebug("CodeAction request canceled for: {0}", request.Title);
48+
}
49+
return request;
5950
}
6051

61-
public async Task<CommandOrCodeActionContainer> Handle(CodeActionParams request, CancellationToken cancellationToken)
52+
public override async Task<CommandOrCodeActionContainer> Handle(CodeActionParams request, CancellationToken cancellationToken)
6253
{
6354
if (cancellationToken.IsCancellationRequested)
6455
{
@@ -101,7 +92,7 @@ public async Task<CommandOrCodeActionContainer> Handle(CodeActionParams request,
10192
new WorkspaceEditDocumentChange(
10293
new TextDocumentEdit
10394
{
104-
TextDocument = new VersionedTextDocumentIdentifier
95+
TextDocument = new OptionalVersionedTextDocumentIdentifier
10596
{
10697
Uri = request.TextDocument.Uri
10798
},

0 commit comments

Comments
 (0)