@@ -109,6 +109,9 @@ protected override void Initialize()
109
109
110
110
this . SetRequestHandler ( DebugAdapterMessages . EvaluateRequest . Type , this . HandleEvaluateRequest ) ;
111
111
112
+ this . SetRequestHandler ( GetPSSARulesRequest . Type , this . HandleGetPSSARulesRequest ) ;
113
+ this . SetRequestHandler ( SetPSSARulesRequest . Type , this . HandleSetPSSARulesRequest ) ;
114
+
112
115
// Initialize the extension service
113
116
// TODO: This should be made awaited once Initialize is async!
114
117
this . editorSession . ExtensionService . Initialize (
@@ -180,6 +183,55 @@ protected async Task HandleShowOnlineHelpRequest(
180
183
await requestContext . SendResult ( null ) ;
181
184
}
182
185
186
+ private async Task HandleSetPSSARulesRequest (
187
+ object param ,
188
+ RequestContext < object > requestContext )
189
+ {
190
+ var dynParams = param as dynamic ;
191
+ if ( editorSession . AnalysisService != null &&
192
+ editorSession . AnalysisService . SettingsPath == null )
193
+ {
194
+ var activeRules = new List < string > ( ) ;
195
+ var ruleInfos = dynParams . ruleInfos ;
196
+ foreach ( dynamic ruleInfo in ruleInfos )
197
+ {
198
+ if ( ( Boolean ) ruleInfo . isEnabled )
199
+ {
200
+ activeRules . Add ( ( string ) ruleInfo . name ) ;
201
+ }
202
+ }
203
+ editorSession . AnalysisService . ActiveRules = activeRules . ToArray ( ) ;
204
+ }
205
+
206
+ var sendresult = requestContext . SendResult ( null ) ;
207
+ var scripFile = editorSession . Workspace . GetFile ( ( string ) dynParams . filepath ) ;
208
+ await RunScriptDiagnostics (
209
+ new ScriptFile [ ] { scripFile } ,
210
+ editorSession ,
211
+ requestContext . SendEvent ) ;
212
+ await sendresult ;
213
+ }
214
+
215
+ private async Task HandleGetPSSARulesRequest (
216
+ object param ,
217
+ RequestContext < object > requestContext )
218
+ {
219
+ List < object > rules = null ;
220
+ if ( editorSession . AnalysisService != null
221
+ && editorSession . AnalysisService . SettingsPath == null )
222
+ {
223
+ rules = new List < object > ( ) ;
224
+ var ruleNames = editorSession . AnalysisService . GetPSScriptAnalyzerRules ( ) ;
225
+ var activeRules = editorSession . AnalysisService . ActiveRules ;
226
+ foreach ( var ruleName in ruleNames )
227
+ {
228
+ rules . Add ( new { name = ruleName , isEnabled = activeRules . Contains ( ruleName , StringComparer . OrdinalIgnoreCase ) } ) ;
229
+ }
230
+ }
231
+
232
+ await requestContext . SendResult ( rules ) ;
233
+ }
234
+
183
235
private async Task HandleInstallModuleRequest (
184
236
string moduleName ,
185
237
RequestContext < object > requestContext
@@ -964,6 +1016,14 @@ private Task RunScriptDiagnostics(
964
1016
ScriptFile [ ] filesToAnalyze ,
965
1017
EditorSession editorSession ,
966
1018
EventContext eventContext )
1019
+ {
1020
+ return RunScriptDiagnostics ( filesToAnalyze , editorSession , eventContext . SendEvent ) ;
1021
+ }
1022
+
1023
+ private Task RunScriptDiagnostics (
1024
+ ScriptFile [ ] filesToAnalyze ,
1025
+ EditorSession editorSession ,
1026
+ Func < EventType < PublishDiagnosticsNotification > , PublishDiagnosticsNotification , Task > eventSender )
967
1027
{
968
1028
if ( ! this . currentSettings . ScriptAnalysis . Enable . Value )
969
1029
{
@@ -1011,7 +1071,7 @@ private Task RunScriptDiagnostics(
1011
1071
filesToAnalyze ,
1012
1072
this . codeActionsPerFile ,
1013
1073
editorSession ,
1014
- eventContext ,
1074
+ eventSender ,
1015
1075
existingRequestCancellation . Token ) ,
1016
1076
CancellationToken . None ,
1017
1077
TaskCreationOptions . None ,
@@ -1020,13 +1080,32 @@ private Task RunScriptDiagnostics(
1020
1080
return Task . FromResult ( true ) ;
1021
1081
}
1022
1082
1083
+
1023
1084
private static async Task DelayThenInvokeDiagnostics (
1024
1085
int delayMilliseconds ,
1025
1086
ScriptFile [ ] filesToAnalyze ,
1026
1087
Dictionary < string , Dictionary < string , MarkerCorrection > > correctionIndex ,
1027
1088
EditorSession editorSession ,
1028
1089
EventContext eventContext ,
1029
1090
CancellationToken cancellationToken )
1091
+ {
1092
+ await DelayThenInvokeDiagnostics (
1093
+ delayMilliseconds ,
1094
+ filesToAnalyze ,
1095
+ correctionIndex ,
1096
+ editorSession ,
1097
+ eventContext . SendEvent ,
1098
+ cancellationToken ) ;
1099
+ }
1100
+
1101
+
1102
+ private static async Task DelayThenInvokeDiagnostics (
1103
+ int delayMilliseconds ,
1104
+ ScriptFile [ ] filesToAnalyze ,
1105
+ Dictionary < string , Dictionary < string , MarkerCorrection > > correctionIndex ,
1106
+ EditorSession editorSession ,
1107
+ Func < EventType < PublishDiagnosticsNotification > , PublishDiagnosticsNotification , Task > eventSender ,
1108
+ CancellationToken cancellationToken )
1030
1109
{
1031
1110
// First of all, wait for the desired delay period before
1032
1111
// analyzing the provided list of files
@@ -1072,7 +1151,7 @@ await PublishScriptDiagnostics(
1072
1151
scriptFile ,
1073
1152
semanticMarkers ,
1074
1153
correctionIndex ,
1075
- eventContext ) ;
1154
+ eventSender ) ;
1076
1155
}
1077
1156
}
1078
1157
@@ -1081,6 +1160,19 @@ private static async Task PublishScriptDiagnostics(
1081
1160
ScriptFileMarker [ ] semanticMarkers ,
1082
1161
Dictionary < string , Dictionary < string , MarkerCorrection > > correctionIndex ,
1083
1162
EventContext eventContext )
1163
+ {
1164
+ await PublishScriptDiagnostics (
1165
+ scriptFile ,
1166
+ semanticMarkers ,
1167
+ correctionIndex ,
1168
+ eventContext . SendEvent ) ;
1169
+ }
1170
+
1171
+ private static async Task PublishScriptDiagnostics (
1172
+ ScriptFile scriptFile ,
1173
+ ScriptFileMarker [ ] semanticMarkers ,
1174
+ Dictionary < string , Dictionary < string , MarkerCorrection > > correctionIndex ,
1175
+ Func < EventType < PublishDiagnosticsNotification > , PublishDiagnosticsNotification , Task > eventSender )
1084
1176
{
1085
1177
List < Diagnostic > diagnostics = new List < Diagnostic > ( ) ;
1086
1178
@@ -1104,7 +1196,7 @@ private static async Task PublishScriptDiagnostics(
1104
1196
1105
1197
// Always send syntax and semantic errors. We want to
1106
1198
// make sure no out-of-date markers are being displayed.
1107
- await eventContext . SendEvent (
1199
+ await eventSender (
1108
1200
PublishDiagnosticsNotification . Type ,
1109
1201
new PublishDiagnosticsNotification
1110
1202
{
0 commit comments