forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompilerDiagnostic.cs
More file actions
47 lines (39 loc) · 1.6 KB
/
CompilerDiagnostic.cs
File metadata and controls
47 lines (39 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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);
}
}
}