diff --git a/src/Fable.Compiler/CHANGELOG.md b/src/Fable.Compiler/CHANGELOG.md index d2263d8609..9c2d6b52cf 100644 --- a/src/Fable.Compiler/CHANGELOG.md +++ b/src/Fable.Compiler/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Changed + +* [GH-3742](https://github.com/fable-compiler/Fable/pull/3742) Return diagnostics in compile response (by @nojaf) + ## 4.0.0-alpha-004 - 2024-01-30 ### Changed diff --git a/src/Fable.Compiler/Library.fs b/src/Fable.Compiler/Library.fs index 1b2ddca728..649ea1b866 100644 --- a/src/Fable.Compiler/Library.fs +++ b/src/Fable.Compiler/Library.fs @@ -4,12 +4,21 @@ open System open System.IO open FSharp.Compiler.CodeAnalysis open FSharp.Compiler.SourceCodeServices +open FSharp.Compiler.Diagnostics open Fable open Fable.Transforms.State open Fable.Transforms open Fable.Compiler.ProjectCracker open Fable.Compiler.Util +type CompileResult = + { + /// A map of absolute file path to transpiled JavaScript code + CompiledFiles: Map + /// Diagnostics of the entire checked F# project + Diagnostics: FSharpDiagnostic array + } + type BabelWriter ( com: Compiler, @@ -100,7 +109,7 @@ let compileProjectToJavaScript (pathResolver: PathResolver) (cliArgs: CliArgs) (crackerResponse: CrackerResponse) - : Async> + : Async = async { let! assemblies = checker.GetImportedAssemblies() @@ -151,7 +160,11 @@ let compileProjectToJavaScript ) |> Async.Parallel - return Map.ofArray compiledFiles + return + { + CompiledFiles = Map.ofArray compiledFiles + Diagnostics = checkProjectResult.Diagnostics + } } let compileFileToJavaScript @@ -161,7 +174,7 @@ let compileFileToJavaScript (cliArgs: CliArgs) (crackerResponse: CrackerResponse) (currentFile: string) - : Async> + : Async = async { let! dependentFiles = @@ -222,5 +235,9 @@ let compileFileToJavaScript ) |> Async.Parallel - return Map.ofArray compiledFiles + return + { + CompiledFiles = Map.ofArray compiledFiles + Diagnostics = checkProjectResult.Diagnostics + } } diff --git a/src/Fable.Compiler/Library.fsi b/src/Fable.Compiler/Library.fsi index 874d9ca4e3..4d347ddc79 100644 --- a/src/Fable.Compiler/Library.fsi +++ b/src/Fable.Compiler/Library.fsi @@ -1,10 +1,19 @@ module Fable.Compiler.CodeServices open FSharp.Compiler.SourceCodeServices +open FSharp.Compiler.Diagnostics open Fable open Fable.Compiler.Util open Fable.Compiler.ProjectCracker +type CompileResult = + { + /// A map of absolute file path to transpiled JavaScript + CompiledFiles: Map + /// Diagnostics of the entire checked F# project + Diagnostics: FSharpDiagnostic array + } + /// Does a full type-check of the current project. /// And compiles the implementation files to JavaScript. val compileProjectToJavaScript: @@ -13,7 +22,7 @@ val compileProjectToJavaScript: pathResolver: PathResolver -> cliArgs: CliArgs -> crackerResponse: CrackerResponse -> - Async> + Async /// Type-checks the project up until the last transitive dependent file. /// Compile the current and the transitive dependent files to JavaScript. @@ -24,4 +33,4 @@ val compileFileToJavaScript: cliArgs: CliArgs -> crackerResponse: CrackerResponse -> currentFile: string -> - Async> + Async