diff --git a/src/Fable.Compiler.Service/Library.fs b/src/Fable.Compiler.Service/Library.fs index 3cc23bdb51..48b01cc1d9 100644 --- a/src/Fable.Compiler.Service/Library.fs +++ b/src/Fable.Compiler.Service/Library.fs @@ -4,7 +4,6 @@ open System open System.Text open FSharp.Compiler.CodeAnalysis open FSharp.Compiler.SourceCodeServices -open FSharp.Compiler.Text open Fable open Fable.Compiler.Service.Util open Fable.Transforms.State @@ -98,6 +97,7 @@ type BabelWriter // mapGenerator.Force().AddMapping(generated, original, source=sourcePath, ?name=displayName) let mkCompilerForFile + (sourceReader: SourceReader) (checker: InteractiveChecker) (cliArgs: CliArgs) (crackerResponse: CrackerResponse) @@ -106,15 +106,6 @@ let mkCompilerForFile async { let! assemblies = checker.GetImportedAssemblies() - let sourceReader fileName = - let source = - Array.find - (fun sourceFile -> sourceFile = fileName) - crackerResponse.ProjectOptions.SourceFiles - |> System.IO.File.ReadAllText - - 1, lazy source - let! checkProjectResult = checker.ParseAndCheckProject( cliArgs.ProjectFile, @@ -153,7 +144,12 @@ let mkCompilerForFile ) } -let compileFile (com: Compiler) (pathResolver: PathResolver) (outPath: string) = +let compileFile + (sourceReader: SourceReader) + (com: Compiler) + (pathResolver: PathResolver) + (outPath: string) + = async { let babel = FSharp2Fable.Compiler.transformFile com @@ -171,17 +167,6 @@ let compileFile (com: Compiler) (pathResolver: PathResolver) (outPath: string) = do! BabelPrinter.run writer babel let output = writer.ToString() - - let sourceReader fileName = - let source = - Array.find - (fun sourceFile -> sourceFile = fileName) - com.SourceFiles - |> System.IO.File.ReadAllText - - 1, lazy source - - let! dependentFiles = com.GetDependentFiles() - + let! dependentFiles = com.GetDependentFiles sourceReader return output, dependentFiles } diff --git a/src/Fable.Compiler.Service/Library.fsi b/src/Fable.Compiler.Service/Library.fsi index fafc2768bd..a42f2c45a4 100644 --- a/src/Fable.Compiler.Service/Library.fsi +++ b/src/Fable.Compiler.Service/Library.fsi @@ -6,6 +6,7 @@ open Fable.Compiler.Service.Util open Fable.Compiler.Service.ProjectCracker val mkCompilerForFile: + sourceReader:SourceReader -> checker: InteractiveChecker -> cliArgs: CliArgs -> crackerResponse: CrackerResponse -> @@ -13,6 +14,7 @@ val mkCompilerForFile: Async val compileFile: + sourceReader:SourceReader -> com: Compiler -> pathResolver: PathResolver -> outPath: string -> diff --git a/src/Fable.Transforms/Dart/Fable2Dart.fs b/src/Fable.Transforms/Dart/Fable2Dart.fs index 52f6e86606..4bc28457c9 100644 --- a/src/Fable.Transforms/Dart/Fable2Dart.fs +++ b/src/Fable.Transforms/Dart/Fable2Dart.fs @@ -2284,7 +2284,7 @@ module Compiler = member _.AddWatchDependency(fileName) = com.AddWatchDependency(fileName) member _.AddLog(msg, severity, ?range, ?fileName:string, ?tag: string) = com.AddLog(msg, severity, ?range=range, ?fileName=fileName, ?tag=tag) - member _.GetDependentFiles () = com.GetDependentFiles() + member _.GetDependentFiles sourceReader = com.GetDependentFiles sourceReader let makeCompiler com = DartCompiler(com) diff --git a/src/Fable.Transforms/FSharp2Fable.fs b/src/Fable.Transforms/FSharp2Fable.fs index 6184d90940..e60c38d705 100644 --- a/src/Fable.Transforms/FSharp2Fable.fs +++ b/src/Fable.Transforms/FSharp2Fable.fs @@ -1934,7 +1934,7 @@ type FableCompiler(com: Compiler) = member _.AddWatchDependency(fileName) = com.AddWatchDependency(fileName) member _.AddLog(msg, severity, ?range, ?fileName:string, ?tag: string) = com.AddLog(msg, severity, ?range=range, ?fileName=fileName, ?tag=tag) - member _.GetDependentFiles () = com.GetDependentFiles() + member _.GetDependentFiles sourceReader = com.GetDependentFiles sourceReader let rec attachClassMembers (com: FableCompiler) = function diff --git a/src/Fable.Transforms/Fable2Babel.fs b/src/Fable.Transforms/Fable2Babel.fs index 209ad94ab0..835a4a9339 100644 --- a/src/Fable.Transforms/Fable2Babel.fs +++ b/src/Fable.Transforms/Fable2Babel.fs @@ -3164,7 +3164,7 @@ module Compiler = member _.AddWatchDependency(fileName) = com.AddWatchDependency(fileName) member _.AddLog(msg, severity, ?range, ?fileName:string, ?tag: string) = com.AddLog(msg, severity, ?range=range, ?fileName=fileName, ?tag=tag) - member _.GetDependentFiles () = com.GetDependentFiles() + member _.GetDependentFiles sourceReader = com.GetDependentFiles sourceReader let makeCompiler com = BabelCompiler(com) diff --git a/src/Fable.Transforms/Global/Compiler.fs b/src/Fable.Transforms/Global/Compiler.fs index 091e0c9e89..ebc5897c37 100644 --- a/src/Fable.Transforms/Global/Compiler.fs +++ b/src/Fable.Transforms/Global/Compiler.fs @@ -51,6 +51,8 @@ type InlineExpr = type CompilerPlugins = { MemberDeclarationPlugins: Map } +type SourceReader = string -> int * Lazy + type Compiler = abstract LibraryDir: string abstract CurrentFile: string @@ -73,7 +75,7 @@ type Compiler = /// Invokes InteractiveChecker.GetDependentFiles /// This will find dependent file via the untyped tree graph. - abstract GetDependentFiles: unit -> Async + abstract GetDependentFiles: sourceReader:SourceReader -> Async type InlineExprLazy(f: Compiler -> InlineExpr) = let mutable value: InlineExpr voption = ValueNone diff --git a/src/Fable.Transforms/Php/Fable2Php.fs b/src/Fable.Transforms/Php/Fable2Php.fs index 315976b65a..ea24351bcf 100644 --- a/src/Fable.Transforms/Php/Fable2Php.fs +++ b/src/Fable.Transforms/Php/Fable2Php.fs @@ -1652,7 +1652,7 @@ type PhpCompiler(com: Fable.Compiler) = member this.FindLableLevel(label) = List.findIndex(function Some v when v = label -> true | _ -> false) breakable - member _.GetDependentFiles () = com.GetDependentFiles() + member _.GetDependentFiles sourceReader = com.GetDependentFiles sourceReader module Compiler = diff --git a/src/Fable.Transforms/Python/Fable2Python.fs b/src/Fable.Transforms/Python/Fable2Python.fs index 28f2cde882..0720ad37b0 100644 --- a/src/Fable.Transforms/Python/Fable2Python.fs +++ b/src/Fable.Transforms/Python/Fable2Python.fs @@ -4182,7 +4182,7 @@ module Compiler = member _.AddLog(msg, severity, ?range, ?fileName: string, ?tag: string) = com.AddLog(msg, severity, ?range = range, ?fileName = fileName, ?tag = tag) - member _.GetDependentFiles () = com.GetDependentFiles() + member _.GetDependentFiles sourceReader = com.GetDependentFiles sourceReader let makeCompiler com = PythonCompiler(com) diff --git a/src/Fable.Transforms/Rust/Fable2Rust.fs b/src/Fable.Transforms/Rust/Fable2Rust.fs index 7d3830bbcc..71562b6482 100644 --- a/src/Fable.Transforms/Rust/Fable2Rust.fs +++ b/src/Fable.Transforms/Rust/Fable2Rust.fs @@ -4315,7 +4315,7 @@ module Compiler = member _.AddLog(msg, severity, ?range, ?fileName:string, ?tag: string) = com.AddLog(msg, severity, ?range=range, ?fileName=fileName, ?tag=tag) - member _.GetDependentFiles () = com.GetDependentFiles() + member _.GetDependentFiles sourceReader = com.GetDependentFiles sourceReader let makeCompiler com = RustCompiler(com) diff --git a/src/Fable.Transforms/State.fs b/src/Fable.Transforms/State.fs index a5606d0bda..3aceccca00 100644 --- a/src/Fable.Transforms/State.fs +++ b/src/Fable.Transforms/State.fs @@ -337,6 +337,5 @@ type CompilerImpl Log.Make(severity, msg, ?range=range, ?fileName=fileName, ?tag=tag) |> logs.Add - member _.GetDependentFiles () = - let sourceReader = File.MakeSourceReader (Array.map File project.SourceFiles) |> snd + member _.GetDependentFiles sourceReader = checker.GetDependentFiles (currentFile, project.SourceFiles, sourceReader) diff --git a/tests/FCSTest/Program.fs b/tests/FCSTest/Program.fs index 0e5600aee7..d62223243d 100644 --- a/tests/FCSTest/Program.fs +++ b/tests/FCSTest/Program.fs @@ -32,7 +32,7 @@ module CoolCatProjectCracking = && File.Exists filePath && not (filePath.Contains "obj") then - Some (Path.normalizeFullPath filePath) + Some(Path.normalizeFullPath filePath) else None ) @@ -122,7 +122,15 @@ module CoolCatProjectCracking = Directory.Delete(pwd, true) let fsprojOptions = - CoolCatProjectCracking.mkOptionsFromDesignTimeBuild fsprojPath "" + let sw = Stopwatch() + sw.Start() + + let options = + CoolCatProjectCracking.mkOptionsFromDesignTimeBuild fsprojPath "" + + sw.Stop() + printfn "Cracking took: %A" sw.Elapsed + options let crackerResponse: CrackerResponse = { FableLibDir = @@ -173,8 +181,17 @@ let cliArgs: CliArgs = { let checker = InteractiveChecker.Create(crackerResponse.ProjectOptions) +let sourceReader = + Fable.Transforms.File.MakeSourceReader( + Array.map + Fable.Transforms.File + crackerResponse.ProjectOptions.SourceFiles + ) + |> snd + let compilerForFile = mkCompilerForFile + sourceReader checker cliArgs crackerResponse @@ -189,10 +206,14 @@ let dummyPathResolver = let javascript, dependentFiles = compileFile + sourceReader compilerForFile dummyPathResolver @"C:\Users\nojaf\Projects\MyFableApp\Lib.js" |> Async.RunSynchronously printfn "this is javascript:\n%s" javascript -printfn "these files need to be reprocessed: %s" (String.concat "," dependentFiles) + +printfn + "these files need to be reprocessed: %s" + (String.concat "," dependentFiles)