Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement doc comments for enum value #115

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NTypewriter.CodeModel.Roslyn/EnumValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal sealed class EnumValue : IEnumValue
public object Value => symbol.ConstantValue;
public string Name => symbol.Name;
public IEnumerable<IAttribute> Attributes => AttributeCollection.Create(symbol);

public IDocumentationCommentXml DocComment => DocumentationCommentXml.Create(symbol);

private EnumValue(IFieldSymbol symbol)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
One
Two
Three
This is the number four. (4)Four
This is the number five. (5)Five
25 changes: 25 additions & 0 deletions NTypewriter.CodeModel.Tests/EnumValue/DocComments/inputCode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;

namespace NTypewriter.Tests.CodeModel
{
enum EnumWithDocComments
{
One = 1,
Two = 2,
Three = 3,
/// <summary>
/// This is the number four. (4)
/// </summary>
Four = 4,
/// <summary>
/// This is the number five. (5)
/// </summary>
Five = 5,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{- capture captured
for enum in data.Enums | Symbols.WhereNamespaceStartsWith "NTypewriter.Tests.CodeModel"
for enumValue in enum.Values }}
{{- if enumValue.DocComment && enumValue.DocComment.Summary }}
{{- enumValue.DocComment.Summary }}
{{- end }}
{{- enumValue.Name }}
{{ end
end
end
Save captured "result" }}
6 changes: 6 additions & 0 deletions NTypewriter.CodeModel.Tests/EnumValue/EnumRenderingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@ public async Task Attributes()
{
await RunTestForProperty();
}

[TestMethod]
public async Task DocComments()
{
await RunTestForProperty();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<Compile Remove="DocumentationCommentXml\Returns\inputCode.cs" />
<Compile Remove="DocumentationCommentXml\Summary\inputCode.cs" />
<Compile Remove="EnumValue\Attributes\inputCode.cs" />
<Compile Remove="EnumValue\DocComments\inputCode.cs" />
<Compile Remove="Enum\UnderlyingType\inputCode.cs" />
<Compile Remove="Enum\Values\inputCode.cs" />
<Compile Remove="Event\Type\inputCode.cs" />
Expand Down Expand Up @@ -117,6 +118,8 @@
<None Remove="DocumentationCommentXml\Summary\inputTemplate.tsnt" />
<None Remove="EnumValue\Attributes\expectedResult.txt" />
<None Remove="EnumValue\Attributes\inputTemplate.tsnt" />
<None Remove="EnumValue\DocComments\expectedResult.txt" />
<None Remove="EnumValue\DocComments\inputTemplate.tsnt" />
<None Remove="Enum\UnderlyingType\expectedResult.txt" />
<None Remove="Enum\UnderlyingType\inputTemplate.tsnt" />
<None Remove="Enum\Values\expectedResult.txt" />
Expand Down Expand Up @@ -283,6 +286,9 @@
<EmbeddedResource Include="EnumValue\Attributes\expectedResult.txt" />
<EmbeddedResource Include="EnumValue\Attributes\inputCode.cs" />
<EmbeddedResource Include="EnumValue\Attributes\inputTemplate.tsnt" />
<EmbeddedResource Include="EnumValue\DocComments\expectedResult.txt" />
<EmbeddedResource Include="EnumValue\DocComments\inputCode.cs" />
<EmbeddedResource Include="EnumValue\DocComments\inputTemplate.tsnt" />
<EmbeddedResource Include="Enum\UnderlyingType\expectedResult.txt" />
<EmbeddedResource Include="Enum\UnderlyingType\inputCode.cs" />
<EmbeddedResource Include="Enum\UnderlyingType\inputTemplate.tsnt" />
Expand Down
5 changes: 5 additions & 0 deletions NTypewriter.CodeModel/IEnumValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,10 @@ public interface IEnumValue
/// All attributes declared on the enum value.
/// </summary>
IEnumerable<IAttribute> Attributes { get; }

/// <summary>
/// The XML documentation for the comment associated with the symbol.
/// </summary>
IDocumentationCommentXml DocComment { get; }
}
}
Loading