mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-04-19 22:08:34 -04:00
Avoids unnecessary reparsing and allocations by reusing identical trees, and running generators only on what's been modified, significantly reducing incremental compile times for small changes in large codebases.
31 lines
720 B
C#
31 lines
720 B
C#
using Microsoft.CodeAnalysis;
|
|
using Microsoft.CodeAnalysis.CSharp;
|
|
using System.Collections.Concurrent;
|
|
|
|
namespace Sandbox;
|
|
|
|
partial class Compiler
|
|
{
|
|
private void RunBlacklistWalker( CSharpCompilation compiler, IEnumerable<SyntaxTree> syntaxTrees, CompilerOutput output )
|
|
{
|
|
if ( !syntaxTrees.Any() )
|
|
{
|
|
return;
|
|
}
|
|
|
|
ConcurrentBag<Diagnostic> diagnostics = new();
|
|
|
|
var result = System.Threading.Tasks.Parallel.ForEach( syntaxTrees, tree =>
|
|
{
|
|
var semanticModel = compiler.GetSemanticModel( tree );
|
|
|
|
var walker = new BlacklistCodeWalker( semanticModel );
|
|
walker.Visit( tree.GetRoot() );
|
|
|
|
walker.Diagnostics.ForEach( diagnostics.Add );
|
|
} );
|
|
|
|
output.Diagnostics.AddRange( diagnostics );
|
|
}
|
|
}
|