Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
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
8 changes: 1 addition & 7 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dotnet_style_qualification_for_field = true:suggestion
dotnet_style_qualification_for_method = true:suggestion
dotnet_style_qualification_for_property = true:suggestion

dotnet_diagnostic.IDE0001.severity = warning # Name can be simplified
dotnet_diagnostic.IDE0002.severity = warning # Name can be simplified

# StyleCop: Special Rules
Expand All @@ -21,8 +22,6 @@ dotnet_diagnostic.SA0001.severity = none # XML comment analysis disabled
# StyleCop: Readability Rules
dotnet_diagnostic.SA1118.severity = none # Parameter should not span multiple lines
dotnet_diagnostic.SA1122.severity = none # Use string.Empty for empty strings
dotnet_diagnostic.SA1127.severity = none # Generic type constraints should be on their own line
dotnet_diagnostic.SA1128.severity = none # Put constructor initializers on their own line
dotnet_diagnostic.SA1135.severity = none # Using directives should be qualified

# StyleCop: Ordering Rules
Expand All @@ -45,13 +44,8 @@ dotnet_diagnostic.SA1513.severity = none # Closing brace should be follow
dotnet_diagnostic.SA1515.severity = none # Single-line comment should be preceded by blank line

# StyleCop: Documentation Rules
dotnet_diagnostic.SA1611.severity = none # Element parameters should be documented
dotnet_diagnostic.SA1612.severity = none # Element parameter documentation should match element parameters
dotnet_diagnostic.SA1615.severity = none # Element return value should be documented
dotnet_diagnostic.SA1618.severity = none # Generic type parameters should be documented
dotnet_diagnostic.SA1623.severity = none # Property summary documentation should match accessors
dotnet_diagnostic.SA1629.severity = none # Documentation text should end with a period
dotnet_diagnostic.SA1633.severity = none # File should have header
dotnet_diagnostic.SA1642.severity = none # Constructor summary documentation should begin with standard text
dotnet_diagnostic.SA1649.severity = none # File name should match first type name

Expand Down
5 changes: 5 additions & 0 deletions src/Common/AssemblyCommon.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
<WarningsAsErrors>3390</WarningsAsErrors>
</PropertyGroup>

<ItemGroup Condition="'$(MSBuildProjectExtension)' == '.csproj'">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.321" PrivateAssets="All" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)\stylecop.json" Link="stylecop.json" />
</ItemGroup>

<!--
When DefineConstants receives a list with the semicolon escaped (%3B),
like: SIGNED%3BTELEMETRY
Expand Down
2 changes: 1 addition & 1 deletion src/Common/DelaySign.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#if SIGNED
Expand Down
2 changes: 1 addition & 1 deletion src/Common/SigningConstants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

internal static class SigningConstants
Expand Down
6 changes: 5 additions & 1 deletion src/Common/stylecop.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
"usingDirectivesPlacement": "preserve"
},
"documentationRules": {
"documentInternalElements": false
"copyrightText": "Copyright (c) Microsoft Corporation.\nLicensed under the MIT License.",
"documentInterfaces": false,
"documentExposedElements": false,
"documentInternalElements": false,
"xmlHeader": false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ public bool Transformation(QsCompilation compilation, out QsCompilation transfor
: null,
this.AssemblyConstants.TryGetValue("DocsPackageId", out var packageName)
? packageName
: null
);
: null);

docProcessor.OnDiagnostic += diagnostic =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

<ItemGroup>
<ProjectReference Include="..\..\QsCompiler\Compiler\Compiler.csproj" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.164" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand All @@ -33,8 +32,4 @@
<PackagePath>build\Microsoft.Quantum.DocumentationGenerator.props</PackagePath>
</Content>
</ItemGroup>

<ItemGroup>
<AdditionalFiles Include="..\..\Common\stylecop.json" Link="stylecop.json" />
</ItemGroup>
</Project>
70 changes: 25 additions & 45 deletions src/Documentation/DocumentationGenerator/DocumentationWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Microsoft.Quantum.Documentation
{

/// <summary>
/// Writes API documentation files as Markdown to a given output
/// directory, using parsed API documentation comments.
Expand Down Expand Up @@ -80,9 +79,7 @@ await this.TryWithExceptionsAsDiagnostics(
$"writing output to {filename}",
async () => await File.WriteAllTextAsync(
Path.Join(this.OutputPath, filename.ToLowerInvariant()),
contents
)
);
contents));
}

