Skip to content

Commit 34256fa

Browse files
committed
Preserve XML documentation in generated commands
Added support to extract and include XML documentation comments from method symbols into the generated command properties. This helps retain developer documentation in the generated code for better maintainability and IntelliSense support.
1 parent 50c03c3 commit 34256fa

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/ReactiveUI.SourceGenerators.Roslyn/ReactiveCommand/Models/CommandInfo.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ internal record CommandInfo(
1919
CanExecuteTypeInfo? CanExecuteTypeInfo,
2020
string? OutputScheduler,
2121
EquatableArray<string> ForwardedPropertyAttributes,
22-
string AccessModifier)
22+
string AccessModifier,
23+
string? XmlComment)
2324
{
2425
private const string UnitTypeName = "global::System.Reactive.Unit";
2526

src/ReactiveUI.SourceGenerators.Roslyn/ReactiveCommand/ReactiveCommandGenerator.Execute.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,19 @@ public partial class ReactiveCommandGenerator
123123

124124
token.ThrowIfCancellationRequested();
125125

126+
var xmlTrivia = methodSymbol.GetDocumentationCommentXml(cancellationToken: token);
127+
128+
// Remove Member attributes from xmlTrivia on the first and last lines
129+
if (xmlTrivia?.Length > 0)
130+
{
131+
var s = xmlTrivia.Split('\n').ToList();
132+
s.RemoveAt(0);
133+
s.Remove(s.Last());
134+
s.Remove(s.Last());
135+
xmlTrivia = string.Concat(s.Select(c => " /// " + c.TrimStart() + "\n"));
136+
xmlTrivia = xmlTrivia.TrimEnd();
137+
}
138+
126139
return new(
127140
targetInfo,
128141
symbol.Name,
@@ -135,7 +148,8 @@ public partial class ReactiveCommandGenerator
135148
canExecuteTypeInfo,
136149
outputScheduler,
137150
forwardedPropertyAttributes,
138-
accessModifier);
151+
accessModifier,
152+
xmlTrivia);
139153
}
140154

141155
private static string GenerateSource(string containingTypeName, string containingNamespace, string containingClassVisibility, string containingType, CommandInfo[] commands)
@@ -217,6 +231,7 @@ private static string GetCommandSyntax(CommandInfo commandExtensionInfo)
217231
$$"""
218232
private {{RxCmd}}<{{inputType}}, {{outputType}}>? {{fieldName}};
219233
234+
{{commandExtensionInfo.XmlComment}}
220235
[global::System.CodeDom.Compiler.GeneratedCode("{{GeneratorName}}", "{{GeneratorVersion}}")]
221236
{{forwardedPropertyAttributesString}}
222237
{{commandExtensionInfo.AccessModifier}} {{RxCmd}}<{{inputType}}, {{outputType}}> {{commandName}} { get => {{initializer}} }

0 commit comments

Comments
 (0)