@@ -109,6 +109,9 @@ protected override void Initialize()
109109
110110 this . SetRequestHandler ( DebugAdapterMessages . EvaluateRequest . Type , this . HandleEvaluateRequest ) ;
111111
112+ this . SetRequestHandler ( GetPSSARulesRequest . Type , this . HandleGetPSSARulesRequest ) ;
113+ this . SetRequestHandler ( SetPSSARulesRequest . Type , this . HandleSetPSSARulesRequest ) ;
114+
112115 // Initialize the extension service
113116 // TODO: This should be made awaited once Initialize is async!
114117 this . editorSession . ExtensionService . Initialize (
@@ -180,6 +183,55 @@ protected async Task HandleShowOnlineHelpRequest(
180183 await requestContext . SendResult ( null ) ;
181184 }
182185
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+
183235 private async Task HandleInstallModuleRequest (
184236 string moduleName ,
185237 RequestContext < object > requestContext
@@ -964,6 +1016,14 @@ private Task RunScriptDiagnostics(
9641016 ScriptFile [ ] filesToAnalyze ,
9651017 EditorSession editorSession ,
9661018 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 )
9671027 {
9681028 if ( ! this . currentSettings . ScriptAnalysis . Enable . Value )
9691029 {
@@ -1011,7 +1071,7 @@ private Task RunScriptDiagnostics(
10111071 filesToAnalyze ,
10121072 this . codeActionsPerFile ,
10131073 editorSession ,
1014- eventContext ,
1074+ eventSender ,
10151075 existingRequestCancellation . Token ) ,
10161076 CancellationToken . None ,
10171077 TaskCreationOptions . None ,
@@ -1020,13 +1080,32 @@ private Task RunScriptDiagnostics(
10201080 return Task . FromResult ( true ) ;
10211081 }
10221082
1083+
10231084 private static async Task DelayThenInvokeDiagnostics (
10241085 int delayMilliseconds ,
10251086 ScriptFile [ ] filesToAnalyze ,
10261087 Dictionary < string , Dictionary < string , MarkerCorrection > > correctionIndex ,
10271088 EditorSession editorSession ,
10281089 EventContext eventContext ,
10291090 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 )
10301109 {
10311110 // First of all, wait for the desired delay period before
10321111 // analyzing the provided list of files
@@ -1072,7 +1151,7 @@ await PublishScriptDiagnostics(
10721151 scriptFile ,
10731152 semanticMarkers ,
10741153 correctionIndex ,
1075- eventContext ) ;
1154+ eventSender ) ;
10761155 }
10771156 }
10781157
@@ -1081,6 +1160,19 @@ private static async Task PublishScriptDiagnostics(
10811160 ScriptFileMarker [ ] semanticMarkers ,
10821161 Dictionary < string , Dictionary < string , MarkerCorrection > > correctionIndex ,
10831162 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 )
10841176 {
10851177 List < Diagnostic > diagnostics = new List < Diagnostic > ( ) ;
10861178
@@ -1104,7 +1196,7 @@ private static async Task PublishScriptDiagnostics(
11041196
11051197 // Always send syntax and semantic errors. We want to
11061198 // make sure no out-of-date markers are being displayed.
1107- await eventContext . SendEvent (
1199+ await eventSender (
11081200 PublishDiagnosticsNotification . Type ,
11091201 new PublishDiagnosticsNotification
11101202 {
0 commit comments