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

Return diagnostics in compile response #3742

Merged
merged 2 commits into from
Feb 7, 2024
Merged
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
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>
Loading