@@ -197,7 +197,7 @@ public static Hashtable GetPSSASettingsHashtable(IDictionary<string, Hashtable>
197197 /// <returns>An array of ScriptFileMarkers containing semantic analysis results.</returns>
198198 public async Task < ScriptFileMarker [ ] > GetSemanticMarkersAsync ( ScriptFile file )
199199 {
200- return await GetSemanticMarkersAsync ( file , activeRules , settingsPath ) ;
200+ return await GetSemanticMarkersAsync < string > ( file , activeRules , settingsPath ) ;
201201 }
202202
203203 /// <summary>
@@ -211,6 +211,19 @@ public async Task<ScriptFileMarker[]> GetSemanticMarkersAsync(ScriptFile file, H
211211 return await GetSemanticMarkersAsync < Hashtable > ( file , null , settings ) ;
212212 }
213213
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+
214227 /// <summary>
215228 /// Returns a list of builtin-in PSScriptAnalyzer rules
216229 /// </summary>
@@ -252,11 +265,29 @@ private async Task<ScriptFileMarker[]> GetSemanticMarkersAsync<TSettings>(
252265 TSettings settings ) where TSettings : class
253266 {
254267 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 ) )
257288 && ( rules != null || settings != null ) )
258289 {
259- var scriptFileMarkers = await GetDiagnosticRecordsAsync ( file , rules , settings ) ;
290+ var scriptFileMarkers = await GetDiagnosticRecordsAsync ( scriptContent , rules , settings ) ;
260291 return scriptFileMarkers . Select ( ScriptFileMarker . FromDiagnosticRecord ) . ToArray ( ) ;
261292 }
262293 else
@@ -318,9 +349,9 @@ private void EnumeratePSScriptAnalyzerRules()
318349 }
319350
320351 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
324355 {
325356 var diagnosticRecords = new PSObject [ 0 ] ;
326357
@@ -346,7 +377,7 @@ private async Task<PSObject[]> GetDiagnosticRecordsAsync<TSettings>(
346377 "Invoke-ScriptAnalyzer" ,
347378 new Dictionary < string , object >
348379 {
349- { "ScriptDefinition" , file . Contents } ,
380+ { "ScriptDefinition" , scriptContent } ,
350381 { settingParameter , settingArgument }
351382 } ) ;
352383 }
@@ -358,6 +389,7 @@ private async Task<PSObject[]> GetDiagnosticRecordsAsync<TSettings>(
358389 return diagnosticRecords ;
359390 }
360391
392+
361393 private PSObject [ ] InvokePowerShell ( string command , IDictionary < string , object > paramArgMap )
362394 {
363395 using ( var powerShell = System . Management . Automation . PowerShell . Create ( ) )
@@ -389,7 +421,8 @@ private PSObject[] InvokePowerShell(string command, IDictionary<string, object>
389421
390422 private async Task < PSObject [ ] > InvokePowerShellAsync ( string command , IDictionary < string , object > paramArgMap )
391423 {
392- var task = Task . Run ( ( ) => {
424+ var task = Task . Run ( ( ) =>
425+ {
393426 return InvokePowerShell ( command , paramArgMap ) ;
394427 } ) ;
395428
0 commit comments