Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion analysis/src/Packages.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ let makePathsForModule ~projectFilesAndPaths ~dependenciesFilesAndPaths =
Hashtbl.replace pathsForModule modName paths);
pathsForModule

let getReScriptVersion () =
(* TODO: Include patch stuff when needed *)
let defaultVersion = (10, 1) in
try
let value = Sys.getenv "RESCRIPT_VERSION" in
let version =
match value |> String.split_on_char '.' with
| major :: minor :: _rest -> (
match (int_of_string_opt major, int_of_string_opt minor) with
| Some major, Some minor -> (major, minor)
| _ -> defaultVersion)
| _ -> defaultVersion
in
version
with Not_found -> defaultVersion

let newBsPackage ~rootPath =
let rescriptJson = Filename.concat rootPath "rescript.json" in
let bsconfigJson = Filename.concat rootPath "bsconfig.json" in
Expand All @@ -27,9 +43,12 @@ let newBsPackage ~rootPath =
| Some libBs ->
Some
(let namespace = FindFiles.getNamespace config in
let rescriptVersion = getReScriptVersion () in
let uncurried =
let ns = config |> Json.get "uncurried" in
Option.bind ns Json.bool
match (rescriptVersion, ns) with
| (major, _), None when major >= 11 -> Some true
| _, ns -> Option.bind ns Json.bool
in
let uncurried = uncurried = Some true in
let sourceDirectories =
Expand Down Expand Up @@ -93,6 +112,7 @@ let newBsPackage ~rootPath =
("Opens from ReScript config file: "
^ (opens |> List.map pathToString |> String.concat " "));
{
rescriptVersion;
rootPath;
projectFiles =
projectFilesAndPaths |> List.map fst |> FileSet.of_list;
Expand Down
1 change: 1 addition & 0 deletions analysis/src/SharedTypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ type package = {
builtInCompletionModules: builtInCompletionModules;
opens: path list;
uncurried: bool;
rescriptVersion: int * int;
}

let allFilesInPackage package =
Expand Down
28 changes: 28 additions & 0 deletions server/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,29 @@ export let formatCode = (
}
};

let findReScriptVersion = (filePath: p.DocumentUri): string | undefined => {
let projectRoot = findProjectRootOfFile(filePath);
if (projectRoot == null) {
return undefined;
}

let rescriptBinary = lookup.findFilePathFromProjectRoot(
projectRoot,
path.join(c.nodeModulesBinDir, c.rescriptBinName)
);

if (rescriptBinary == null) {
return undefined;
}

try {
let version = childProcess.execSync(`${rescriptBinary} -v`);
return version.toString().trim();
} catch (e) {
return undefined;
}
};

export let runAnalysisAfterSanityCheck = (
filePath: p.DocumentUri,
args: Array<any>,
Expand All @@ -154,9 +177,14 @@ export let runAnalysisAfterSanityCheck = (
if (projectRootPath == null && projectRequired) {
return null;
}
let rescriptVersion = findReScriptVersion(filePath);
let options: childProcess.ExecFileSyncOptions = {
cwd: projectRootPath || undefined,
maxBuffer: Infinity,
env: {
...process.env,
RESCRIPT_VERSION: rescriptVersion,
},
};
let stdout = childProcess.execFileSync(binaryPath, args, options);

Expand Down