Skip to content

Commit

Permalink
Invoke-ScriptAnalyzer: Stream diagnostics instead of batching (#2062)
Browse files Browse the repository at this point in the history
Before this commit, diagnostics for all analyzed files in this pipeline step were batched and logged at once. With this commit, diagnostics are rendered immediately.
  • Loading branch information
MatejKafka authored Feb 25, 2025
1 parent 01a3259 commit 56c6ea1
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions Engine/Commands/InvokeScriptAnalyzerCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -434,29 +434,39 @@ private void ProcessInput()
WriteToOutput(RunAnalysis());
}

private List<DiagnosticRecord> RunAnalysis()
private IEnumerable<DiagnosticRecord> RunAnalysis()
{
if (!IsFileParameterSet())
{
return ScriptAnalyzer.Instance.AnalyzeScriptDefinition(scriptDefinition, out _, out _);
foreach (var record in ScriptAnalyzer.Instance.AnalyzeScriptDefinition(scriptDefinition, out _, out _))
{
yield return record;
}
yield break;
}

var diagnostics = new List<DiagnosticRecord>();
foreach (string path in this.processedPaths)
foreach (var path in this.processedPaths)
{
if (!ShouldProcess(path, $"Analyzing path with Fix={this.fix} and Recurse={this.recurse}"))
{
continue;
}

if (fix)
{
ShouldProcess(path, $"Analyzing and fixing path with Recurse={this.recurse}");
diagnostics.AddRange(ScriptAnalyzer.Instance.AnalyzeAndFixPath(path, this.ShouldProcess, this.recurse));
foreach (var record in ScriptAnalyzer.Instance.AnalyzeAndFixPath(path, this.ShouldProcess, this.recurse))
{
yield return record;
}
}
else
{
ShouldProcess(path, $"Analyzing path with Recurse={this.recurse}");
diagnostics.AddRange(ScriptAnalyzer.Instance.AnalyzePath(path, this.ShouldProcess, this.recurse));
foreach (var record in ScriptAnalyzer.Instance.AnalyzePath(path, this.ShouldProcess, this.recurse))
{
yield return record;
}
}
}

return diagnostics;
}

private void WriteToOutput(IEnumerable<DiagnosticRecord> diagnosticRecords)
Expand Down

0 comments on commit 56c6ea1

Please sign in to comment.