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

Unify behavior of send references to FSI and generate references #2029

Merged
merged 1 commit into from
Aug 10, 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
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
Loading