Skip to content

Commit

Permalink
Use Yayaml module for generating signature help (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
SeeminglyScience committed Sep 16, 2023
1 parent a5aa12a commit 2b436ce
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 43 deletions.
14 changes: 3 additions & 11 deletions ClassExplorer.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ task AssertRequiredModules {
& $AssertModule Pester 5.3.0 -Force:$Force.IsPresent
& $AssertModule InvokeBuild 5.8.4 -Force:$Force.IsPresent
& $AssertModule platyPS 0.14.2 -Force:$Force.IsPresent

# Cannot import powershell-yaml and platyPS in the same session due to
# assembly conflict.
& $AssertModule powershell-yaml 0.4.2 -Force:$Force.IsPresent -NoImport
& $AssertModule Yayaml 0.1.1 -Force:$Force.IsPresent
}

task AssertDevDependencies -Jobs AssertDotNet, AssertOpenCover, AssertRequiredModules
Expand All @@ -95,13 +92,8 @@ task BuildDocs -If { $Discovery.HasDocs } {
$null = New-Item $releaseDocs -ItemType Directory -Force -ErrorAction SilentlyContinue
$null = New-ExternalHelp -Path $sourceDocs -OutputPath $releaseDocs

# Cannot import powershell-yaml and platyPS in the same session due to
# assembly conflict.
$generateSignatureMarkdownPath = $GenerateSignatureMarkdown.Source
Start-Job {
& $using:generateSignatureMarkdownPath -AboutHelp $using:releaseDocs\about_Type_Signatures.help.txt
& $using:generateSignatureMarkdownPath $using:PSScriptRoot\docs\en-US\about_Type_Signatures.help.md
} | Receive-Job -Wait -AutoRemoveJob
& $GenerateSignatureMarkdown.Source -AboutHelp $releaseDocs\about_Type_Signatures.help.txt
& $GenerateSignatureMarkdown.Source $PSScriptRoot\docs\en-US\about_Type_Signatures.help.md
}

task BuildDll {
Expand Down
4 changes: 2 additions & 2 deletions tools/GenerateSignatureMarkdown.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ begin {
}
end {
$yaml = Get-Content -Raw $PSScriptRoot/Signatures.yaml -ErrorAction Stop |
ConvertFrom-Yaml
Yayaml\ConvertFrom-Yaml

if (-not $AboutHelp) {
$w = [MdSigWriter]::new([StringBuilder]::new())
Expand All @@ -327,7 +327,7 @@ end {

$null = $w.AppendLine()

$keywords = $yaml['keywords'].ToArray()
$keywords = $yaml['keywords']

$null = $w.ToC([string[]]$keywords.ForEach{ $PSItem['header'] })

Expand Down
60 changes: 30 additions & 30 deletions tools/Signatures.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -373,42 +373,42 @@ keywords:
signatures:
- match: true
sig: "
public class MyClass<T> where T : unmanaged\n
{ }\n\n
public class MyClass<T> where T : unmanaged\n
{ }\n\n
void Example(T value);"
void Example(T value);"
- syntax: Find-Member -ParameterType { [T[new]] }
signatures:
- match: true
sig: "
public class MyClass<T> where T : new()\n
{ }\n\n
public class MyClass<T> where T : new()\n
{ }\n\n
void Example(T value);"
void Example(T value);"
- syntax: Find-Member -ParameterType { [T[Collections.IList]] }
signatures:
- match: true
sig: "
public class MyClass<T> where T : IList\n
{ }\n\n
public class MyClass<T> where T : IList\n
{ }\n\n
void Example(T value);"
void Example(T value);"
- syntax: Find-Member -ParameterType { [T[struct]] }
signatures:
- match: true
sig: "
public class MyClass<T> where T : struct\n
{ }\n\n
public class MyClass<T> where T : struct\n
{ }\n\n
void Example(T value);"
void Example(T value);"
- syntax: Find-Member -ParameterType { [T[class]] }
signatures:
- match: true
sig: "
public class MyClass<T> where T : class\n
{ }\n\n
public class MyClass<T> where T : class\n
{ }\n\n
void Example(T value);"
void Example(T value);"

- header: "`primitive`"
description: Matches bool, byte, char, double, short, int, long, IntPtr, sbyte, float, ushort, uint, ulong, or UIntPtr.
Expand Down Expand Up @@ -494,7 +494,7 @@ keywords:
- match: true
sig: void Example(string value, object obj, string str);
- syntax: "# You can also use `i`\n
Find-Member -ParameterType { [allof[i0..1, string]] }"
Find-Member -ParameterType { [allof[i0..1, string]] }"
signatures:
- match: false
sig: void Example(IDisposable disposable);
Expand Down Expand Up @@ -567,8 +567,8 @@ keywords:
- match: false
sig: void Example(object[] args);
- syntax: "Find-Member -ParameterType {\n
\t[hasattr[Management.Automation.CmdletAttribute]]\n
}"
\t[hasattr[Management.Automation.CmdletAttribute]]\n
}"
signatures:
- match: true
sig: void Example(OutStringCommand command);
Expand All @@ -577,8 +577,8 @@ keywords:
description: Provides a way to specify a signature that takes arguments for a generic type definition.
examples:
- syntax: "Find-Member -ParameterType {\n
\t[generic[exact[Collections.Generic.IList`1], args[struct]]]\n
}"
\t[generic[exact[Collections.Generic.IList`1], args[struct]]]\n
}"
signatures:
- match: true
sig: void Example(IList<DateTime> values);
Expand All @@ -592,17 +592,17 @@ keywords:
examples:
- syntax:
- "$map = @{\n
\tnumber = {\n
\t\t[anyof[bigint, [allof[primitive, [not[anyof[bool, char]]]]]]]\n
\t}\n\n
\tanymemory = {\n
\t\t[anyof[Span[any], ReadOnlySpan[any], Memory[any], ReadOnlyMemory[any]]]\n
\t}\n\n
\tLocalRunspace = (Find-Type LocalRunspace -Force)\n
}\n"
\tnumber = {\n
\t\t[anyof[bigint, [allof[primitive, [not[anyof[bool, char]]]]]]]\n
\t}\n\n
\tanymemory = {\n
\t\t[anyof[Span[any], ReadOnlySpan[any], Memory[any], ReadOnlyMemory[any]]]\n
\t}\n\n
\tLocalRunspace = (Find-Type LocalRunspace -Force)\n
}\n"
- "Find-Type -Force -ResolutionMap $map -Signature {\n
\t[anyof[number, anymemory, LocalRunspace]]\n
}"
\t[anyof[number, anymemory, LocalRunspace]]\n
}"
signatures:
- match: true
sig: public struct Byte { }
Expand Down

0 comments on commit 2b436ce

Please sign in to comment.