Skip to content

Commit

Permalink
Merge pull request fable-compiler#3742 from nojaf/add-diagnostics
Browse files Browse the repository at this point in the history
Return diagnostics in compile response
  • Loading branch information
nojaf authored Feb 7, 2024
2 parents 436c10c + 816483f commit bb09d11
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/Fable.Compiler/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 21 additions & 4 deletions src/Fable.Compiler/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>
/// Diagnostics of the entire checked F# project
Diagnostics: FSharpDiagnostic array
}

type BabelWriter
(
com: Compiler,
Expand Down Expand Up @@ -100,7 +109,7 @@ let compileProjectToJavaScript
(pathResolver: PathResolver)
(cliArgs: CliArgs)
(crackerResponse: CrackerResponse)
: Async<Map<string, string>>
: Async<CompileResult>
=
async {
let! assemblies = checker.GetImportedAssemblies()
Expand Down Expand Up @@ -151,7 +160,11 @@ let compileProjectToJavaScript
)
|> Async.Parallel

return Map.ofArray compiledFiles
return
{
CompiledFiles = Map.ofArray compiledFiles
Diagnostics = checkProjectResult.Diagnostics
}
}

let compileFileToJavaScript
Expand All @@ -161,7 +174,7 @@ let compileFileToJavaScript
(cliArgs: CliArgs)
(crackerResponse: CrackerResponse)
(currentFile: string)
: Async<Map<string, string>>
: Async<CompileResult>
=
async {
let! dependentFiles =
Expand Down Expand Up @@ -222,5 +235,9 @@ let compileFileToJavaScript
)
|> Async.Parallel

return Map.ofArray compiledFiles
return
{
CompiledFiles = Map.ofArray compiledFiles
Diagnostics = checkProjectResult.Diagnostics
}
}
13 changes: 11 additions & 2 deletions src/Fable.Compiler/Library.fsi
Original file line number Diff line number Diff line change
@@ -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<string, string>
/// 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:
Expand All @@ -13,7 +22,7 @@ val compileProjectToJavaScript:
pathResolver: PathResolver ->
cliArgs: CliArgs ->
crackerResponse: CrackerResponse ->
Async<Map<string, string>>
Async<CompileResult>

/// Type-checks the project up until the last transitive dependent file.
/// Compile the current and the transitive dependent files to JavaScript.
Expand All @@ -24,4 +33,4 @@ val compileFileToJavaScript:
cliArgs: CliArgs ->
crackerResponse: CrackerResponse ->
currentFile: string ->
Async<Map<string, string>>
Async<CompileResult>

0 comments on commit bb09d11

Please sign in to comment.