mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
using System.IO;
|
|
using Semmle.Util;
|
|
|
|
namespace Semmle.Extraction.CSharp.Entities
|
|
{
|
|
internal class CompilerDiagnostic : FreshEntity
|
|
{
|
|
private static readonly int limit = EnvironmentVariables.TryGetExtractorNumberOption<int>("COMPILER_DIAGNOSTIC_LIMIT") ?? 1000;
|
|
|
|
private readonly Microsoft.CodeAnalysis.Diagnostic diagnostic;
|
|
private readonly Compilation compilation;
|
|
private readonly int index;
|
|
|
|
public CompilerDiagnostic(Context cx, Microsoft.CodeAnalysis.Diagnostic diag, Compilation compilation, int index) : base(cx)
|
|
{
|
|
diagnostic = diag;
|
|
this.compilation = compilation;
|
|
this.index = index;
|
|
TryPopulate();
|
|
}
|
|
|
|
protected override void Populate(TextWriter trapFile)
|
|
{
|
|
if (Context.OnlyScaffold)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var key = diagnostic.Id;
|
|
var messageCount = compilation.messageCounts.AddOrUpdate(key, 1, (_, c) => c + 1);
|
|
if (messageCount > limit)
|
|
{
|
|
if (messageCount == limit + 1)
|
|
{
|
|
Context.ExtractionContext.Logger.LogWarning($"Stopped logging {key} compiler diagnostics for the current compilation after reaching {limit}");
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
trapFile.diagnostics(this, (int)diagnostic.Severity, key, diagnostic.Descriptor.Title.ToString(),
|
|
diagnostic.GetMessage(), Context.CreateLocation(diagnostic.Location));
|
|
|
|
trapFile.diagnostic_for(this, compilation, 0, index);
|
|
}
|
|
}
|
|
}
|