@@ -197,7 +197,7 @@ public static Hashtable GetPSSASettingsHashtable(IDictionary<string, Hashtable>
197
197
/// <returns>An array of ScriptFileMarkers containing semantic analysis results.</returns>
198
198
public async Task < ScriptFileMarker [ ] > GetSemanticMarkersAsync ( ScriptFile file )
199
199
{
200
- return await GetSemanticMarkersAsync ( file , activeRules , settingsPath ) ;
200
+ return await GetSemanticMarkersAsync < string > ( file , activeRules , settingsPath ) ;
201
201
}
202
202
203
203
/// <summary>
@@ -211,6 +211,19 @@ public async Task<ScriptFileMarker[]> GetSemanticMarkersAsync(ScriptFile file, H
211
211
return await GetSemanticMarkersAsync < Hashtable > ( file , null , settings ) ;
212
212
}
213
213
214
+ /// <summary>
215
+ /// Perform semantic analysis on the given script with the given settings.
216
+ /// </summary>
217
+ /// <param name="scriptContent">The script content to be analyzed.</param>
218
+ /// <param name="settings">ScriptAnalyzer settings</param>
219
+ /// <returns></returns>
220
+ public async Task < ScriptFileMarker [ ] > GetSemanticMarkersAsync (
221
+ string scriptContent ,
222
+ Hashtable settings )
223
+ {
224
+ return await GetSemanticMarkersAsync < Hashtable > ( scriptContent , null , settings ) ;
225
+ }
226
+
214
227
/// <summary>
215
228
/// Returns a list of builtin-in PSScriptAnalyzer rules
216
229
/// </summary>
@@ -252,11 +265,29 @@ private async Task<ScriptFileMarker[]> GetSemanticMarkersAsync<TSettings>(
252
265
TSettings settings ) where TSettings : class
253
266
{
254
267
if ( hasScriptAnalyzerModule
255
- && file . IsAnalysisEnabled
256
- && ( typeof ( TSettings ) == typeof ( string ) || typeof ( TSettings ) == typeof ( Hashtable ) )
268
+ && file . IsAnalysisEnabled )
269
+ {
270
+ return await GetSemanticMarkersAsync < TSettings > (
271
+ file . Contents ,
272
+ rules ,
273
+ settings ) ;
274
+ }
275
+ else
276
+ {
277
+ // Return an empty marker list
278
+ return new ScriptFileMarker [ 0 ] ;
279
+ }
280
+ }
281
+
282
+ private async Task < ScriptFileMarker [ ] > GetSemanticMarkersAsync < TSettings > (
283
+ string scriptContent ,
284
+ string [ ] rules ,
285
+ TSettings settings ) where TSettings : class
286
+ {
287
+ if ( ( typeof ( TSettings ) == typeof ( string ) || typeof ( TSettings ) == typeof ( Hashtable ) )
257
288
&& ( rules != null || settings != null ) )
258
289
{
259
- var scriptFileMarkers = await GetDiagnosticRecordsAsync ( file , rules , settings ) ;
290
+ var scriptFileMarkers = await GetDiagnosticRecordsAsync ( scriptContent , rules , settings ) ;
260
291
return scriptFileMarkers . Select ( ScriptFileMarker . FromDiagnosticRecord ) . ToArray ( ) ;
261
292
}
262
293
else
@@ -318,9 +349,9 @@ private void EnumeratePSScriptAnalyzerRules()
318
349
}
319
350
320
351
private async Task < PSObject [ ] > GetDiagnosticRecordsAsync < TSettings > (
321
- ScriptFile file ,
322
- string [ ] rules ,
323
- TSettings settings ) where TSettings : class
352
+ string scriptContent ,
353
+ string [ ] rules ,
354
+ TSettings settings ) where TSettings : class
324
355
{
325
356
var diagnosticRecords = new PSObject [ 0 ] ;
326
357
@@ -346,7 +377,7 @@ private async Task<PSObject[]> GetDiagnosticRecordsAsync<TSettings>(
346
377
"Invoke-ScriptAnalyzer" ,
347
378
new Dictionary < string , object >
348
379
{
349
- { "ScriptDefinition" , file . Contents } ,
380
+ { "ScriptDefinition" , scriptContent } ,
350
381
{ settingParameter , settingArgument }
351
382
} ) ;
352
383
}
@@ -358,6 +389,7 @@ private async Task<PSObject[]> GetDiagnosticRecordsAsync<TSettings>(
358
389
return diagnosticRecords ;
359
390
}
360
391
392
+
361
393
private PSObject [ ] InvokePowerShell ( string command , IDictionary < string , object > paramArgMap )
362
394
{
363
395
using ( var powerShell = System . Management . Automation . PowerShell . Create ( ) )
@@ -389,7 +421,8 @@ private PSObject[] InvokePowerShell(string command, IDictionary<string, object>
389
421
390
422
private async Task < PSObject [ ] > InvokePowerShellAsync ( string command , IDictionary < string , object > paramArgMap )
391
423
{
392
- var task = Task . Run ( ( ) => {
424
+ var task = Task . Run ( ( ) =>
425
+ {
393
426
return InvokePowerShell ( command , paramArgMap ) ;
394
427
} ) ;
395
428
0 commit comments