@@ -311,6 +311,12 @@ module Fsi =
311
311
Some ( U2.Case2 work)
312
312
}
313
313
314
+ let private setupTerminalState ( terminal : Terminal ) =
315
+ terminal.processId |> Promise.onSuccess ( fun pId -> fsiOutputPID <- Some pId) |> ignore
316
+ lastCd <- None
317
+ lastCurrentFile <- None
318
+ fsiOutput <- Some terminal
319
+
314
320
let private start () =
315
321
fsiOutput |> Option.iter ( fun n -> n.dispose())
316
322
promise {
@@ -326,12 +332,7 @@ module Fsi =
326
332
window.showErrorMessage( " Unable to spawn FSI" , null ) |> ignore
327
333
failwith " unable to spawn FSI"
328
334
let w = Fable.Core.JsInterop.import " window" " vscode"
329
- let terminal : Terminal = w?createTerminal( profile.options)
330
- terminal.processId |> Promise.onSuccess ( fun pId -> fsiOutputPID <- Some pId) |> ignore
331
- lastCd <- None
332
- lastCurrentFile <- None
333
- fsiOutput <- Some terminal
334
- sendCd window.activeTextEditor
335
+ let terminal : Terminal = w?createTerminal( profile.options) // setting up terminal state will happen on the terminal listener
335
336
terminal.show( true )
336
337
return terminal
337
338
}
@@ -424,19 +425,25 @@ module Fsi =
424
425
|> Promise.suppress
425
426
|> ignore)
426
427
428
+
429
+ let private clearOldTerminalState () =
430
+ fsiOutput |> Option.iter ( fun t -> t.dispose())
431
+
427
432
let private handleCloseTerminal ( terminal : Terminal ) =
428
- fsiOutputPID
429
- |> Option.iter ( fun currentTerminalPID ->
430
- terminal.processId
431
- |> Promise.onSuccess ( fun closedTerminalPID ->
432
- if closedTerminalPID = currentTerminalPID then
433
- fsiOutput <- None
434
- fsiOutputPID <- None
435
- lastCd <- None
436
- lastCurrentFile <- None)
437
- |> Promise.suppress // prevent unhandled promise exception
438
- |> ignore)
439
- |> ignore
433
+ fsiOutput <- None
434
+ fsiOutputPID <- None
435
+ lastCd <- None
436
+ lastCurrentFile <- None
437
+ ()
438
+
439
+ // when a new terminal is created, if it's FSI and if we don't already have a terminal then setup the state for tracking FSI
440
+ let private handleOpenTerminal ( terminal : Terminal ): unit =
441
+ if terminal.name = fsiNetCoreName || terminal.name = fsiNetFrameworkName
442
+ then
443
+ clearOldTerminalState ()
444
+ setupTerminalState terminal
445
+ // initially have to set up the terminal to be in the correct start directory
446
+ sendCd window.activeTextEditor
440
447
441
448
let private generateProjectReferences () =
442
449
let ctn =
@@ -488,8 +495,8 @@ module Fsi =
488
495
SdkScriptsNotify.activate context
489
496
let w = Fable.Core.JsInterop.import " window" " vscode"
490
497
w?registerTerminalProfileProvider( " ionide-fsharp.fsi" , provider) |> context.subscriptions.Add
491
- window.onDidCloseTerminal $ ( handleCloseTerminal, (), context.subscriptions ) |> ignore
492
-
498
+ window.onDidCloseTerminal.Invoke ( handleCloseTerminal >> box ) |> context.subscriptions.Add
499
+ ( w?onDidOpenTerminal : Event < Terminal >) .Invoke ( handleOpenTerminal >> box ) |> context.subscriptions.Add
493
500
commands.registerCommand( " fsi.Start" , start |> objfy2) |> context.subscriptions.Add
494
501
commands.registerCommand( " fsi.SendLine" , sendLine |> objfy2) |> context.subscriptions.Add
495
502
commands.registerCommand( " fsi.SendSelection" , sendSelection |> objfy2) |> context.subscriptions.Add
0 commit comments