Skip to content

Commit e96b4ac

Browse files
oxxaKrzysztof-Cieslak
authored andcommitted
Add config option to specify tools directory (#103)
1 parent 3004041 commit e96b4ac

File tree

3 files changed

+45
-16
lines changed

3 files changed

+45
-16
lines changed

release/package.json

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,20 @@
155155
}
156156
],
157157
"configuration": {
158-
"type": "object",
159-
"title": "FSharp configuration",
160-
"properties": {
161-
"FSharp.automaticProjectModification": {
162-
"type": "boolean",
163-
"default": false,
164-
"description": "Automatically modifies fsproj on file add/remove"
165-
}
158+
"type": "object",
159+
"title": "FSharp configuration",
160+
"properties": {
161+
"FSharp.automaticProjectModification": {
162+
"type": "boolean",
163+
"default": false,
164+
"description": "Automatically modifies fsproj on file add/remove"
165+
},
166+
"FSharp.toolsDirPath": {
167+
"type": "string",
168+
"default": "",
169+
"description": "The directory containing the F# tools"
166170
}
171+
}
167172
}
168173
},
169174
"activationEvents": [

src/Components/Environment.fs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,21 @@ namespace Ionide.VSCode.FSharp
66
// Below code adapted from similar in FSSutoComplete project
77
module 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

src/Components/Fsi.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module Fsi =
2020

2121
let private start () =
2222
try
23-
//window.showInformationMessage ("FSI path: " + Environment.fsi) |> ignore
23+
// window.showInformationMessage ("FSI path: " + Environment.fsi) |> ignore
2424
fsiProcess |> Option.iter(fun fp -> fp.kill ())
2525
fsiProcess <-
2626
(Process.spawn Environment.fsi "" "--fsi-server-input-codepage:65001")

0 commit comments

Comments
 (0)