From 2b436ce03bcd94108a14822f887256c992037620 Mon Sep 17 00:00:00 2001 From: Patrick Meinecke Date: Sat, 16 Sep 2023 15:05:38 -0400 Subject: [PATCH] Use `Yayaml` module for generating signature help (#51) --- ClassExplorer.build.ps1 | 14 ++----- tools/GenerateSignatureMarkdown.ps1 | 4 +- tools/Signatures.yaml | 60 ++++++++++++++--------------- 3 files changed, 35 insertions(+), 43 deletions(-) diff --git a/ClassExplorer.build.ps1 b/ClassExplorer.build.ps1 index 9671cdb..6f2eb49 100644 --- a/ClassExplorer.build.ps1 +++ b/ClassExplorer.build.ps1 @@ -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 @@ -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 { diff --git a/tools/GenerateSignatureMarkdown.ps1 b/tools/GenerateSignatureMarkdown.ps1 index 426710c..86189d9 100644 --- a/tools/GenerateSignatureMarkdown.ps1 +++ b/tools/GenerateSignatureMarkdown.ps1 @@ -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()) @@ -327,7 +327,7 @@ end { $null = $w.AppendLine() - $keywords = $yaml['keywords'].ToArray() + $keywords = $yaml['keywords'] $null = $w.ToC([string[]]$keywords.ForEach{ $PSItem['header'] }) diff --git a/tools/Signatures.yaml b/tools/Signatures.yaml index a843b37..4977f5c 100644 --- a/tools/Signatures.yaml +++ b/tools/Signatures.yaml @@ -373,42 +373,42 @@ keywords: signatures: - match: true sig: " - public class MyClass where T : unmanaged\n - { }\n\n + public class MyClass 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 where T : new()\n - { }\n\n + public class MyClass 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 where T : IList\n - { }\n\n + public class MyClass 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 where T : struct\n - { }\n\n + public class MyClass 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 where T : class\n - { }\n\n + public class MyClass 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. @@ -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); @@ -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); @@ -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 values); @@ -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 { }