diff --git a/src/fsharp/CompileOps.fs b/src/fsharp/CompileOps.fs index 7848de02e7..213a14beeb 100755 --- a/src/fsharp/CompileOps.fs +++ b/src/fsharp/CompileOps.fs @@ -4991,7 +4991,8 @@ module private ScriptPreprocessClosure = [ClosedSourceFile(filename,m,None,[],[],[])] // Don't traverse into .fs leafs. let loadedSources = (!tcConfig).GetAvailableLoadedSources() |> List.rev |> List.map AddFileIfNotSeen |> List.concat - ClosedSourceFile(filename,m,Some(input),!errors,!warnings,!noWarns) :: loadedSources |> List.map FindClosure |> List.concat // Final closure is in reverse order. Keep the closed source at the top. + (loadedSources |> List.map FindClosure |> List.concat) + @ [ClosedSourceFile(filename,m,Some(input),!errors,!warnings,!noWarns)] | None -> [ClosedSourceFile(filename,m,None,!errors,!warnings,[])] closureDirectives |> List.map FindClosure |> List.concat, !tcConfig @@ -5053,7 +5054,7 @@ module private ScriptPreprocessClosure = let rootWarnings = rootWarnings |> List.filter isRootRange let result : LoadClosure = - { SourceFiles = List.groupByFirst !sourceFiles + { SourceFiles = List.groupByFirst !sourceFiles |> List.rev References = List.groupByFirst references UnresolvedReferences = unresolvedReferences Inputs = !sourceInputs diff --git a/src/fsharp/vs/service.fs b/src/fsharp/vs/service.fs index 5484afdea6..90ba909e93 100755 --- a/src/fsharp/vs/service.fs +++ b/src/fsharp/vs/service.fs @@ -2552,7 +2552,7 @@ type BackgroundCompiler(projectCacheSize, keepAssemblyContents, keepAllBackgroun let co = { ProjectFileName = filename + ".fsproj" // Make a name that is unique in this directory. - ProjectFileNames = fas.Inputs |> List.map fst |> List.toArray + ProjectFileNames = fas.SourceFiles |> List.map fst |> List.toArray OtherOptions = otherFlags ReferencedProjects= [| |] IsIncompleteTypeCheckEnvironment = false diff --git a/tests/service/ProjectOptionsTests.fs b/tests/service/ProjectOptionsTests.fs index e6377a0fe3..a916254397 100644 --- a/tests/service/ProjectOptionsTests.fs +++ b/tests/service/ProjectOptionsTests.fs @@ -409,5 +409,17 @@ let ``Project file parsing -- space in file name``() = |> set |> should equal (set [ "Test2File1.fs"; "Test2File2.fs" ]) +[] +let ``Test ProjectFileNames order for GetProjectOptionsFromScript`` () = // See #594 + let scriptPath = __SOURCE_DIRECTORY__ + @"/data/ScriptProject/Main.fsx" + let scriptSource = File.ReadAllText scriptPath + let projOpts = + checker.GetProjectOptionsFromScript(scriptPath, scriptSource) + |> Async.RunSynchronously + projOpts.ProjectFileNames + |> Array.map Path.GetFileNameWithoutExtension + |> (=) [|"BaseLib"; "Lib1"; "Lib2"; "Main"|] + |> shouldEqual true + #endif diff --git a/tests/service/data/ScriptProject/BaseLib.fs b/tests/service/data/ScriptProject/BaseLib.fs new file mode 100644 index 0000000000..7d68a8615a --- /dev/null +++ b/tests/service/data/ScriptProject/BaseLib.fs @@ -0,0 +1,3 @@ +module BaseLib + +let add2 x = x + 2 \ No newline at end of file diff --git a/tests/service/data/ScriptProject/Lib1.fsx b/tests/service/data/ScriptProject/Lib1.fsx new file mode 100644 index 0000000000..171cfef719 --- /dev/null +++ b/tests/service/data/ScriptProject/Lib1.fsx @@ -0,0 +1,2 @@ +#load "BaseLib.fs" +let add3 = BaseLib.add2 >> ((+) 1) \ No newline at end of file diff --git a/tests/service/data/ScriptProject/Lib2.fsx b/tests/service/data/ScriptProject/Lib2.fsx new file mode 100644 index 0000000000..00c440b1d4 --- /dev/null +++ b/tests/service/data/ScriptProject/Lib2.fsx @@ -0,0 +1,2 @@ +#load "BaseLib.fs" +let add4 = BaseLib.add2 >> ((+) 2) \ No newline at end of file diff --git a/tests/service/data/ScriptProject/Main.fsx b/tests/service/data/ScriptProject/Main.fsx new file mode 100644 index 0000000000..90086fc76d --- /dev/null +++ b/tests/service/data/ScriptProject/Main.fsx @@ -0,0 +1,4 @@ +#load "Lib1.fsx" +#load "Lib2.fsx" +Lib1.add3 5 |> printfn "%i" +Lib2.add4 5 |> printfn "%i" \ No newline at end of file