Skip to content

Commit

Permalink
Updated version, change log
Browse files Browse the repository at this point in the history
Made errors just write failure to the console not the source file.
  • Loading branch information
7sharp9 committed Oct 29, 2021
1 parent e5093a5 commit 8eb6f98
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 28 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.7.4]
### Changed
- Exceptions are no longer written to the generated files but are instead reported to the command line
With the advent on in line generation, errors out to the source code can be quite disruptive


## [0.7.3]
### Added
- Added ProjectPath to the project context so the full name of the project is know by the plugin rather than just its project name
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<GitHome>https://github.com/$(gitOwner)</GitHome>
<GitUrl>$(gitHome)/$(gitName)</GitUrl>
<NupkgsDir>$([System.IO.Path]::GetFullPath("$(MSBuildThisFileDirectory)/bin/nupkg"))</NupkgsDir>
<VersionPrefix Condition=" '$(VersionPrefix)' == '' ">0.7.3</VersionPrefix>
<VersionPrefix Condition=" '$(VersionPrefix)' == '' ">0.7.4</VersionPrefix>
<Version Condition=" '$(Version)' == '' ">$(VersionPrefix)$(VersionSuffix)</Version>
<!-- pack stuff -->
<TargetFrameworks>net5.0;netstandard2.0</TargetFrameworks>
Expand Down
49 changes: 22 additions & 27 deletions src/Myriad/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -142,62 +142,57 @@ module Main =
if verbose then
printfn $"Executing: %s{genType.FullName}..."

let result =
let result, errors =
try
if instance.ValidInputExtensions |> Seq.contains (Path.GetExtension(inputFile))
then
let context = GeneratorContext.Create(configKey, configHandler, inputFile, projectContext, additionalParams)
Some (instance.Generate(context))
else None
Some (instance.Generate(context)), None
else None, None
with
| exc ->
// emit the module with exception text
let info = SynComponentInfo.Create (Ident.CreateLong $"%s{genType.Name}Failure")
let pattern =
// intentionally generating invalid identifier name to fail the compilation
let name = LongIdentWithDots.CreateString "!CompilationError"
SynPat.CreateLongIdent(name, [])
let letBinding = SynBinding.Let(pattern = pattern, expr = SynExpr.CreateConstString (exc.ToString()))
let modulDecl = SynModuleDecl.CreateNestedModule(info, [SynModuleDecl.CreateLet [letBinding]])
Some (Output.Ast [SynModuleOrNamespace.CreateNamespace(Ident.CreateLong "", isRecursive = true, decls = [modulDecl])])
let info = $"%s{genType.Name} Failure"
let message = exc.ToString()
None, Some ($"%s{info}%s{Environment.NewLine}!CompilationError%s{Environment.NewLine}%s{message}")

if verbose then printfn $"Result: '%A{result}'"

result
result, errors

if verbose then
printfn "Execute generators:"
printfn $"Input Filename:\n:%A{inputFile}"

let generated =
generators
|> List.choose (runGenerator inputFile)
let generated = generators |> List.map (runGenerator inputFile)

let formattedCode =
let cfg = { FormatConfig.FormatConfig.Default with StrictMode = true }

let parseTree =
let outputCode =
let filename =
if inlineGeneration then
inputFile
else if outputFile.IsSome then
outputFile.Value
if inlineGeneration then inputFile
else if outputFile.IsSome then outputFile.Value
else failwith "Error: No OutputFile was included, and --selfgeneration was not specified."

generated
|> List.map (fun f ->
|> List.map (fun (f, errors) ->
//if theres an error just fail here
match errors with
| Some error -> failwithf $"%s{error}"
| _ -> ()

match f with
| Output.Ast ast ->
| Some(Output.Ast ast) ->
let parseTree = ParsedInput.ImplFile(ParsedImplFileInput.CreateFs(filename, modules = ast))
if verbose then
printfn "Generated Ast:------------------------------------"
printfn $"%A{parseTree}"
printfn "--------------------------------------------------"
CodeFormatter.FormatASTAsync(parseTree, "myriad.fsx", [], None, cfg) |> Async.RunSynchronously
| Output.Source source -> source )


| Some (Output.Source source) -> source
| None -> "")

parseTree |> String.concat Environment.NewLine
outputCode |> String.concat Environment.NewLine

let code = Generation.getHeaderedCode formattedCode
if verbose then
Expand Down
3 changes: 3 additions & 0 deletions test/Myriad.IntegrationPluginTests/ArbitaryFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// This code was generated by myriad.
// Changes to this file will be lost when the code is regenerated.
//------------------------------------------------------------------------------



namespace TestExample1

module First =
Expand Down
3 changes: 3 additions & 0 deletions test/Myriad.IntegrationPluginTests/ArbitaryFile2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// This code was generated by myriad.
// Changes to this file will be lost when the code is regenerated.
//------------------------------------------------------------------------------



namespace UnknownNamespace

module First =
Expand Down
1 change: 1 addition & 0 deletions test/Myriad.IntegrationPluginTests/FieldsLensDus.fs
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,4 @@ module Currency =
| Custom _ -> true
| _ -> false


1 change: 1 addition & 0 deletions test/Myriad.IntegrationPluginTests/InputSelfGenerate.fs
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,4 @@ module Currency =
| Custom _ -> true
| _ -> false


0 comments on commit 8eb6f98

Please sign in to comment.