I have developed my first diagnostic analyzer and installed it into a test project via NuGet. Everything works find, except that no red line is shown under the issue. I am using context.Node.GetLocation() where context is SyntaxNodeAnalysisContext.
I updated the diagnostic to write the location in the message so I could try to determine the location using context.ReportDiagnostic(Diagnostic.Create(DD_INVALID_PARAM_TYPE, location, methodSymbol.Name, location.ToString(), propertyType)); and I see in the errors window something that location is SourceFile(C:\..\..\..\Program.cs[275..276)) but the Program.cs file is only 27 lines long.
This is the full method in question at the moment:
private static void AnalyzeParameters(SyntaxNodeAnalysisContext context, IMethodSymbol methodSymbol)
{
var parameters = methodSymbol.Parameters;
if (parameters.Length != 1)
{
context.ReportDiagnostic(Diagnostic.Create(DD_INVALID_PARAM_COUNT, context.Node.GetLocation(), methodSymbol.Name, parameters.Length));
return;
}
var propertyType = ((PropertyDeclarationSyntax)context.Node).Type.ToString();
var methodInputType = parameters.First().Type.ToString();
if (propertyType != methodInputType)
{
context.ReportDiagnostic(Diagnostic.Create(DD_INVALID_PARAM_TYPE, context.Node.GetLocation(), methodSymbol.Name, methodInputType, propertyType));
}
}
where I am analyzing a property declaration and its associated attributes.