3
3
4
4
using System ;
5
5
using System . Collections . Generic ;
6
- using System . Linq ;
7
6
using System . Threading ;
8
7
using System . Threading . Tasks ;
9
8
using Microsoft . Extensions . Logging ;
10
9
using Microsoft . PowerShell . EditorServices . Services ;
11
10
using Microsoft . PowerShell . EditorServices . Services . TextDocument ;
12
11
using Microsoft . PowerShell . EditorServices . Utility ;
13
- using Newtonsoft . Json . Linq ;
14
12
using OmniSharp . Extensions . LanguageServer . Protocol . Client . Capabilities ;
15
13
using OmniSharp . Extensions . LanguageServer . Protocol . Document ;
16
14
using OmniSharp . Extensions . LanguageServer . Protocol . Models ;
@@ -21,21 +19,22 @@ internal class PsesCodeActionHandler : CodeActionHandlerBase
21
19
{
22
20
private readonly ILogger _logger ;
23
21
private readonly AnalysisService _analysisService ;
24
- private readonly WorkspaceService _workspaceService ;
25
22
26
- public PsesCodeActionHandler ( ILoggerFactory factory , AnalysisService analysisService , WorkspaceService workspaceService )
23
+ public PsesCodeActionHandler ( ILoggerFactory factory , AnalysisService analysisService )
27
24
{
28
25
_logger = factory . CreateLogger < PsesCodeActionHandler > ( ) ;
29
26
_analysisService = analysisService ;
30
- _workspaceService = workspaceService ;
31
27
}
32
28
33
- protected override CodeActionRegistrationOptions CreateRegistrationOptions ( CodeActionCapability capability , ClientCapabilities clientCapabilities ) => new CodeActionRegistrationOptions
29
+ protected override CodeActionRegistrationOptions CreateRegistrationOptions ( CodeActionCapability capability , ClientCapabilities clientCapabilities )
30
+ {
31
+ return new ( )
34
32
{
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
+ }
39
38
40
39
// TODO: Either fix or ignore "method lacks 'await'" warning.
41
40
public override async Task < CodeAction > Handle ( CodeAction request , CancellationToken cancellationToken )
@@ -65,7 +64,7 @@ public override async Task<CommandOrCodeActionContainer> Handle(CodeActionParams
65
64
return Array . Empty < CommandOrCodeAction > ( ) ;
66
65
}
67
66
68
- var codeActions = new List < CommandOrCodeAction > ( ) ;
67
+ List < CommandOrCodeAction > codeActions = new ( ) ;
69
68
70
69
// If there are any code fixes, send these commands first so they appear at top of "Code Fix" menu in the client UI.
71
70
foreach ( Diagnostic diagnostic in request . Context . Diagnostics )
@@ -108,7 +107,7 @@ public override async Task<CommandOrCodeActionContainer> Handle(CodeActionParams
108
107
// Add "show documentation" commands last so they appear at the bottom of the client UI.
109
108
// These commands do not require code fixes. Sometimes we get a batch of diagnostics
110
109
// 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 ( ) ;
112
111
foreach ( Diagnostic diagnostic in request . Context . Diagnostics )
113
112
{
114
113
if (
@@ -122,8 +121,8 @@ public override async Task<CommandOrCodeActionContainer> Handle(CodeActionParams
122
121
if ( string . Equals ( diagnostic . Source , "PSScriptAnalyzer" , StringComparison . OrdinalIgnoreCase ) &&
123
122
! ruleNamesProcessed . Contains ( diagnostic . Code ? . String ) )
124
123
{
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 } ";
127
126
codeActions . Add ( new CodeAction
128
127
{
129
128
Title = title ,
@@ -135,7 +134,7 @@ public override async Task<CommandOrCodeActionContainer> Handle(CodeActionParams
135
134
{
136
135
Title = title ,
137
136
Name = "PowerShell.ShowCodeActionDocumentation" ,
138
- Arguments = JArray . FromObject ( new [ ] { diagnostic . Code ? . String } )
137
+ Arguments = Newtonsoft . Json . Linq . JArray . FromObject ( new [ ] { diagnostic . Code ? . String } )
139
138
}
140
139
} ) ;
141
140
}
0 commit comments