Skip to content

Commit

Permalink
feat: UseClrTypeNames: new option to indicate that the output must us…
Browse files Browse the repository at this point in the history
…e the CLR type names instead of the language specific aliases (#10072)

* UseClrTypeNames: new option to indicate that the output must use the CLR type names instead of the language specific aliases.

* Updated the schema with the new parameter.

* Updated the documentation with the new parameter.
  • Loading branch information
Patrick8639 authored Jul 9, 2024
1 parent d3c3327 commit 1bb332a
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 9 deletions.
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 @@ -692,6 +692,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

0 comments on commit 1bb332a

Please sign in to comment.