Skip to content

Commit d4d3c26

Browse files
committed
Add generated XML docs to __IMessengerExtensions
1 parent 1ca30ff commit d4d3c26

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

src/CommunityToolkit.Mvvm.SourceGenerators/Messaging/IMessengerRegisterAllGenerator.Execute.cs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System.Collections.Immutable;
66
using System.Linq;
7+
using CommunityToolkit.Mvvm.SourceGenerators.ComponentModel.Models;
78
using CommunityToolkit.Mvvm.SourceGenerators.Extensions;
89
using CommunityToolkit.Mvvm.SourceGenerators.Helpers;
910
using CommunityToolkit.Mvvm.SourceGenerators.Messaging.Models;
@@ -74,6 +75,9 @@ public static CompilationUnitSyntax GetSyntax(bool isDynamicallyAccessedMembersA
7475

7576
// Prepare the base attributes with are always present:
7677
//
78+
// /// <summary>
79+
// /// A helper type with generated registration stubs for types implementing <see cref="global::CommunityToolkit.Mvvm.Messaging.IRecipient{T}"/>.
80+
// /// </summary>
7781
// [global::System.CodeDom.Compiler.GeneratedCode("...", "...")]
7882
// [global::System.Diagnostics.DebuggerNonUserCode]
7983
// [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
@@ -83,7 +87,11 @@ public static CompilationUnitSyntax GetSyntax(bool isDynamicallyAccessedMembersA
8387
AttributeList(SingletonSeparatedList(
8488
Attribute(IdentifierName($"global::System.CodeDom.Compiler.GeneratedCode")).AddArgumentListArguments(
8589
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(IMessengerRegisterAllGenerator).FullName))),
86-
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(IMessengerRegisterAllGenerator).Assembly.GetName().Version.ToString())))))));
90+
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(IMessengerRegisterAllGenerator).Assembly.GetName().Version.ToString()))))))
91+
.WithOpenBracketToken(Token(TriviaList(
92+
Comment("/// <summary>"),
93+
Comment("/// A helper type with generated registration stubs for types implementing <see cref=\"global::CommunityToolkit.Mvvm.Messaging.IRecipient{T}\"/>."),
94+
Comment("/// </summary>")), SyntaxKind.OpenBracketToken, TriviaList())));
8795
attributes.Add(AttributeList(SingletonSeparatedList(Attribute(IdentifierName("global::System.Diagnostics.DebuggerNonUserCode")))));
8896
attributes.Add(AttributeList(SingletonSeparatedList(Attribute(IdentifierName("global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage")))));
8997
attributes.Add(
@@ -146,6 +154,11 @@ public static CompilationUnitSyntax GetSyntax(RecipientInfo recipientInfo)
146154
// with no tokens, which is the most common scenario and will help particularly with AOT.
147155
// This code will produce a syntax tree as follows:
148156
//
157+
// /// <summary>
158+
// /// Creates a message registration stub for <see cref="<RECIPIENT_TYPE>"/> objects.
159+
// /// </summary>
160+
// /// <param name="_">Dummy parameter, only used to disambiguate the method signature.</param>
161+
// /// <returns>A message registration stub for <see cref="<RECIPIENT_TYPE>"/> objects.</returns>
149162
// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
150163
// [global::System.Obsolete("This method is not intended to be called directly by user code")]
151164
// public static global::System.Action<global::CommunityToolkit.Mvvm.Messaging.IMessenger, object> CreateAllMessagesRegistrator(<RECIPIENT_TYPE> _)
@@ -166,7 +179,13 @@ public static CompilationUnitSyntax GetSyntax(RecipientInfo recipientInfo)
166179
Identifier("CreateAllMessagesRegistrator")).AddAttributeLists(
167180
AttributeList(SingletonSeparatedList(
168181
Attribute(IdentifierName("global::System.ComponentModel.EditorBrowsable")).AddArgumentListArguments(
169-
AttributeArgument(ParseExpression("global::System.ComponentModel.EditorBrowsableState.Never"))))),
182+
AttributeArgument(ParseExpression("global::System.ComponentModel.EditorBrowsableState.Never")))))
183+
.WithOpenBracketToken(Token(TriviaList(
184+
Comment("/// <summary>"),
185+
Comment($"/// Creates a message registration stub for <see cref=\"{recipientInfo.TypeName}\"/> objects."),
186+
Comment("/// </summary>"),
187+
Comment("/// <param name=\"_\">Dummy parameter, only used to disambiguate the method signature.</param>"),
188+
Comment($"/// <returns>A message registration stub for <see cref=\"{recipientInfo.TypeName}\"/> objects.</returns>")), SyntaxKind.OpenBracketToken, TriviaList())),
170189
AttributeList(SingletonSeparatedList(
171190
Attribute(IdentifierName("global::System.Obsolete")).AddArgumentListArguments(
172191
AttributeArgument(LiteralExpression(
@@ -199,6 +218,12 @@ public static CompilationUnitSyntax GetSyntax(RecipientInfo recipientInfo)
199218
// Note: the generic overload has a different name to simplify the lookup with reflection.
200219
// This code will produce a syntax tree as follows:
201220
//
221+
// /// <summary>
222+
// /// Creates a message registration stub for <see cref="<RECIPIENT_TYPE>"/> objects, with an input token.
223+
// /// </summary>
224+
// /// <typeparam name="TToken">The type of tokens that will be used to register messages.
225+
// /// <param name="_">Dummy parameter, only used to disambiguate the method signature.</param>
226+
// /// <returns>A message registration stub for <see cref="<RECIPIENT_TYPE>"/> objects.</returns>
202227
// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
203228
// [global::System.Obsolete("This method is not intended to be called directly by user code")]
204229
// public static global::System.Action<global::CommunityToolkit.Mvvm.Messaging.IMessenger, object, TToken> CreateAllMessagesRegistratorWithToken<TToken>(<RECIPIENT_TYPE> _)
@@ -221,7 +246,14 @@ public static CompilationUnitSyntax GetSyntax(RecipientInfo recipientInfo)
221246
Identifier("CreateAllMessagesRegistratorWithToken")).AddAttributeLists(
222247
AttributeList(SingletonSeparatedList(
223248
Attribute(IdentifierName("global::System.ComponentModel.EditorBrowsable")).AddArgumentListArguments(
224-
AttributeArgument(ParseExpression("global::System.ComponentModel.EditorBrowsableState.Never"))))),
249+
AttributeArgument(ParseExpression("global::System.ComponentModel.EditorBrowsableState.Never")))))
250+
.WithOpenBracketToken(Token(TriviaList(
251+
Comment("/// <summary>"),
252+
Comment($"/// Creates a message registration stub for <see cref=\"{recipientInfo.TypeName}\"/> objects."),
253+
Comment("/// </summary>"),
254+
Comment("/// <typeparam name=\"TToken\">The type of tokens that will be used to register messages.</typeparam>"),
255+
Comment("/// <param name=\"_\">Dummy parameter, only used to disambiguate the method signature.</param>"),
256+
Comment($"/// <returns>A message registration stub for <see cref=\"{recipientInfo.TypeName}\"/> objects.</returns>")), SyntaxKind.OpenBracketToken, TriviaList())),
225257
AttributeList(SingletonSeparatedList(
226258
Attribute(IdentifierName("global::System.Obsolete")).AddArgumentListArguments(
227259
AttributeArgument(LiteralExpression(
@@ -261,6 +293,7 @@ public static CompilationUnitSyntax GetSyntax(RecipientInfo recipientInfo)
261293
// #pragma warning disable
262294
// namespace CommunityToolkit.Mvvm.Messaging.__Internals
263295
// {
296+
// /// <inheritdoc/>
264297
// partial class __IMessengerExtensions
265298
// {
266299
// <GENERATED_MEMBERS>
@@ -271,7 +304,8 @@ public static CompilationUnitSyntax GetSyntax(RecipientInfo recipientInfo)
271304
NamespaceDeclaration(IdentifierName("CommunityToolkit.Mvvm.Messaging.__Internals")).WithLeadingTrivia(TriviaList(
272305
Comment("// <auto-generated/>"),
273306
Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true)))).AddMembers(
274-
ClassDeclaration("__IMessengerExtensions").AddModifiers(Token(SyntaxKind.PartialKeyword))
307+
ClassDeclaration("__IMessengerExtensions").AddModifiers(
308+
Token(TriviaList(Comment("/// <inheritdoc/>")), SyntaxKind.PartialKeyword, TriviaList()))
275309
.AddMembers(defaultChannelMethodDeclaration, customChannelMethodDeclaration)))
276310
.NormalizeWhitespace();
277311
}

0 commit comments

Comments
 (0)