diff --git a/src/Components/Fsi.fs b/src/Components/Fsi.fs index 4b7ae285..e963f7b6 100644 --- a/src/Components/Fsi.fs +++ b/src/Components/Fsi.fs @@ -609,18 +609,17 @@ module Fsi = None - let sendReferencesForProject project = - let references = - project.References - |> Seq.filter (fun n -> n.EndsWith "FSharp.Core.dll" |> not && n.EndsWith "mscorlib.dll" |> not) - |> Seq.toList - - let sendReference terminal (path: ResolvedReferencePath) = send terminal $"#r @\"%s{path}\"" + let private fsiInitCommandsForProject (project: Project) = + [| yield! + project.References + |> Seq.filter (fun n -> n.EndsWith "FSharp.Core.dll" |> not && n.EndsWith "mscorlib.dll" |> not) + |> Seq.map (sprintf "#r @\"%s\"") + yield! project.Files |> Seq.map (sprintf "#load @\"%s\"") |] + let sendReferencesForProject project = promise { let! terminal = getTerminal () - - do! Promise.executeForAll (sendReference terminal) references + do! Promise.executeForAll (fun i -> send terminal i) (fsiInitCommandsForProject project) } |> Promise.suppress |> ignore @@ -635,12 +634,7 @@ module Fsi = | None -> window.showErrorMessage ("File not in a project") |> ignore let generateProjectReferencesForProject project = - let ctn = - [| yield! - project.References - |> Seq.filter (fun n -> n.EndsWith "FSharp.Core.dll" |> not && n.EndsWith "mscorlib.dll" |> not) - |> Seq.map (sprintf "#r @\"%s\"") - yield! project.Files |> Seq.map (sprintf "#load @\"%s\"") |] + let ctn = fsiInitCommandsForProject project promise { let path = node.path.join (workspace.rootPath.Value, "references.fsx") diff --git a/src/Core/Utils.fs b/src/Core/Utils.fs index 92bd652e..0a742a8a 100644 --- a/src/Core/Utils.fs +++ b/src/Core/Utils.fs @@ -316,11 +316,11 @@ module Promise = let suppress (pr: JS.Promise<'T>) = pr |> Promise.either (fun _ -> U2.Case1()) (fun _ -> U2.Case1()) - let executeForAll f items = - match items with - | [] -> empty - | [ x ] -> f x - | x :: tail -> tail |> List.fold (fun acc next -> acc |> Promise.bind (fun _ -> f next)) (f x) + let executeForAll f (items: #seq<'t>) = + if Seq.isEmpty items then + empty + else + Seq.fold (fun acc next -> acc |> Promise.bind (fun _ -> f next)) (f (Seq.head items)) (Seq.skip 1 items) let mapExecuteForAll (f: 'a -> JS.Promise<'b>) items = let mutable collected = ResizeArray()