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

Use Whippet #282

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
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
62 changes: 27 additions & 35 deletions ConsumePlugin/ConsumePlugin.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,88 +6,80 @@
<OtherFlags>--reflectionfree $(OtherFlags)</OtherFlags>
</PropertyGroup>
<ItemGroup>
<MyriadSdkGenerator Include="$(MSBuildThisFileDirectory)..\WoofWare.Myriad.Plugins\bin\$(Configuration)\net6.0\WoofWare.Myriad.Plugins.dll"/>
</ItemGroup>

<ItemGroup>
<None Include="myriad.toml"/>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="RecordFile.fs"/>
<Compile Include="GeneratedRecord.fs">
<MyriadFile>RecordFile.fs</MyriadFile>
<WhippetFile>RecordFile.fs</WhippetFile>
</Compile>
<Compile Include="JsonRecord.fs"/>
<Compile Include="GeneratedJson.fs">
<MyriadFile>JsonRecord.fs</MyriadFile>
<WhippetFile>JsonRecord.fs</WhippetFile>
</Compile>
<Compile Include="PureGymDto.fs"/>
<Compile Include="GeneratedPureGymDto.fs">
<MyriadFile>PureGymDto.fs</MyriadFile>
<WhippetFile>PureGymDto.fs</WhippetFile>
</Compile>
<Compile Include="RestApiExample.fs"/>
<Compile Include="GeneratedRestClient.fs">
<MyriadFile>RestApiExample.fs</MyriadFile>
<WhippetFile>RestApiExample.fs</WhippetFile>
</Compile>
<Compile Include="MockExample.fs"/>
<Compile Include="GeneratedMock.fs">
<MyriadFile>MockExample.fs</MyriadFile>
<WhippetFile>MockExample.fs</WhippetFile>
</Compile>
<Compile Include="MockExampleNoAttributes.fs" />
<Compile Include="GeneratedMockNoAttributes.fs">
<MyriadFile>MockExampleNoAttributes.fs</MyriadFile>
<MyriadParams>
<IPublicTypeNoAttr>GenerateMock</IPublicTypeNoAttr>
<IPublicTypeInternalFalseNoAttr>GenerateMock(false)</IPublicTypeInternalFalseNoAttr>
<InternalTypeNoAttr>GenerateMock</InternalTypeNoAttr>
<PrivateTypeNoAttr>GenerateMock</PrivateTypeNoAttr>
<PrivateTypeInternalFalseNoAttr>GenerateMock(false)</PrivateTypeInternalFalseNoAttr>
<VeryPublicTypeNoAttr>GenerateMock</VeryPublicTypeNoAttr>
<CurriedNoAttr>GenerateMock</CurriedNoAttr>
<TypeWithInterfaceNoAttr>GenerateMock</TypeWithInterfaceNoAttr>
</MyriadParams>
<WhippetFile>MockExampleNoAttributes.fs</WhippetFile>
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the choice to flatten these params, because the contents of this XML node are presented through msbuild only as a string, not as an XML node!

