Skip to content

Commit d41fc26

Browse files
author
Kapil Borle
committed
Format and add inline docs
1 parent 634e2a9 commit d41fc26

File tree

3 files changed

+69
-36
lines changed

3 files changed

+69
-36
lines changed

src/PowerShellEditorServices.Protocol/LanguageServer/ScriptFileMarkersRequest.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,40 @@
77

88
namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer
99
{
10+
/// <summary>
11+
/// Class to encapsulate the request type.
12+
/// </summary>
1013
class ScriptFileMarkersRequest
1114
{
1215
public static readonly
1316
RequestType<ScriptFileMarkerRequestParams, ScriptFileMarkerRequestResultParams> Type =
1417
RequestType<ScriptFileMarkerRequestParams, ScriptFileMarkerRequestResultParams>.Create("powerShell/getScriptFileMarkers");
1518
}
1619

20+
/// <summary>
21+
/// Class to encapsulate the request parameters.
22+
/// </summary>
1723
class ScriptFileMarkerRequestParams
1824
{
25+
/// <summary>
26+
/// Path of the file for which the markers are requested.
27+
/// </summary>
1928
public string filePath;
29+
30+
/// <summary>
31+
/// Settings to provided to ScriptAnalyzer to get the markers.
32+
/// </summary>
2033
public string settings;
2134
}
2235

36+
/// <summary>
37+
/// Class to encapsulate the result of marker request.
38+
/// </summary>
2339
class ScriptFileMarkerRequestResultParams
2440
{
41+
/// <summary>
42+
/// An array of markers obtained by analyzing the given file.
43+
/// </summary>
2544
public ScriptFileMarker[] markers;
2645
}
2746
}

src/PowerShellEditorServices/Analysis/AnalysisService.cs

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public AnalysisService(IConsoleHost consoleHost, string settingsPath = null)
129129
#region Public Methods
130130

131131
/// <summary>
132-
/// Performs semantic analysis on the given ScriptFile and returns
132+
/// Perform semantic analysis on the given ScriptFile and returns
133133
/// an array of ScriptFileMarkers.
134134
/// </summary>
135135
/// <param name="file">The ScriptFile which will be analyzed for semantic markers.</param>
@@ -139,46 +139,17 @@ public ScriptFileMarker[] GetSemanticMarkers(ScriptFile file)
139139
return GetSemanticMarkers(file, activeRules, settingsPath);
140140
}
141141

142+
/// <summary>
143+
/// Perform semantic analysis on the given ScriptFile with the given settings.
144+
/// </summary>
145+
/// <param name="file">The ScriptFile to be analyzed.</param>
146+
/// <param name="settings">ScriptAnalyzer settings</param>
147+
/// <returns></returns>
142148
public ScriptFileMarker[] GetSemanticMarkers(ScriptFile file, Hashtable settings)
143149
{
144150
return GetSemanticMarkers<Hashtable>(file, null, settings);
145151
}
146152

147-
private ScriptFileMarker[] GetSemanticMarkers<TSettings>(
148-
ScriptFile file,
149-
string[] rules,
150-
TSettings settings) where TSettings: class
151-
{
152-
if (this.scriptAnalyzerModuleInfo != null
153-
&& file.IsAnalysisEnabled
154-
&& (typeof(TSettings) == typeof(string) || typeof(TSettings) == typeof(Hashtable))
155-
&& (rules != null || settings != null))
156-
{
157-
// TODO: This is a temporary fix until we can change how
158-
// ScriptAnalyzer invokes their async tasks.
159-
// TODO: Make this async
160-
Task<ScriptFileMarker[]> analysisTask =
161-
Task.Factory.StartNew<ScriptFileMarker[]>(
162-
() =>
163-
{
164-
return
165-
GetDiagnosticRecords(file, rules, settings)
166-
.Select(ScriptFileMarker.FromDiagnosticRecord)
167-
.ToArray();
168-
},
169-
CancellationToken.None,
170-
TaskCreationOptions.None,
171-
TaskScheduler.Default);
172-
analysisTask.Wait();
173-
return analysisTask.Result;
174-
}
175-
else
176-
{
177-
// Return an empty marker list
178-
return new ScriptFileMarker[0];
179-
}
180-
}
181-
182153
/// <summary>
183154
/// Returns a list of builtin-in PSScriptAnalyzer rules
184155
/// </summary>
@@ -220,6 +191,42 @@ public void Dispose()
220191
#endregion // public methods
221192

222193
#region Private Methods
194+
195+
private ScriptFileMarker[] GetSemanticMarkers<TSettings>(
196+
ScriptFile file,
197+
string[] rules,
198+
TSettings settings) where TSettings : class
199+
{
200+
if (this.scriptAnalyzerModuleInfo != null
201+
&& file.IsAnalysisEnabled
202+
&& (typeof(TSettings) == typeof(string) || typeof(TSettings) == typeof(Hashtable))
203+
&& (rules != null || settings != null))
204+
{
205+
// TODO: This is a temporary fix until we can change how
206+
// ScriptAnalyzer invokes their async tasks.
207+
// TODO: Make this async
208+
Task<ScriptFileMarker[]> analysisTask =
209+
Task.Factory.StartNew<ScriptFileMarker[]>(
210+
() =>
211+
{
212+
return
213+
GetDiagnosticRecords(file, rules, settings)
214+
.Select(ScriptFileMarker.FromDiagnosticRecord)
215+
.ToArray();
216+
},
217+
CancellationToken.None,
218+
TaskCreationOptions.None,
219+
TaskScheduler.Default);
220+
analysisTask.Wait();
221+
return analysisTask.Result;
222+
}
223+
else
224+
{
225+
// Return an empty marker list
226+
return new ScriptFileMarker[0];
227+
}
228+
}
229+
223230
private void FindPSScriptAnalyzer()
224231
{
225232
lock (runspaceLock)

src/PowerShellEditorServices/Language/LanguageService.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,13 @@ await CommandHelpers.GetCommandInfo(
450450
}
451451
}
452452

453+
/// <summary>
454+
/// Returns a hashtable from its literal representation in PowerShell.
455+
///
456+
/// If the input is null or If the method encounter any error during the conversion it returns null.
457+
/// </summary>
458+
/// <param name="hashtableString"></param>
459+
/// <returns></returns>
453460
public Hashtable GetHashtableFromString(string hashtableString)
454461
{
455462
if (hashtableString == null)

0 commit comments

Comments
 (0)