Skip to content

Commit f298def

Browse files
author
Kapil Borle
committed
Add xml comment in AnalysisService class
1 parent 80ff907 commit f298def

File tree

2 files changed

+21
-33
lines changed

2 files changed

+21
-33
lines changed

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,18 +204,12 @@ private async Task HandleSetPSSARulesRequest(
204204
}
205205

206206
var sendresult = requestContext.SendResult(null);
207-
// send the file uri from the client
208-
// retrieve the file
209-
// requestcontext is the eventcontext
210207
var scripFile = editorSession.Workspace.GetFile((string)dynParams.filepath);
211208
await RunScriptDiagnostics(
212209
new ScriptFile[] { scripFile },
213210
editorSession,
214211
requestContext.SendEvent);
215-
216212
await sendresult;
217-
218-
//await requestContext.SendResult(null);
219213
}
220214

221215
private async Task HandleGetPSSARulesRequest(

src/PowerShellEditorServices/Analysis/AnalysisService.cs

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,15 @@ public class AnalysisService : IDisposable
4646
"PSUseDeclaredVarsMoreThanAssigments"
4747
};
4848

49-
private List<string> activeRules;
50-
5149
#endregion // Private Fields
5250

5351

5452
#region Properties
5553

56-
public string[] ActiveRules
57-
{
58-
get
59-
{
60-
return activeRules != null ? activeRules.ToArray() : null;
61-
}
62-
set
63-
{
64-
activeRules = new List<string>(value); // TODO check the argument
65-
}
66-
}
54+
/// <summary>
55+
/// Set of PSScriptAnalyzer rules used for analysis
56+
/// </summary>
57+
public string[] ActiveRules { get; set; }
6758

6859
/// <summary>
6960
/// Gets or sets the path to a settings file (.psd1)
@@ -93,7 +84,7 @@ public AnalysisService(IConsoleHost consoleHost, string settingsPath = null)
9384
this.analysisRunspace = RunspaceFactory.CreateRunspace(InitialSessionState.CreateDefault2());
9485
this.analysisRunspace.ThreadOptions = PSThreadOptions.ReuseThread;
9586
this.analysisRunspace.Open();
96-
activeRules = new List<string>(IncludedRules);
87+
ActiveRules = IncludedRules.ToArray();
9788
InitializePSScriptAnalyzer();
9889
}
9990
catch (Exception e)
@@ -145,18 +136,8 @@ public ScriptFileMarker[] GetSemanticMarkers(ScriptFile file)
145136
}
146137

147138
/// <summary>
148-
/// Disposes the runspace being used by the analysis service.
139+
/// Returns a list of builtin-in PSScriptAnalyzer rules
149140
/// </summary>
150-
public void Dispose()
151-
{
152-
if (this.analysisRunspace != null)
153-
{
154-
this.analysisRunspace.Close();
155-
this.analysisRunspace.Dispose();
156-
this.analysisRunspace = null;
157-
}
158-
}
159-
160141
public IEnumerable<string> GetPSScriptAnalyzerRules()
161142
{
162143
List<string> ruleNames = new List<string>();
@@ -166,7 +147,7 @@ public IEnumerable<string> GetPSScriptAnalyzerRules()
166147
{
167148
ps.Runspace = this.analysisRunspace;
168149
var ruleObjects = ps.AddCommand("Get-ScriptAnalyzerRule").Invoke();
169-
foreach(var rule in ruleObjects)
150+
foreach (var rule in ruleObjects)
170151
{
171152
ruleNames.Add((string)rule.Members["RuleName"].Value);
172153
}
@@ -176,6 +157,19 @@ public IEnumerable<string> GetPSScriptAnalyzerRules()
176157
return ruleNames;
177158
}
178159

160+
/// <summary>
161+
/// Disposes the runspace being used by the analysis service.
162+
/// </summary>
163+
public void Dispose()
164+
{
165+
if (this.analysisRunspace != null)
166+
{
167+
this.analysisRunspace.Close();
168+
this.analysisRunspace.Dispose();
169+
this.analysisRunspace = null;
170+
}
171+
}
172+
179173
#endregion // public methods
180174

181175
#region Private Methods
@@ -284,7 +278,7 @@ private IEnumerable<PSObject> GetDiagnosticRecords(ScriptFile file)
284278
}
285279
else
286280
{
287-
powerShell.AddParameter("IncludeRule", activeRules.ToArray());
281+
powerShell.AddParameter("IncludeRule", ActiveRules);
288282
}
289283

290284
diagnosticRecords = powerShell.Invoke();

0 commit comments

Comments
 (0)