Skip to content

Commit 04ff9aa

Browse files
authored
Look up and propagate ReScript version (#867)
* look up and propagate ReScript version to analysis so we can default uncurried by default properly * revert test changes * changelog
1 parent 23bcade commit 04ff9aa

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#### :bug: Bug Fix
2020

21+
- Proper default for `"uncurried"` in V11 projects. https://github.com/rescript-lang/rescript-vscode/pull/867
2122
- Treat `result` type as a proper built in type. https://github.com/rescript-lang/rescript-vscode/pull/860
2223

2324
#### :nail_care: Polish

analysis/src/Packages.ml

+21-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@ let makePathsForModule ~projectFilesAndPaths ~dependenciesFilesAndPaths =
1111
Hashtbl.replace pathsForModule modName paths);
1212
pathsForModule
1313

14+
let getReScriptVersion () =
15+
(* TODO: Include patch stuff when needed *)
16+
let defaultVersion = (10, 1) in
17+
try
18+
let value = Sys.getenv "RESCRIPT_VERSION" in
19+
let version =
20+
match value |> String.split_on_char '.' with
21+
| major :: minor :: _rest -> (
22+
match (int_of_string_opt major, int_of_string_opt minor) with
23+
| Some major, Some minor -> (major, minor)
24+
| _ -> defaultVersion)
25+
| _ -> defaultVersion
26+
in
27+
version
28+
with Not_found -> defaultVersion
29+
1430
let newBsPackage ~rootPath =
1531
let rescriptJson = Filename.concat rootPath "rescript.json" in
1632
let bsconfigJson = Filename.concat rootPath "bsconfig.json" in
@@ -27,9 +43,12 @@ let newBsPackage ~rootPath =
2743
| Some libBs ->
2844
Some
2945
(let namespace = FindFiles.getNamespace config in
46+
let rescriptVersion = getReScriptVersion () in
3047
let uncurried =
3148
let ns = config |> Json.get "uncurried" in
32-
Option.bind ns Json.bool
49+
match (rescriptVersion, ns) with
50+
| (major, _), None when major >= 11 -> Some true
51+
| _, ns -> Option.bind ns Json.bool
3352
in
3453
let uncurried = uncurried = Some true in
3554
let sourceDirectories =
@@ -93,6 +112,7 @@ let newBsPackage ~rootPath =
93112
("Opens from ReScript config file: "
94113
^ (opens |> List.map pathToString |> String.concat " "));
95114
{
115+
rescriptVersion;
96116
rootPath;
97117
projectFiles =
98118
projectFilesAndPaths |> List.map fst |> FileSet.of_list;

analysis/src/SharedTypes.ml

+1
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ type package = {
493493
builtInCompletionModules: builtInCompletionModules;
494494
opens: path list;
495495
uncurried: bool;
496+
rescriptVersion: int * int;
496497
}
497498

498499
let allFilesInPackage package =

server/src/utils.ts

+28
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,29 @@ export let formatCode = (
136136
}
137137
};
138138

139+
let findReScriptVersion = (filePath: p.DocumentUri): string | undefined => {
140+
let projectRoot = findProjectRootOfFile(filePath);
141+
if (projectRoot == null) {
142+
return undefined;
143+
}
144+
145+
let rescriptBinary = lookup.findFilePathFromProjectRoot(
146+
projectRoot,
147+
path.join(c.nodeModulesBinDir, c.rescriptBinName)
148+
);
149+
150+
if (rescriptBinary == null) {
151+
return undefined;
152+
}
153+
154+
try {
155+
let version = childProcess.execSync(`${rescriptBinary} -v`);
156+
return version.toString().trim();
157+
} catch (e) {
158+
return undefined;
159+
}
160+
};
161+
139162
export let runAnalysisAfterSanityCheck = (
140163
filePath: p.DocumentUri,
141164
args: Array<any>,
@@ -154,9 +177,14 @@ export let runAnalysisAfterSanityCheck = (
154177
if (projectRootPath == null && projectRequired) {
155178
return null;
156179
}
180+
let rescriptVersion = findReScriptVersion(filePath);
157181
let options: childProcess.ExecFileSyncOptions = {
158182
cwd: projectRootPath || undefined,
159183
maxBuffer: Infinity,
184+
env: {
185+
...process.env,
186+
RESCRIPT_VERSION: rescriptVersion,
187+
},
160188
};
161189
let stdout = childProcess.execFileSync(binaryPath, args, options);
162190

0 commit comments

Comments
 (0)