<WhippetParamIPublicTypeNoAttr>GenerateMock</WhippetParamIPublicTypeNoAttr>
<WhippetParamIPublicTypeNoAttr>GenerateMock</WhippetParamIPublicTypeNoAttr>
<WhippetParamIPublicTypeInternalFalseNoAttr>GenerateMock(false)</WhippetParamIPublicTypeInternalFalseNoAttr>
<WhippetParamInternalTypeNoAttr>GenerateMock</WhippetParamInternalTypeNoAttr>
<WhippetParamPrivateTypeNoAttr>GenerateMock</WhippetParamPrivateTypeNoAttr>
<WhippetParamPrivateTypeInternalFalseNoAttr>GenerateMock(false)</WhippetParamPrivateTypeInternalFalseNoAttr>
<WhippetParamVeryPublicTypeNoAttr>GenerateMock</WhippetParamVeryPublicTypeNoAttr>
<WhippetParamCurriedNoAttr>GenerateMock</WhippetParamCurriedNoAttr>
<WhippetParamTypeWithInterfaceNoAttr>GenerateMock</WhippetParamTypeWithInterfaceNoAttr>
</Compile>
<Compile Include="Vault.fs" />
<Compile Include="GeneratedVault.fs">
<MyriadFile>Vault.fs</MyriadFile>
<WhippetFile>Vault.fs</WhippetFile>
</Compile>
<Compile Include="SerializationAndDeserialization.fs" />
<Compile Include="GeneratedSerde.fs">
<MyriadFile>SerializationAndDeserialization.fs</MyriadFile>
<WhippetFile>SerializationAndDeserialization.fs</WhippetFile>
</Compile>
<Compile Include="Catamorphism.fs" />
<Compile Include="GeneratedCatamorphism.fs">
<MyriadFile>Catamorphism.fs</MyriadFile>
<WhippetFile>Catamorphism.fs</WhippetFile>
</Compile>
<Compile Include="FSharpForFunAndProfitCata.fs" />
<Compile Include="GeneratedFileSystem.fs">
<MyriadFile>FSharpForFunAndProfitCata.fs</MyriadFile>
<WhippetFile>FSharpForFunAndProfitCata.fs</WhippetFile>
</Compile>
<Compile Include="List.fs" />
<Compile Include="ListCata.fs">
<MyriadFile>List.fs</MyriadFile>
<WhippetFile>List.fs</WhippetFile>
</Compile>
<Compile Include="Args.fs" />
<Compile Include="GeneratedArgs.fs">
<MyriadFile>Args.fs</MyriadFile>
<WhippetFile>Args.fs</WhippetFile>
</Compile>
<None Include="swagger-gitea.json" />
<Compile Include="GeneratedSwaggerGitea.fs">
<MyriadFile>swagger-gitea.json</MyriadFile>
<MyriadParams>
<GenerateMockInternal>true</GenerateMockInternal>
<ClassName>Gitea</ClassName>
</MyriadParams>
<WhippetFile>swagger-gitea.json</WhippetFile>
<WhippetParamGenerateMockInternal>true</WhippetParamGenerateMockInternal>
<WhippetParamClassName>Gitea</WhippetParamClassName>
</Compile>
<Compile Include="Generated2SwaggerGitea.fs">
<MyriadFile>GeneratedSwaggerGitea.fs</MyriadFile>
<WhippetFile>GeneratedSwaggerGitea.fs</WhippetFile>
</Compile>
</ItemGroup>

<ItemGroup>
<PackageReference Include="RestEase" Version="1.6.4"/>
<ProjectReference Include="..\WoofWare.Myriad.Plugins.Attributes\WoofWare.Myriad.Plugins.Attributes.fsproj" />
<ProjectReference Include="..\WoofWare.Myriad.Plugins\WoofWare.Myriad.Plugins.fsproj" PrivateAssets="all" />
<PackageReference Include="Myriad.Sdk" Version="0.8.3" PrivateAssets="all" />
<ProjectReference Include="..\WoofWare.Myriad.Plugins\WoofWare.Myriad.Plugins.fsproj" PrivateAssets="all" WhippetPlugin="true" />
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now all you need to do is add WhippetPlugin="true" and that's all the plugin registration done.

<PackageReference Include="WoofWare.Whippet" Version="0.1.6-gc23a25b8e0" PrivateAssets="all" />
</ItemGroup>

</Project>
6 changes: 0 additions & 6 deletions ConsumePlugin/Generated2SwaggerGitea.fs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
//------------------------------------------------------------------------------
// This code was generated by myriad.
// Changes to this file will be lost when the code is regenerated.
//------------------------------------------------------------------------------


namespace Gitea

open WoofWare.Myriad.Plugins
Expand Down
10 changes: 0 additions & 10 deletions ConsumePlugin/GeneratedArgs.fs
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
//------------------------------------------------------------------------------
// This code was generated by myriad.
// Changes to this file will be lost when the code is regenerated.
//------------------------------------------------------------------------------






namespace ConsumePlugin

