Skip to content

Commit

Permalink
refactor type documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidVollmers committed May 6, 2024
1 parent 2395809 commit f189c6b
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 31 deletions.
6 changes: 0 additions & 6 deletions src/Doki.Abstractions/DocumentationContentType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
/// </summary>
public enum DocumentationContentType
{
/// <summary>
/// An object in the documentation. This is the default content type.
/// </summary>
// ReSharper disable once UnusedMember.Global
Object,

/// <summary>
/// The root of the documentation, containing all assemblies/packages.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Doki.Abstractions/GenericTypeArgumentDocumentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public sealed record GenericTypeArgumentDocumentation : TypeDocumentationReferen
/// <summary>
/// Gets the description of the generic type argument.
/// </summary>
public DocumentationObject? Description { get; internal set; }
public XmlDocumentation? Description { get; internal set; }

/// <summary>
/// Gets a value indicating whether the generic type argument is a generic parameter.
Expand All @@ -17,6 +17,6 @@ public sealed record GenericTypeArgumentDocumentation : TypeDocumentationReferen

public GenericTypeArgumentDocumentation()
{
Content = DocumentationContentType.GenericTypeArgument;
ContentType = DocumentationContentType.GenericTypeArgument;
}
}
8 changes: 4 additions & 4 deletions src/Doki.Abstractions/MemberDocumentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public record MemberDocumentation : DocumentationObject
/// Gets the assembly of the member.
/// </summary>
public string? Assembly { get; internal init; }

/// <summary>
/// Gets the summary of the member.
/// </summary>
public DocumentationObject? Summary { get; internal set; }
public new DocumentationContentType Content { get; internal init; }
public XmlDocumentation? Summary { get; internal set; }

public new DocumentationContentType ContentType { get; internal init; }
}
20 changes: 10 additions & 10 deletions src/Doki.Abstractions/TypeDocumentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,47 @@ public sealed record TypeDocumentation : TypeDocumentationReference
/// <summary>
/// Gets the definition of the type.
/// </summary>
public string Definition { get; internal init; } = null!;
public string Definition { get; init; } = null!;

/// <summary>
/// Get the examples of the type.
/// </summary>
public DocumentationObject[] Examples { get; internal set; } = [];
public XmlDocumentation[] Examples { get; init; } = [];

/// <summary>
/// Gets the remarks of the type.
/// </summary>
public DocumentationObject[] Remarks { get; internal set; } = [];
public XmlDocumentation[] Remarks { get; init; } = [];

/// <summary>
/// Gets the interfaces implemented by the type.
/// </summary>
public TypeDocumentationReference[] Interfaces { get; internal set; } = [];
public TypeDocumentationReference[] Interfaces { get; init; } = [];

/// <summary>
/// Gets the derived types of the type.
/// </summary>
public TypeDocumentationReference[] DerivedTypes { get; internal set; } = [];
public TypeDocumentationReference[] DerivedTypes { get; init; } = [];

/// <summary>
/// Gets the constructors of the type.
/// </summary>
public MemberDocumentation[] Constructors { get; internal set; } = [];
public MemberDocumentation[] Constructors { get; init; } = [];

/// <summary>
/// Gets the fields of the type.
/// </summary>
public MemberDocumentation[] Fields { get; internal set; } = [];
public MemberDocumentation[] Fields { get; init; } = [];

/// <summary>
/// Gets the properties of the type.
/// </summary>
public MemberDocumentation[] Properties { get; internal set; } = [];
public MemberDocumentation[] Properties { get; init; } = [];

/// <summary>
/// Gets the methods of the type.
/// </summary>
public MemberDocumentation[] Methods { get; internal set; } = [];
public MemberDocumentation[] Methods { get; init; } = [];

public new DocumentationContentType Content { get; internal init; }
public new DocumentationContentType ContentType { get; init; }
}
2 changes: 1 addition & 1 deletion src/Doki.Abstractions/TypeDocumentationReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public record TypeDocumentationReference : MemberDocumentation
/// </summary>
public TypeDocumentationReference()
{
Content = DocumentationContentType.TypeReference;
ContentType = DocumentationContentType.TypeReference;
}
}
30 changes: 29 additions & 1 deletion src/Doki.Output.ClassLibrary/ClassLibraryOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,40 @@ private static void BuildNamespaceDocumentation(NamespaceDocumentation namespace

foreach (var typeDocumentation in namespaceDocumentation.Types)
{
//TODO Add type documentation
BuildTypeDocumentation(typeDocumentation, content, indent + 1);
}

content.AppendLine($$"""
{{i}} ]
{{i}}},
""");
}

