Skip to content

Commit c4c1f65

Browse files
committed
Use findReScriptVersionForProjectRoot
1 parent 481a8d2 commit c4c1f65

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

Diff for: server/src/server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ let openedFile = (fileUri: string, fileContent: string) => {
268268
filesDiagnostics: {},
269269
namespaceName:
270270
namespaceName.kind === "success" ? namespaceName.result : null,
271-
rescriptVersion: utils.findReScriptVersion(projectRootPath),
271+
rescriptVersion: utils.findReScriptVersionForProjectRoot(projectRootPath),
272272
bsbWatcherByEditor: null,
273273
bscBinaryLocation: utils.findBscExeBinary(projectRootPath),
274274
editorAnalysisLocation: utils.findEditorAnalysisBinary(projectRootPath),

Diff for: server/src/utils.ts

+19-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ export let findProjectRootOfFile = (
6767
if (foundRootFromProjectFiles != null) {
6868
return foundRootFromProjectFiles;
6969
} else {
70-
const dirStat = fs.statSync(source);
71-
const isDir = dirStat.isDirectory();
70+
const isDir = path.extname(source) === "";
7271
return findProjectRootOfFileInDir(
7372
isDir && !allowDir ? path.join(source, "dummy.res") : source
7473
);
@@ -166,6 +165,24 @@ export let findReScriptVersion = (
166165
}
167166
};
168167

168+
export function findReScriptVersionForProjectRoot(projectRootPath:string) : string | undefined {
169+
let rescriptBinary = lookup.findFilePathFromProjectRoot(
170+
projectRootPath,
171+
path.join(c.nodeModulesBinDir, c.rescriptBinName)
172+
);
173+
174+
if (rescriptBinary == null) {
175+
return undefined;
176+
}
177+
178+
try {
179+
let version = childProcess.execSync(`${rescriptBinary} -v`);
180+
return version.toString().trim();
181+
} catch (e) {
182+
return undefined;
183+
}
184+
}
185+
169186
// This is the path for the _builtin_ legacy analysis, that works for versions 11 and below.
170187
let builtinBinaryPath: string | null = null;
171188
if (fs.existsSync(c.builtinAnalysisDevPath)) {

0 commit comments

Comments
 (0)