@@ -6,18 +6,21 @@ namespace Ionide.VSCode.FSharp
66// Below code adapted from similar in FSSutoComplete project
77module Environment =
88 open Fable.Core
9+ open Fable.Import .vscode
910 open Fable.Import .Node
1011 open Fable.Import .Node .fs_types
1112
12- let isWin = `` process `` .platform = " win32"
13+ let private isWin = `` process `` .platform = " win32"
1314
14- let (</>) a b =
15+ let private (</>) a b =
1516 if isWin then a + @" \" + b
1617 else a + " /" + b
1718
18- let dirExists dir = fs.statSync( dir) .isDirectory()
19+ let private dirExists dir = fs.statSync( dir) .isDirectory()
1920
20- let getOrElse defaultValue option =
21+ let private fileExists file = fs.statSync( file) .isFile()
22+
23+ let private getOrElse defaultValue option =
2124 match option with
2225 | None -> defaultValue
2326 | Some x -> x
@@ -32,11 +35,32 @@ module Environment =
3235 if detected = null then @" C:\Program Files (x86)\"
3336 else detected
3437
35- let private fsharpInstallationPath () =
38+ let private getToolsPathWindows () =
3639 [ " 4.0" ; " 3.1" ; " 3.0" ]
3740 |> List.map ( fun v -> programFilesX86 </> @" \Microsoft SDKs\F#\" </> v </> @" \Framework\v4.0" )
3841 |> List.tryFind dirExists
3942
43+ let private getToolsPathFromConfiguration () =
44+ let cfg = workspace.getConfiguration ()
45+ let path = cfg.get( " FSharp.toolsDirPath" , " " )
46+ if not ( path = " " ) && dirExists path then Some path
47+ else None
48+
49+ let private getListDirectoriesToSearchForTools () =
50+ if isWin then
51+ [ getToolsPathFromConfiguration (); getToolsPathWindows () ]
52+ else
53+ [ getToolsPathFromConfiguration () ]
54+ |> List.choose id
55+
56+ let private findFirstValidFilePath exeName directoryList =
57+ directoryList
58+ |> List.map ( fun v -> v </> exeName)
59+ |> List.tryFind fileExists
60+
4061 let fsi =
41- if not isWin then " fsharpi"
42- else getOrElse " " ( fsharpInstallationPath ()) </> " fsi.exe"
62+ let fileName = if isWin then " fsi.exe" else " fsharpi"
63+ let dirs = getListDirectoriesToSearchForTools ()
64+ match findFirstValidFilePath fileName dirs with
65+ | None -> fileName
66+ | Some x -> x
0 commit comments