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

feat: UseClrTypeNames: new option to indicate that the output must use the CLR type names instead of the language specific aliases #10072

Merged
merged 3 commits into from
Jul 9, 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
10 changes: 9 additions & 1 deletion docs/reference/docfx-cli-reference/docfx-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,19 @@ Run `docfx metadata --help` or `docfx -h` to get a list of all available options
- `SeparatePages`
- Place members in separate pages.

- **--useClrTypeNames**

Indicates whether the CLR type names or the language aliases must be used.

- not specified or `false`
- The language aliases are used: `int`.
- `true`
- The CLR type names are used: `Int32`.

## Examples

- Generate YAML files with default config.

```pwsh
docfx metadata
```

5 changes: 5 additions & 0 deletions schemas/docfx.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,11 @@
"type": "boolean",
"default": false,
"description": "When enabled, continues documentation generation in case of compilation errors."
},
"useClrTypeNames": {
"type": "boolean",
"default": false,
"description": "When enabled, use CLR type names instead of language aliases."
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Docfx.Dotnet/DotnetApiCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ private static ExtractMetadataConfig ConvertConfig(MetadataJsonItemConfig config
var expandedFiles = GlobUtility.ExpandFileMapping(EnvironmentContext.BaseDirectory, projects);
var expandedReferences = GlobUtility.ExpandFileMapping(EnvironmentContext.BaseDirectory, references);

ExtractMetadataConfig.UseClrTypeNames = configModel?.UseClrTypeNames ?? false;

return new ExtractMetadataConfig
{
ShouldSkipMarkup = configModel?.ShouldSkipMarkup ?? false,
Expand Down
3 changes: 3 additions & 0 deletions src/Docfx.Dotnet/ManagedReference/ExtractMetadataConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@ internal class ExtractMetadataConfig
public Dictionary<string, string> MSBuildProperties { get; init; }

public bool AllowCompilationErrors { get; init; }

public static bool UseClrTypeNames { get; set; }

}
7 changes: 7 additions & 0 deletions src/Docfx.Dotnet/MetadataJsonConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ internal class MetadataJsonItemConfig
[JsonProperty("allowCompilationErrors")]
[JsonPropertyName("allowCompilationErrors")]
public bool AllowCompilationErrors { get; set; }

/// <summary>
/// When enabled, the types uses the CLR type names instead of the C# aliases.
/// </summary>
[JsonProperty("useClrTypeNames")]
[JsonPropertyName("useClrTypeNames")]
public bool UseClrTypeNames { get; init; }
}

/// <summary>
Expand Down
15 changes: 11 additions & 4 deletions src/Docfx.Dotnet/SymbolFormatter.Syntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,24 @@ class SyntaxFormatter
SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier |
SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers |
SymbolDisplayMiscellaneousOptions.AllowDefaultLiteral |
SymbolDisplayMiscellaneousOptions.UseSpecialTypes |
SymbolDisplayMiscellaneousOptions.RemoveAttributeSuffix,
SymbolDisplayMiscellaneousOptions.RemoveAttributeSuffix |
(ExtractMetadataConfig.UseClrTypeNames
? SymbolDisplayMiscellaneousOptions.None
: SymbolDisplayMiscellaneousOptions.UseSpecialTypes),
localOptions: SymbolDisplayLocalOptions.IncludeType,
propertyStyle: SymbolDisplayPropertyStyle.ShowReadWriteDescriptor,
delegateStyle: SymbolDisplayDelegateStyle.NameAndSignature,
extensionMethodStyle: SymbolDisplayExtensionMethodStyle.StaticMethod,
typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypes);

private static readonly SymbolDisplayFormat s_syntaxTypeNameFormat = new(
genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters,
miscellaneousOptions: SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier | SymbolDisplayMiscellaneousOptions.UseSpecialTypes,
genericsOptions:
SymbolDisplayGenericsOptions.IncludeTypeParameters,
miscellaneousOptions:
SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier |
(ExtractMetadataConfig.UseClrTypeNames
? SymbolDisplayMiscellaneousOptions.None
: SymbolDisplayMiscellaneousOptions.UseSpecialTypes),
typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypes);

private static readonly SymbolDisplayFormat s_syntaxEnumConstantFormat = s_syntaxFormat
Expand Down
17 changes: 13 additions & 4 deletions src/Docfx.Dotnet/SymbolFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@ namespace Docfx.Dotnet;
internal static partial class SymbolFormatter
{
private static readonly SymbolDisplayFormat s_nameFormat = new(
memberOptions: SymbolDisplayMemberOptions.IncludeParameters | SymbolDisplayMemberOptions.IncludeExplicitInterface,
genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters,
parameterOptions: SymbolDisplayParameterOptions.IncludeType,
miscellaneousOptions: SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier | SymbolDisplayMiscellaneousOptions.AllowDefaultLiteral | SymbolDisplayMiscellaneousOptions.UseSpecialTypes,
memberOptions:
SymbolDisplayMemberOptions.IncludeParameters |
SymbolDisplayMemberOptions.IncludeExplicitInterface,
genericsOptions:
SymbolDisplayGenericsOptions.IncludeTypeParameters,
parameterOptions:
SymbolDisplayParameterOptions.IncludeType,
miscellaneousOptions:
SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier |
SymbolDisplayMiscellaneousOptions.AllowDefaultLiteral |
(ExtractMetadataConfig.UseClrTypeNames
? SymbolDisplayMiscellaneousOptions.None
: SymbolDisplayMiscellaneousOptions.UseSpecialTypes),
extensionMethodStyle: SymbolDisplayExtensionMethodStyle.StaticMethod);

private static readonly SymbolDisplayFormat s_nameWithTypeFormat = s_nameFormat
Expand Down