Skip to content

Commit

Permalink
Release 2.0 (#11)
Browse files Browse the repository at this point in the history
* Doki Extensions concept

* consistent member xml documentation

* TryGetParent Doki.Extensions

* support multiple summaries for member documentation

* generate docs
  • Loading branch information
DavidVollmers authored Jun 22, 2024
1 parent 5010f7b commit e44ef2e
Show file tree
Hide file tree
Showing 15 changed files with 364 additions and 129 deletions.
6 changes: 6 additions & 0 deletions Doki.sln
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Doki.TestAssembly", "tests\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Doki.Tests.Common", "tests\Doki.Tests.Common\Doki.Tests.Common.csproj", "{0FA0FF7A-6EDA-4CB1-8D81-2DFB1A4077CC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Doki.Extensions", "src\Doki.Extensions\Doki.Extensions.csproj", "{9961F717-DBD7-4987-9E68-2B85BB5830B4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Doki.CommandLine.Tests", "tests\Doki.CommandLine.Tests\Doki.CommandLine.Tests.csproj", "{67B12AF1-2696-411F-ADFD-B5C32A43BA71}"
EndProject
Global
Expand Down Expand Up @@ -113,6 +115,10 @@ Global
{0FA0FF7A-6EDA-4CB1-8D81-2DFB1A4077CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0FA0FF7A-6EDA-4CB1-8D81-2DFB1A4077CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0FA0FF7A-6EDA-4CB1-8D81-2DFB1A4077CC}.Release|Any CPU.Build.0 = Release|Any CPU
{9961F717-DBD7-4987-9E68-2B85BB5830B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9961F717-DBD7-4987-9E68-2B85BB5830B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9961F717-DBD7-4987-9E68-2B85BB5830B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9961F717-DBD7-4987-9E68-2B85BB5830B4}.Release|Any CPU.Build.0 = Release|Any CPU
{67B12AF1-2696-411F-ADFD-B5C32A43BA71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{67B12AF1-2696-411F-ADFD-B5C32A43BA71}.Debug|Any CPU.Build.0 = Debug|Any CPU
{67B12AF1-2696-411F-ADFD-B5C32A43BA71}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
4 changes: 3 additions & 1 deletion docs/api/Doki.Abstractions/Doki/Doki.MemberDocumentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ Implements: [System.IEquatable<Doki.MemberDocumentation>](https://learn.mi
|Name| Gets the name of the member.|
|Namespace| Gets the namespace of the member.|
|Assembly| Gets the assembly of the member.|
|Summary| Gets the summary of the member.|
|Summaries| Gets the summary of the member.|
|Examples| Get the examples of the member.|
|Remarks| Gets the remarks of the member.|
|IsDocumented| Gets a value indicating whether the type is documented.|
|ContentType||

Expand Down
2 changes: 0 additions & 2 deletions docs/api/Doki.Abstractions/Doki/Doki.TypeDocumentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ Implements: [System.IEquatable<Doki.TypeDocumentation>](https://learn.micr
|---|---|
|EqualityContract||
|Definition| Gets the definition of the type.|
|Examples| Get the examples of the type.|
|Remarks| Gets the remarks of the type.|
|Interfaces| Gets the interfaces implemented by the type.|
|DerivedTypes| Gets the derived types of the type.|
|Constructors| Gets the constructors of the type.|
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[Packages](../../README.md) / [Doki.Extensions](../README.md) / [Doki.Extensions](README.md) /

# DocumentationObjectExtensions Class

## Definition

Namespace: [Doki.Extensions](README.md)

Assembly: [Doki.Extensions.dll](../README.md)

Package: [Doki.Extensions](https://www.nuget.org/packages/Doki.Extensions)

---

```csharp
public static class DocumentationObjectExtensions
```

Inheritance: [System.Object](https://learn.microsoft.com/en-us/dotnet/api/System.Object) → DocumentationObjectExtensions

## Methods

| |Summary|
|---|---|
|TryGetParent(Doki.DocumentationRoot, Doki.DocumentationObject)||


7 changes: 7 additions & 0 deletions docs/api/Doki.Extensions/Doki.Extensions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Doki.Extensions Namespace

## Types

- [DocumentationObjectExtensions](Doki.Extensions.DocumentationObjectExtensions.md)


9 changes: 9 additions & 0 deletions docs/api/Doki.Extensions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Doki.Extensions

Provides extensions for Doki documentation generation

## Namespaces

- [Doki.Extensions](Doki.Extensions/README.md)


4 changes: 4 additions & 0 deletions docs/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

Provides abstractions for Doki documentation generation

- [Doki.Extensions](Doki.Extensions/README.md)

Provides extensions for Doki documentation generation

- [Doki.Output.Abstractions](Doki.Output.Abstractions/README.md)

Provides abstractions for Doki output generation
Expand Down
33 changes: 31 additions & 2 deletions src/Doki.Abstractions/MemberDocumentation.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Doki;
// ReSharper disable InconsistentNaming
namespace Doki;

/// <summary>
/// Represents the documentation for a member.
Expand All @@ -20,10 +21,38 @@ public record MemberDocumentation : DocumentationObject
/// </summary>
public string? Assembly { get; init; }

internal XmlDocumentation[] InternalSummaries = [];

/// <summary>
/// Gets the summary of the member.
/// </summary>
public XmlDocumentation? Summary { get; set; }
public XmlDocumentation[] Summaries
{
get => InternalSummaries;
init => InternalSummaries = value;
}

internal XmlDocumentation[] InternalExamples = [];

/// <summary>
/// Get the examples of the member.
/// </summary>
public XmlDocumentation[] Examples
{
get => InternalExamples;
init => InternalExamples = value;
}

internal XmlDocumentation[] InternalRemarks = [];

/// <summary>
/// Gets the remarks of the member.
/// </summary>
public XmlDocumentation[] Remarks
{
get => InternalRemarks;
init => InternalRemarks = value;
}

/// <summary>
/// Gets a value indicating whether the type is documented.
Expand Down
22 changes: 0 additions & 22 deletions src/Doki.Abstractions/TypeDocumentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,6 @@ public sealed record TypeDocumentation : TypeDocumentationReference
/// </summary>
public string Definition { get; init; } = null!;

internal XmlDocumentation[] InternalExamples = [];

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

internal XmlDocumentation[] InternalRemarks = [];

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

internal TypeDocumentationReference[] InternalInterfaces = [];

/// <summary>
Expand Down
118 changes: 118 additions & 0 deletions src/Doki.Extensions/DocumentationObjectExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
namespace Doki.Extensions;

public static class DocumentationObjectExtensions
{
public static DocumentationObject? TryGetParent(this DocumentationRoot root, DocumentationObject child)
{
ArgumentNullException.ThrowIfNull(root);
ArgumentNullException.ThrowIfNull(child);

return child.Parent ?? SearchParent(root, child);
}

private static DocumentationObject? SearchParent(DocumentationObject from, DocumentationObject to)
{
if (from == to) return from;

switch (from)
{
case DocumentationRoot root: return SearchParentIn(root.Assemblies, to);
case AssemblyDocumentation assemblyDocumentation:
return SearchParentIn(assemblyDocumentation.Namespaces, to);
case NamespaceDocumentation namespaceDocumentation: return SearchParentIn(namespaceDocumentation.Types, to);
case TypeDocumentation typeDocumentation:
{
var constructor = SearchParentIn(typeDocumentation.Constructors, to);
if (constructor != null) return constructor;

var method = SearchParentIn(typeDocumentation.Methods, to);
if (method != null) return method;

var property = SearchParentIn(typeDocumentation.Properties, to);
if (property != null) return property;

var field = SearchParentIn(typeDocumentation.Fields, to);
if (field != null) return field;

var interfaceDocumentation = SearchParentIn(typeDocumentation.Interfaces, to);
if (interfaceDocumentation != null) return interfaceDocumentation;

var derivedType = SearchParentIn(typeDocumentation.DerivedTypes, to);
if (derivedType != null) return derivedType;

var result = SearchParentInTypeDocumentationReference(typeDocumentation, to);
if (result != null) return result;

break;
}
case GenericTypeArgumentDocumentation genericTypeArgumentDocumentation:
{
if (genericTypeArgumentDocumentation.Description != null)
{
var description = SearchParent(genericTypeArgumentDocumentation.Description, to);
if (description != null) return description;
}

var result = SearchParentInTypeDocumentationReference(genericTypeArgumentDocumentation, to);
if (result != null) return result;

break;
}
case TypeDocumentationReference typeDocumentationReference:
{
var result = SearchParentInTypeDocumentationReference(typeDocumentationReference, to);
if (result != null) return result;

break;
}
case MemberDocumentation memberDocumentation:
{
var result = SearchParentInMemberDocumentation(memberDocumentation, to);
if (result != null) return result;

break;
}
case XmlDocumentation xmlDocumentation:
{
var result = SearchParentIn(xmlDocumentation.Contents, to);
if (result != null) return result;

break;
}
}

return null;
}

private static DocumentationObject? SearchParentInTypeDocumentationReference(
TypeDocumentationReference typeDocumentationReference, DocumentationObject to)
{
if (typeDocumentationReference.BaseType != null)
{
var baseType = SearchParent(typeDocumentationReference.BaseType, to);
if (baseType != null) return baseType;
}

var genericArgument = SearchParentIn(typeDocumentationReference.GenericArguments, to);
return genericArgument ?? SearchParentInMemberDocumentation(typeDocumentationReference, to);
}

private static DocumentationObject? SearchParentInMemberDocumentation(MemberDocumentation memberDocumentation,
DocumentationObject to)
{
var summary = SearchParentIn(memberDocumentation.Summaries, to);
if (summary != null) return summary;

var remarks = SearchParentIn(memberDocumentation.Remarks, to);
if (remarks != null) return remarks;

var example = SearchParentIn(memberDocumentation.Examples, to);
return example;
}

private static DocumentationObject? SearchParentIn(IEnumerable<DocumentationObject> children,
DocumentationObject to)
{
return children.Select(child => SearchParent(child, to)).OfType<DocumentationObject>().FirstOrDefault();
}
}
31 changes: 31 additions & 0 deletions src/Doki.Extensions/Doki.Extensions.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PackageId>Doki.Extensions</PackageId>
<Authors>david@vollmers.org</Authors>
<Copyright>David Vollmers</Copyright>
<Description>Provides extensions for Doki documentation generation</Description>
<PackageProjectUrl>https://github.com/DavidVollmers/doki</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageIcon>logo-64x64.png</PackageIcon>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/DavidVollmers/doki.git</RepositoryUrl>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageOutputPath>..\..\nuget</PackageOutputPath>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<None Include="..\..\README.md" Pack="true" PackagePath="\"/>
<None Include="..\..\LICENSE.txt" Pack="true" PackagePath="\"/>
<None Include="..\..\assets\logo-64x64.png" Pack="true" PackagePath="\"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Doki.Abstractions\Doki.Abstractions.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit e44ef2e

Please sign in to comment.