Adjust analyzer diagnostic severities and improve MCP001 reporting (#1038)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
This commit is contained in:
parent
af719fc576
commit
b230b17ec9
2 changed files with 17 additions and 14 deletions
|
|
@ -25,7 +25,7 @@ internal static class Diagnostics
|
|||
title: "MCP method must be partial to generate [Description] attributes",
|
||||
messageFormat: "Method '{0}' has XML documentation that could be used to generate [Description] attributes, but the method is not declared as partial.",
|
||||
category: "mcp",
|
||||
defaultSeverity: DiagnosticSeverity.Warning,
|
||||
defaultSeverity: DiagnosticSeverity.Info,
|
||||
isEnabledByDefault: true,
|
||||
description: "Methods with MCP attributes should be declared as partial to allow the source generator to emit Description attributes from XML documentation comments.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ public sealed class XmlToDescriptionGenerator : IIncrementalGenerator
|
|||
List<(IMethodSymbol MethodSymbol, MethodDeclarationSyntax MethodDeclaration, XmlDocumentation? XmlDocs)> methodsToGenerate = new(methods.Length);
|
||||
foreach (var methodModel in methods)
|
||||
{
|
||||
var xmlDocs = ExtractXmlDocumentation(methodModel.MethodSymbol, context);
|
||||
var xmlDocs = ExtractXmlDocumentation(methodModel.MethodSymbol, methodModel.MethodDeclaration, context);
|
||||
|
||||
// Generate implementation for partial methods.
|
||||
if (methodModel.MethodDeclaration.Modifiers.Any(SyntaxKind.PartialKeyword))
|
||||
|
|
@ -97,7 +97,7 @@ public sealed class XmlToDescriptionGenerator : IIncrementalGenerator
|
|||
}
|
||||
}
|
||||
|
||||
private static XmlDocumentation? ExtractXmlDocumentation(IMethodSymbol methodSymbol, SourceProductionContext context)
|
||||
private static XmlDocumentation? ExtractXmlDocumentation(IMethodSymbol methodSymbol, MethodDeclarationSyntax methodDeclaration, SourceProductionContext context)
|
||||
{
|
||||
string? xmlDoc = methodSymbol.GetDocumentationCommentXml();
|
||||
if (string.IsNullOrWhiteSpace(xmlDoc))
|
||||
|
|
@ -138,11 +138,14 @@ public sealed class XmlToDescriptionGenerator : IIncrementalGenerator
|
|||
}
|
||||
catch (System.Xml.XmlException)
|
||||
{
|
||||
// Emit warning for invalid XML
|
||||
context.ReportDiagnostic(Diagnostic.Create(
|
||||
Diagnostics.InvalidXmlDocumentation,
|
||||
methodSymbol.Locations.FirstOrDefault(),
|
||||
methodSymbol.Name));
|
||||
// Emit warning for invalid XML only if the method is partial (as that's when it would affect generated code)
|
||||
if (methodDeclaration.Modifiers.Any(SyntaxKind.PartialKeyword))
|
||||
{
|
||||
context.ReportDiagnostic(Diagnostic.Create(
|
||||
Diagnostics.InvalidXmlDocumentation,
|
||||
methodSymbol.Locations.FirstOrDefault(),
|
||||
methodSymbol.Name));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue