Skip to content

Commit 4a2c36c

Browse files
Copilotstephentoub
andauthored
Use fully-qualified type names in generated partial method signatures (#1135)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
1 parent b2afc2f commit 4a2c36c

File tree

2 files changed

+394
-5
lines changed

2 files changed

+394
-5
lines changed

src/ModelContextProtocol.Analyzers/XmlToDescriptionGenerator.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ public sealed class XmlToDescriptionGenerator : IIncrementalGenerator
1919
{
2020
private const string GeneratedFileName = "ModelContextProtocol.Descriptions.g.cs";
2121

22+
/// <summary>
23+
/// A display format that produces fully-qualified type names with "global::" prefix
24+
/// and includes nullability annotations.
25+
/// </summary>
26+
private static readonly SymbolDisplayFormat s_fullyQualifiedFormatWithNullability =
27+
SymbolDisplayFormat.FullyQualifiedFormat.AddMiscellaneousOptions(
28+
SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier);
29+
2230
public void Initialize(IncrementalGeneratorInitializationContext context)
2331
{
2432
// Extract method information for all MCP tools, prompts, and resources.
@@ -125,7 +133,7 @@ private static MethodToGenerate ExtractMethodInfo(
125133
.Where(m => !m.IsKind(SyntaxKind.AsyncKeyword))
126134
.Select(m => m.Text);
127135
string modifiersStr = string.Join(" ", modifiers);
128-
string returnType = methodSymbol.ReturnType.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat);
136+
string returnType = methodSymbol.ReturnType.ToDisplayString(s_fullyQualifiedFormatWithNullability);
129137
string methodName = methodSymbol.Name;
130138

131139
// Extract parameters
@@ -137,7 +145,7 @@ private static MethodToGenerate ExtractMethodInfo(
137145
var paramSyntax = i < parameterSyntaxList.Count ? parameterSyntaxList[i] : null;
138146

139147
parameters[i] = new ParameterInfo(
140-
ParameterType: param.Type.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat),
148+
ParameterType: param.Type.ToDisplayString(s_fullyQualifiedFormatWithNullability),
141149
Name: param.Name,
142150
HasDescriptionAttribute: descriptionAttribute is not null && HasAttribute(param, descriptionAttribute),
143151
XmlDescription: xmlDocs?.Parameters.TryGetValue(param.Name, out var pd) == true && !string.IsNullOrWhiteSpace(pd) ? pd : null,

0 commit comments

Comments
 (0)