Skip to content

Commit f853cee

Browse files
committed
Apply Roslyn analyzer fixes to CodeActionHandler.cs
1 parent a4c4fdf commit f853cee

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

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

+14-15
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using System.Linq;
76
using System.Threading;
87
using System.Threading.Tasks;
98
using Microsoft.Extensions.Logging;
109
using Microsoft.PowerShell.EditorServices.Services;
1110
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
1211
using Microsoft.PowerShell.EditorServices.Utility;
13-
using Newtonsoft.Json.Linq;
1412
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
1513
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
1614
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
@@ -21,21 +19,22 @@ internal class PsesCodeActionHandler : CodeActionHandlerBase
2119
{
2220
private readonly ILogger _logger;
2321
private readonly AnalysisService _analysisService;
24-
private readonly WorkspaceService _workspaceService;
2522

26-
public PsesCodeActionHandler(ILoggerFactory factory, AnalysisService analysisService, WorkspaceService workspaceService)
23+
public PsesCodeActionHandler(ILoggerFactory factory, AnalysisService analysisService)
2724
{
2825
_logger = factory.CreateLogger<PsesCodeActionHandler>();
2926
_analysisService = analysisService;
30-
_workspaceService = workspaceService;
3127
}
3228

33-
protected override CodeActionRegistrationOptions CreateRegistrationOptions(CodeActionCapability capability, ClientCapabilities clientCapabilities) => new CodeActionRegistrationOptions
29+
protected override CodeActionRegistrationOptions CreateRegistrationOptions(CodeActionCapability capability, ClientCapabilities clientCapabilities)
30+
{
31+
return new()
3432
{
35-
// TODO: What do we do with the arguments?
36-
DocumentSelector = LspUtils.PowerShellDocumentSelector,
37-
CodeActionKinds = new CodeActionKind[] { CodeActionKind.QuickFix }
38-
};
33+
// TODO: What do we do with the arguments?
34+
DocumentSelector = LspUtils.PowerShellDocumentSelector,
35+
CodeActionKinds = new CodeActionKind[] { CodeActionKind.QuickFix }
36+
};
37+
}
3938

4039
// TODO: Either fix or ignore "method lacks 'await'" warning.
4140
public override async Task<CodeAction> Handle(CodeAction request, CancellationToken cancellationToken)
@@ -65,7 +64,7 @@ public override async Task<CommandOrCodeActionContainer> Handle(CodeActionParams
6564
return Array.Empty<CommandOrCodeAction>();
6665
}
6766

68-
var codeActions = new List<CommandOrCodeAction>();
67+
List<CommandOrCodeAction> codeActions = new();
6968

7069
// If there are any code fixes, send these commands first so they appear at top of "Code Fix" menu in the client UI.
7170
foreach (Diagnostic diagnostic in request.Context.Diagnostics)
@@ -108,7 +107,7 @@ public override async Task<CommandOrCodeActionContainer> Handle(CodeActionParams
108107
// Add "show documentation" commands last so they appear at the bottom of the client UI.
109108
// These commands do not require code fixes. Sometimes we get a batch of diagnostics
110109
// to create commands for. No need to create multiple show doc commands for the same rule.
111-
var ruleNamesProcessed = new HashSet<string>();
110+
HashSet<string> ruleNamesProcessed = new();
112111
foreach (Diagnostic diagnostic in request.Context.Diagnostics)
113112
{
114113
if (
@@ -122,8 +121,8 @@ public override async Task<CommandOrCodeActionContainer> Handle(CodeActionParams
122121
if (string.Equals(diagnostic.Source, "PSScriptAnalyzer", StringComparison.OrdinalIgnoreCase) &&
123122
!ruleNamesProcessed.Contains(diagnostic.Code?.String))
124123
{
125-
ruleNamesProcessed.Add(diagnostic.Code?.String);
126-
var title = $"Show documentation for: {diagnostic.Code?.String}";
124+
_ = ruleNamesProcessed.Add(diagnostic.Code?.String);
125+
string title = $"Show documentation for: {diagnostic.Code?.String}";
127126
codeActions.Add(new CodeAction
128127
{
129128
Title = title,
@@ -135,7 +134,7 @@ public override async Task<CommandOrCodeActionContainer> Handle(CodeActionParams
135134
{
136135
Title = title,
137136
Name = "PowerShell.ShowCodeActionDocumentation",
138-
Arguments = JArray.FromObject(new[] { diagnostic.Code?.String })
137+
Arguments = Newtonsoft.Json.Linq.JArray.FromObject(new[] { diagnostic.Code?.String })
139138
}
140139
});
141140
}

0 commit comments

Comments
 (0)