private static void BuildTypeDocumentation(TypeDocumentation typeDocumentation, StringBuilder content, int indent)
{
var i = new string(' ', indent * 4);

content.AppendLine($$"""
{{i}}new TypeDocumentation
{{i}}{
{{i}} Name = "{{typeDocumentation.Name}}",
{{i}} ContentType = DocumentationContentType.{{Enum.GetName(typeDocumentation.ContentType)}},
{{i}} Definition = "{{typeDocumentation.Definition}}",
{{i}} IsGeneric = {{typeDocumentation.IsGeneric.ToString().ToLowerInvariant()}},
{{i}} FullName = "{{typeDocumentation.FullName}}",
{{i}} IsDocumented = {{typeDocumentation.IsDocumented.ToString().ToLowerInvariant()}},
{{i}} IsMicrosoft = {{typeDocumentation.IsMicrosoft.ToString().ToLowerInvariant()}},
{{i}} Namespace = "{{typeDocumentation.Namespace}}",
{{i}} Assembly = "{{typeDocumentation.Assembly}}",
""");

// foreach (var memberDocumentation in typeDocumentation.Members)
// {
// BuildMemberDocumentation(memberDocumentation, content, indent + 1);
// }

content.AppendLine($$"""
{{i}}},
""");
}
}
2 changes: 1 addition & 1 deletion src/Doki.Output.Markdown/MarkdownOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public async Task WriteAsync(TypeDocumentation typeDocumentation, CancellationTo

var markdown = new MarkdownBuilder(currentPath);
markdown.Add(markdown.BuildBreadcrumbs(typeDocumentation))
.Add(new Heading(typeDocumentation.Name, 1).Append($" {Enum.GetName(typeDocumentation.Content)}"))
.Add(new Heading(typeDocumentation.Name, 1).Append($" {Enum.GetName(typeDocumentation.ContentType)}"))
.Add(new Heading(nameof(TypeDocumentation.Definition), 2));

var namespaceDocumentation =
Expand Down
10 changes: 5 additions & 5 deletions src/Doki/DocumentationGenerator.Content.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private IEnumerable<MemberDocumentation> BuildFieldDocumentation(Type type, Docu
{
Id = fieldId,
Name = field.Name,
Content = DocumentationContentType.Field,
ContentType = DocumentationContentType.Field,
Namespace = field.DeclaringType.Namespace,
Assembly = fieldAssembly.Name,
Parent = parent,
Expand Down Expand Up @@ -165,7 +165,7 @@ private IEnumerable<MemberDocumentation> BuildConstructorDocumentation(Type type
{
Id = constructorId,
Name = constructor.GetSanitizedName(),
Content = DocumentationContentType.Constructor,
ContentType = DocumentationContentType.Constructor,
Namespace = constructor.DeclaringType.Namespace,
Assembly = constructorAssembly.Name,
Parent = parent,
Expand Down Expand Up @@ -206,7 +206,7 @@ private IEnumerable<MemberDocumentation> BuildPropertyDocumentation(Type type, D
{
Id = propertyId,
Name = property.Name,
Content = DocumentationContentType.Property,
ContentType = DocumentationContentType.Property,
Namespace = property.DeclaringType.Namespace,
Assembly = propertyAssembly.Name,
Parent = parent,
Expand Down Expand Up @@ -249,7 +249,7 @@ private IEnumerable<MemberDocumentation> BuildMethodDocumentation(Type type, Doc
{
Id = methodId,
Name = method.GetSanitizedName(),
Content = DocumentationContentType.Property,
ContentType = DocumentationContentType.Property,
Namespace = method.DeclaringType.Namespace,
Assembly = methodAssembly.Name,
Parent = parent,
Expand Down Expand Up @@ -365,7 +365,7 @@ private TypeDocumentationReference BuildTypeDocumentationReference(Type type, Do
Id = typeId,
Name = type.GetSanitizedName(),
FullName = type.GetSanitizedName(true),
Content = DocumentationContentType.TypeReference,
ContentType = DocumentationContentType.TypeReference,
Namespace = type.Namespace,
Assembly = assembly.Name,
IsGeneric = type.IsGenericType,
Expand Down
2 changes: 1 addition & 1 deletion src/Doki/DocumentationGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ private async Task<TypeDocumentation> GenerateTypeDocumentationAsync(GeneratorCo
var typeDocumentation = new TypeDocumentation
{
Id = typeId,
Content = context.Current.IsClass
ContentType = context.Current.IsClass
? DocumentationContentType.Class
: context.Current.IsEnum
? DocumentationContentType.Enum
Expand Down

0 comments on commit f189c6b

Please sign in to comment.