'Why does my C# analyzer not display messages (DiagnosticSeverity.Info)
Recently started messing around with C# analyzers and generators, and I had to find out that reported diagnostics show up fine when using DiagnosticSeverity.Warning or DiagnosticSeverity.Error, but not at all with DiagnosticSeverity.Info.
External analyzers seem to report messages just fine, so I wonder what I am doing wrong.
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
namespace Sssl.Messaging.Analyzers;
[DiagnosticAnalyzer("C#")]
public class DummyAnalyzer : DiagnosticAnalyzer
{
private static readonly DiagnosticDescriptor TypeFoundDiagnostic = new
("SSSL001", "Named Type Found", "Found Named Type {0}", "Info", DiagnosticSeverity.Warning, true);
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics =>
ImmutableArray.Create(TypeFoundDiagnostic);
public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
context.RegisterSymbolAction(AnalyzeSymbol, SymbolKind.NamedType);
}
private static void AnalyzeSymbol(SymbolAnalysisContext context)
{
context.ReportDiagnostic(Diagnostic.Create(TypeFoundDiagnostic, Location.None, context.Symbol.Name));
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