open System
Expand Down
9 changes: 0 additions & 9 deletions ConsumePlugin/GeneratedCatamorphism.fs
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
//------------------------------------------------------------------------------
// This code was generated by myriad.
// Changes to this file will be lost when the code is regenerated.
//------------------------------------------------------------------------------





namespace ConsumePlugin

open WoofWare.Myriad.Plugins
Expand Down
9 changes: 0 additions & 9 deletions ConsumePlugin/GeneratedFileSystem.fs
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
//------------------------------------------------------------------------------
// This code was generated by myriad.
// Changes to this file will be lost when the code is regenerated.
//------------------------------------------------------------------------------





namespace ConsumePlugin

open WoofWare.Myriad.Plugins
Expand Down
6 changes: 0 additions & 6 deletions ConsumePlugin/GeneratedJson.fs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
//------------------------------------------------------------------------------
// This code was generated by myriad.
// Changes to this file will be lost when the code is regenerated.
//------------------------------------------------------------------------------


namespace ConsumePlugin

open System.Text.Json.Serialization
Expand Down
5 changes: 0 additions & 5 deletions ConsumePlugin/GeneratedMock.fs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
//------------------------------------------------------------------------------
// This code was generated by myriad.
// Changes to this file will be lost when the code is regenerated.
//------------------------------------------------------------------------------

namespace SomeNamespace

open System
Expand Down
5 changes: 0 additions & 5 deletions ConsumePlugin/GeneratedMockNoAttributes.fs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
//------------------------------------------------------------------------------
// This code was generated by myriad.
// Changes to this file will be lost when the code is regenerated.
//------------------------------------------------------------------------------

namespace SomeNamespace

open System
Expand Down
6 changes: 0 additions & 6 deletions ConsumePlugin/GeneratedPureGymDto.fs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
//------------------------------------------------------------------------------
// This code was generated by myriad.
// Changes to this file will be lost when the code is regenerated.
//------------------------------------------------------------------------------


namespace PureGym

open System
Expand Down
4 changes: 0 additions & 4 deletions ConsumePlugin/GeneratedRecord.fs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
//------------------------------------------------------------------------------
// This code was generated by myriad.
// Changes to this file will be lost when the code is regenerated.
//------------------------------------------------------------------------------
namespace ConsumePlugin

/// Module containing an option-truncated version of the RecordType type
Expand Down
8 changes: 0 additions & 8 deletions ConsumePlugin/GeneratedRestClient.fs
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
//------------------------------------------------------------------------------
// This code was generated by myriad.
// Changes to this file will be lost when the code is regenerated.
//------------------------------------------------------------------------------




namespace PureGym

open System
Expand Down
6 changes: 0 additions & 6 deletions ConsumePlugin/GeneratedSerde.fs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
//------------------------------------------------------------------------------
// This code was generated by myriad.
// Changes to this file will be lost when the code is regenerated.
//------------------------------------------------------------------------------


namespace ConsumePlugin

open System
Expand Down
11 changes: 0 additions & 11 deletions ConsumePlugin/GeneratedSwaggerGitea.fs
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
//------------------------------------------------------------------------------
// This code was generated by myriad.
// Changes to this file will be lost when the code is regenerated.
//------------------------------------------------------------------------------







namespace Gitea

open WoofWare.Myriad.Plugins
Expand Down
7 changes: 0 additions & 7 deletions ConsumePlugin/GeneratedVault.fs
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
//------------------------------------------------------------------------------
// This code was generated by myriad.
// Changes to this file will be lost when the code is regenerated.
//------------------------------------------------------------------------------



namespace ConsumePlugin

/// Module containing JSON parsing methods for the JwtVaultAuthResponse type
Expand Down
9 changes: 0 additions & 9 deletions ConsumePlugin/ListCata.fs
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
//------------------------------------------------------------------------------
// This code was generated by myriad.
// Changes to this file will be lost when the code is regenerated.
//------------------------------------------------------------------------------





namespace ConsumePlugin

open WoofWare.Myriad.Plugins
Expand Down
17 changes: 17 additions & 0 deletions NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />

