Skip to content

Commit 235c599

Browse files
Add silentCd and line file to Fsi
1 parent d6789f5 commit 235c599

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/Components/Fsi.fs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,42 @@ module Fsi =
3232
|> Some
3333
fsiOutput |> Option.iter (fun fo -> fo.show (2 |> unbox) )
3434

35-
let private send (msg : string) =
35+
let private send (msg : string) file =
36+
3637
if fsiProcess.IsNone then start ()
3738
let msg = msg.Replace("\uFEFF", "") + ";;\n"
3839
fsiOutput |> Option.iter (fun fo -> fo.append msg)
39-
fsiProcess |> Option.iter (fun fp -> fp.stdin.write(msg, "utf-8" |> unbox) |> ignore)
40+
let msg' =
41+
try
42+
let dir = path.Globals.dirname file
43+
"\n"
44+
+ (sprintf "# silentCd @\"%s\" ;; " dir) + "\n"
45+
+ (sprintf "# %d @\"%s\" " 1 file) + "\n"
46+
+ msg
47+
with
48+
| _ -> msg
49+
50+
fsiProcess |> Option.iter (fun fp -> fp.stdin.write(msg', "utf-8" |> unbox) |> ignore)
4051

4152
let private sendLine () =
4253
let editor = window.Globals.activeTextEditor
54+
let file = editor.document.fileName
4355
let pos = editor.selection.start
4456
let line = editor.document.lineAt pos
45-
send line.text
57+
send line.text file
4658

4759
let private sendSelection () =
4860
let editor = window.Globals.activeTextEditor
61+
let file = editor.document.fileName
4962
let range = Range.Create (editor.selection.anchor, editor.selection.active)
50-
editor.document.getText range |> send
63+
let text = editor.document.getText range
64+
send text file
5165

5266
let private sendFile () =
5367
let editor = window.Globals.activeTextEditor
54-
editor.document.getText () |> send
68+
let file = editor.document.fileName
69+
let text = editor.document.getText ()
70+
send text file
5571

5672
let activate (disposables: Disposable[]) =
5773
commands.Globals.registerCommand("fsi.Start", start |> unbox) |> ignore

0 commit comments

Comments
 (0)