From d4d3c267b49671b4de7f219be1b1675b1a0a2336 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 25 Mar 2023 20:54:38 +0100 Subject: [PATCH] Add generated XML docs to __IMessengerExtensions --- .../IMessengerRegisterAllGenerator.Execute.cs | 42 +++++++++++++++++-- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/CommunityToolkit.Mvvm.SourceGenerators/Messaging/IMessengerRegisterAllGenerator.Execute.cs b/src/CommunityToolkit.Mvvm.SourceGenerators/Messaging/IMessengerRegisterAllGenerator.Execute.cs index 6a50d4b62..516a3bd2d 100644 --- a/src/CommunityToolkit.Mvvm.SourceGenerators/Messaging/IMessengerRegisterAllGenerator.Execute.cs +++ b/src/CommunityToolkit.Mvvm.SourceGenerators/Messaging/IMessengerRegisterAllGenerator.Execute.cs @@ -4,6 +4,7 @@ using System.Collections.Immutable; using System.Linq; +using CommunityToolkit.Mvvm.SourceGenerators.ComponentModel.Models; using CommunityToolkit.Mvvm.SourceGenerators.Extensions; using CommunityToolkit.Mvvm.SourceGenerators.Helpers; using CommunityToolkit.Mvvm.SourceGenerators.Messaging.Models; @@ -74,6 +75,9 @@ public static CompilationUnitSyntax GetSyntax(bool isDynamicallyAccessedMembersA // Prepare the base attributes with are always present: // + // /// + // /// A helper type with generated registration stubs for types implementing . + // /// // [global::System.CodeDom.Compiler.GeneratedCode("...", "...")] // [global::System.Diagnostics.DebuggerNonUserCode] // [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] @@ -83,7 +87,11 @@ public static CompilationUnitSyntax GetSyntax(bool isDynamicallyAccessedMembersA AttributeList(SingletonSeparatedList( Attribute(IdentifierName($"global::System.CodeDom.Compiler.GeneratedCode")).AddArgumentListArguments( AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(IMessengerRegisterAllGenerator).FullName))), - AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(IMessengerRegisterAllGenerator).Assembly.GetName().Version.ToString()))))))); + AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(IMessengerRegisterAllGenerator).Assembly.GetName().Version.ToString())))))) + .WithOpenBracketToken(Token(TriviaList( + Comment("/// "), + Comment("/// A helper type with generated registration stubs for types implementing ."), + Comment("/// ")), SyntaxKind.OpenBracketToken, TriviaList()))); attributes.Add(AttributeList(SingletonSeparatedList(Attribute(IdentifierName("global::System.Diagnostics.DebuggerNonUserCode"))))); attributes.Add(AttributeList(SingletonSeparatedList(Attribute(IdentifierName("global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage"))))); attributes.Add( @@ -146,6 +154,11 @@ public static CompilationUnitSyntax GetSyntax(RecipientInfo recipientInfo) // with no tokens, which is the most common scenario and will help particularly with AOT. // This code will produce a syntax tree as follows: // + // /// + // /// Creates a message registration stub for objects. + // /// + // /// Dummy parameter, only used to disambiguate the method signature. + // /// A message registration stub for objects. // [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] // [global::System.Obsolete("This method is not intended to be called directly by user code")] // public static global::System.Action CreateAllMessagesRegistrator( _) @@ -166,7 +179,13 @@ public static CompilationUnitSyntax GetSyntax(RecipientInfo recipientInfo) Identifier("CreateAllMessagesRegistrator")).AddAttributeLists( AttributeList(SingletonSeparatedList( Attribute(IdentifierName("global::System.ComponentModel.EditorBrowsable")).AddArgumentListArguments( - AttributeArgument(ParseExpression("global::System.ComponentModel.EditorBrowsableState.Never"))))), + AttributeArgument(ParseExpression("global::System.ComponentModel.EditorBrowsableState.Never"))))) + .WithOpenBracketToken(Token(TriviaList( + Comment("/// "), + Comment($"/// Creates a message registration stub for objects."), + Comment("/// "), + Comment("/// Dummy parameter, only used to disambiguate the method signature."), + Comment($"/// A message registration stub for objects.")), SyntaxKind.OpenBracketToken, TriviaList())), AttributeList(SingletonSeparatedList( Attribute(IdentifierName("global::System.Obsolete")).AddArgumentListArguments( AttributeArgument(LiteralExpression( @@ -199,6 +218,12 @@ public static CompilationUnitSyntax GetSyntax(RecipientInfo recipientInfo) // Note: the generic overload has a different name to simplify the lookup with reflection. // This code will produce a syntax tree as follows: // + // /// + // /// Creates a message registration stub for objects, with an input token. + // /// + // /// The type of tokens that will be used to register messages. + // /// Dummy parameter, only used to disambiguate the method signature. + // /// A message registration stub for objects. // [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] // [global::System.Obsolete("This method is not intended to be called directly by user code")] // public static global::System.Action CreateAllMessagesRegistratorWithToken( _) @@ -221,7 +246,14 @@ public static CompilationUnitSyntax GetSyntax(RecipientInfo recipientInfo) Identifier("CreateAllMessagesRegistratorWithToken")).AddAttributeLists( AttributeList(SingletonSeparatedList( Attribute(IdentifierName("global::System.ComponentModel.EditorBrowsable")).AddArgumentListArguments( - AttributeArgument(ParseExpression("global::System.ComponentModel.EditorBrowsableState.Never"))))), + AttributeArgument(ParseExpression("global::System.ComponentModel.EditorBrowsableState.Never"))))) + .WithOpenBracketToken(Token(TriviaList( + Comment("/// "), + Comment($"/// Creates a message registration stub for objects."), + Comment("/// "), + Comment("/// The type of tokens that will be used to register messages."), + Comment("/// Dummy parameter, only used to disambiguate the method signature."), + Comment($"/// A message registration stub for objects.")), SyntaxKind.OpenBracketToken, TriviaList())), AttributeList(SingletonSeparatedList( Attribute(IdentifierName("global::System.Obsolete")).AddArgumentListArguments( AttributeArgument(LiteralExpression( @@ -261,6 +293,7 @@ public static CompilationUnitSyntax GetSyntax(RecipientInfo recipientInfo) // #pragma warning disable // namespace CommunityToolkit.Mvvm.Messaging.__Internals // { + // /// // partial class __IMessengerExtensions // { // @@ -271,7 +304,8 @@ public static CompilationUnitSyntax GetSyntax(RecipientInfo recipientInfo) NamespaceDeclaration(IdentifierName("CommunityToolkit.Mvvm.Messaging.__Internals")).WithLeadingTrivia(TriviaList( Comment("// "), Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true)))).AddMembers( - ClassDeclaration("__IMessengerExtensions").AddModifiers(Token(SyntaxKind.PartialKeyword)) + ClassDeclaration("__IMessengerExtensions").AddModifiers( + Token(TriviaList(Comment("/// ")), SyntaxKind.PartialKeyword, TriviaList())) .AddMembers(defaultChannelMethodDeclaration, customChannelMethodDeclaration))) .NormalizeWhitespace(); }