<add key="Local Packages" value="/Users/patrick/Documents/GitHub/WoofWare.Whippet/WoofWare.Whippet/bin/Release/" />
</packageSources>

<packageSourceMapping>
<packageSource key="Local Packages">
<package pattern="WoofWare.Whippet" />
</packageSource>
<packageSource key="nuget.org">
<package pattern="*" />
</packageSource>
</packageSourceMapping>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/>
<PackageReference Include="NUnit" Version="4.2.2"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0"/>
<PackageReference Include="RestEase" Version="1.6.4"/>
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dunno why this transitive reference became required.

</ItemGroup>

<ItemGroup>
Expand Down
19 changes: 10 additions & 9 deletions WoofWare.Myriad.Plugins/ArgParserGenerator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ namespace WoofWare.Myriad.Plugins
open System
open System.Text
open Fantomas.FCS.Syntax
open WoofWare.Whippet.Core
open WoofWare.Whippet.Fantomas
open Fantomas.FCS.Text.Range
open TypeEquality
open WoofWare.Whippet.Fantomas
Expand Down Expand Up @@ -1745,18 +1747,17 @@ module internal ArgParserGenerator =
]
|> SynModuleOrNamespace.createNamespace ns

open Myriad.Core

/// Myriad generator that provides a catamorphism for an algebraic data type.
[<MyriadGenerator("arg-parser")>]
[<WhippetGenerator>]
type ArgParserGenerator () =

interface IMyriadGenerator with
member _.ValidInputExtensions = [ ".fs" ]
interface IGenerateRawFromRaw with
member _.GenerateRawFromRaw (context : RawSourceGenerationArgs) =
Copy link
Owner Author

@Smaug123 Smaug123 Oct 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the most basic API on which all other APIs are built. I intend adding optional convenience APIs on top, eventually, but this API shape is how we get the most modular design (which e.g. allows the consumer to freely upgrade Fantomas).

if not (context.FilePath.EndsWith (".fs", StringComparison.Ordinal)) then
null
else

member _.Generate (context : GeneratorContext) =
let ast, _ =
Ast.fromFilename context.InputFilename |> Async.RunSynchronously |> Array.head
let ast = Ast.parse (Encoding.UTF8.GetString context.FileContents)

let types = Ast.getTypes ast

Expand Down Expand Up @@ -1816,4 +1817,4 @@ type ArgParserGenerator () =
ArgParserGenerator.createModule opens ns taggedType unions records
)

Output.Ast modules
Ast.render modules |> Option.toObj
19 changes: 10 additions & 9 deletions WoofWare.Myriad.Plugins/CataGenerator.fs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
namespace WoofWare.Myriad.Plugins

open System
open Fantomas.FCS.Syntax
open Fantomas.FCS.SyntaxTrivia
open Fantomas.FCS.Xml
open WoofWare.Whippet.Core
open WoofWare.Whippet.Fantomas

[<RequireQualifiedAccess>]
Expand Down Expand Up @@ -1197,18 +1199,17 @@ module internal CataGenerator =
| _ -> ()
]

open Myriad.Core

/// Myriad generator that provides a catamorphism for an algebraic data type.
[<MyriadGenerator("create-catamorphism")>]
[<WhippetGenerator>]
type CreateCatamorphismGenerator () =

interface IMyriadGenerator with
member _.ValidInputExtensions = [ ".fs" ]
interface IGenerateRawFromRaw with
member _.GenerateRawFromRaw (context : RawSourceGenerationArgs) =
if not (context.FilePath.EndsWith (".fs", StringComparison.Ordinal)) then
null
else

member _.Generate (context : GeneratorContext) =
let ast, _ =
Ast.fromFilename context.InputFilename |> Async.RunSynchronously |> Array.head
let ast = Ast.parse (System.Text.Encoding.UTF8.GetString context.FileContents)

let types = CataGenerator.groupedTypeDefns ast

Expand Down Expand Up @@ -1254,4 +1255,4 @@ type CreateCatamorphismGenerator () =
CataGenerator.createModule opens ns taggedType unions records
)

Output.Ast modules
Ast.render modules |> Option.toObj
Loading
Loading