Skip to content

Commit f09d70c

Browse files
author
Kapil Borle
committed
Execute formatter only if module is present
1 parent 0b8e8a2 commit f09d70c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/PowerShellEditorServices/Analysis/AnalysisService.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,25 @@ public IEnumerable<string> GetPSScriptAnalyzerRules()
246246
return ruleNames;
247247
}
248248

249+
/// <summary>
250+
/// Format a given script text with default codeformatting settings.
251+
/// </summary>
252+
/// <param name="scriptDefinition">Script text to be formatted</param>
253+
/// <returns>The formatted script text.</returns>
249254
public async Task<string> Format(string scriptDefinition)
250255
{
251-
var result = InvokePowerShellAsync(
256+
if (!hasScriptAnalyzerModule)
257+
{
258+
return null;
259+
}
260+
261+
var result = await InvokePowerShellAsync(
252262
"Invoke-Formatter",
253263
new Dictionary<string, object> {
254264
{"ScriptDefinition", scriptDefinition}
255265
});
256266

257-
return (await result)?.Select(r => r.ImmediateBaseObject as string).FirstOrDefault();
267+
return result?.Select(r => r.ImmediateBaseObject as string).FirstOrDefault();
258268
}
259269

260270
/// <summary>

0 commit comments

Comments
 (0)