/// <summary>
Expand All @@ -109,18 +106,19 @@ public DocumentationWriter(string outputPath, string? packageName)
{
this.OnDiagnostic?.Invoke(new IRewriteStep.Diagnostic
{
Severity = CodeAnalysis.DiagnosticSeverity.Info,
Severity = DiagnosticSeverity.Info,
Message = $"Writing documentation output to: {outputPath}...",
Range = null,
Source = null,
Stage = IRewriteStep.Stage.Transformation,
});
if (!Directory.Exists(outputPath))
{
this.TryWithExceptionsAsDiagnostics(
"creating directory",
async () => Directory.CreateDirectory(outputPath)
).Wait();
this
.TryWithExceptionsAsDiagnostics(
"creating directory",
() => Task.FromResult(Directory.CreateDirectory(outputPath)))
.Wait();
}
}

Expand Down Expand Up @@ -170,15 +168,11 @@ public async Task WriteOutput(QsNamespace ns, DocComment docComment)
.MaybeWithSection(
"See Also",
string.Join("\n", docComment.SeeAlso.Select(
seeAlso => AsSeeAlsoLink(seeAlso)
))
)
seeAlso => AsSeeAlsoLink(seeAlso))))
.WithYamlHeader(header);

// Open a file to write the new doc to.
await this.WriteAllTextAsync(
$"{name}.md", document
);
await this.WriteAllTextAsync($"{name}.md", document);
}

/// <summary>
Expand Down Expand Up @@ -237,26 +231,21 @@ public async Task WriteOutput(QsCustomType type, DocComment docComment)
? comment
: string.Empty;
return $"### {itemName} : {resolvedType.ToMarkdownLink()}\n\n{documentation}";
}
))
)
})))
.MaybeWithSection("Description", docComment.Description)
.WithSectionForEach("Example", docComment.Examples)
.MaybeWithSection("Remarks", docComment.Remarks)
.MaybeWithSection("References", docComment.References)
.MaybeWithSection(
"See Also",
string.Join("\n", docComment.SeeAlso.Select(
seeAlso => AsSeeAlsoLink(seeAlso, type.FullName.Namespace)
))
)
seeAlso => AsSeeAlsoLink(seeAlso, type.FullName.Namespace))))
.WithYamlHeader(header);

// Open a file to write the new doc to.
await this.WriteAllTextAsync(
$"{type.FullName.Namespace}.{type.FullName.Name}.md",
document
);
document);
}

/// <summary>
Expand Down Expand Up @@ -296,6 +285,13 @@ public async Task WriteOutput(QsCallable callable, DocComment docComment)
["qsharp.name"] = callable.FullName.Name,
["qsharp.summary"] = docComment.Summary,
};
var keyword = callable.Kind.Tag switch
{
QsCallableKind.Tags.Function => "function ",
QsCallableKind.Tags.Operation => "operation ",
QsCallableKind.Tags.TypeConstructor => "newtype ",
_ => ""
};
var document = $@"
# {title}

Expand All @@ -305,15 +301,7 @@ public async Task WriteOutput(QsCallable callable, DocComment docComment)
{docComment.Summary}

```{this.LanguageMode}
{
callable.Kind.Tag switch
{
QsCallableKind.Tags.Function => "function ",
QsCallableKind.Tags.Operation => "operation ",
QsCallableKind.Tags.TypeConstructor => "newtype ",
_ => ""
}
}{callable.ToSyntax()}
{keyword}{callable.ToSyntax()}
```
"
.MaybeWithSection("Description", docComment.Description)
Expand All @@ -327,9 +315,7 @@ public async Task WriteOutput(QsCallable callable, DocComment docComment)
? inputComment
: string.Empty;
return $"### {inputName} : {resolvedType.ToMarkdownLink()}\n\n{documentation}\n\n";
}
))
)
})))
.WithSection($"Output : {callable.Signature.ReturnType.ToMarkdownLink()}", docComment.Output)
.MaybeWithSection(
"Type Parameters",
Expand All @@ -339,27 +325,21 @@ typeParam is QsLocalSymbol.ValidName name
? $@"### '{name.Item}{"\n\n"}{(
docComment.TypeParameters.TryGetValue($"'{name.Item}", out var comment)
? comment
: string.Empty
)}"
: string.Empty
))
)
: string.Empty)}"
: string.Empty)))
.WithSectionForEach("Example", docComment.Examples)
.MaybeWithSection("Remarks", docComment.Remarks)
.MaybeWithSection("References", docComment.References)
.MaybeWithSection(
"See Also",
string.Join("\n", docComment.SeeAlso.Select(
seeAlso => AsSeeAlsoLink(seeAlso, callable.FullName.Namespace)
))
)
seeAlso => AsSeeAlsoLink(seeAlso, callable.FullName.Namespace))))
.WithYamlHeader(header);

// Open a file to write the new doc to.
await this.WriteAllTextAsync(
$"{callable.FullName.Namespace}.{callable.FullName.Name}.md",
document
);
document);
}
}
}
Loading