Skip to content

Commit c3d46fd

Browse files
author
Kapil Borle
committed
Return list of active PSSA rules
1 parent c63b449 commit c3d46fd

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,18 @@ private async Task HandleGetPSSARulesRequest(
187187
RequestContext<object> requestContext)
188188
{
189189
List<string> ruleList = new List<string>();
190+
List<object> rules = new List<object>();
190191
if (editorSession.AnalysisService != null)
191192
{
192193
var ruleNames = editorSession.AnalysisService.GetPSScriptAnalyzerRules();
194+
var activeRules = editorSession.AnalysisService.ActiveRules;
193195
foreach (var ruleName in ruleNames)
194196
{
195-
ruleList.Add(ruleName);
197+
rules.Add(new { Name = ruleName, IsEnabled = activeRules.Contains(ruleName, StringComparer.OrdinalIgnoreCase) });
196198
}
197199
}
198-
await requestContext.SendResult(ruleList);
200+
201+
await requestContext.SendResult(rules);
199202
}
200203

201204
private async Task HandleInstallModuleRequest(

src/PowerShellEditorServices/Analysis/AnalysisService.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,18 @@ public class AnalysisService : IDisposable
4646
"PSUseDeclaredVarsMoreThanAssigments"
4747
};
4848

49+
private List<string> activeRules;
50+
4951
#endregion // Private Fields
5052

5153

5254
#region Properties
5355

56+
public string[] ActiveRules
57+
{
58+
get { return activeRules != null ? activeRules.ToArray() : null; }
59+
}
60+
5461
/// <summary>
5562
/// Gets or sets the path to a settings file (.psd1)
5663
/// containing PSScriptAnalyzer settings.
@@ -79,6 +86,7 @@ public AnalysisService(IConsoleHost consoleHost, string settingsPath = null)
7986
this.analysisRunspace = RunspaceFactory.CreateRunspace(InitialSessionState.CreateDefault2());
8087
this.analysisRunspace.ThreadOptions = PSThreadOptions.ReuseThread;
8188
this.analysisRunspace.Open();
89+
activeRules = new List<string>(IncludedRules);
8290
InitializePSScriptAnalyzer();
8391
}
8492
catch (Exception e)
@@ -269,7 +277,7 @@ private IEnumerable<PSObject> GetDiagnosticRecords(ScriptFile file)
269277
}
270278
else
271279
{
272-
powerShell.AddParameter("IncludeRule", IncludedRules);
280+
powerShell.AddParameter("IncludeRule", activeRules.ToArray());
273281
}
274282

275283
diagnosticRecords = powerShell.Invoke();

0 commit comments

Comments
 (0)