Skip to content

Commit

Permalink
Unify behavior of send references to FSI and generate references (#2029)
Browse files Browse the repository at this point in the history
  • Loading branch information
baronfel authored Aug 10, 2024
1 parent eb9373f commit 35834a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
24 changes: 9 additions & 15 deletions src/Components/Fsi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
10 changes: 5 additions & 5 deletions src/Core/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 35834a0

Please sign in to comment.