Skip to content

Commit 3b57c41

Browse files
committed
run analysis from compiler package if high enough version
1 parent 2837e08 commit 3b57c41

File tree

4 files changed

+50
-14
lines changed

4 files changed

+50
-14
lines changed

server/src/constants.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,22 @@ export let jsonrpcVersion = "2.0";
1010
export let platformPath = path.join("rescript", platformDir);
1111
export let nodeModulesPlatformPath = path.join("node_modules", platformPath);
1212
export let bscExeName = "bsc.exe";
13+
export let editorAnalysisName = "rescript-editor-analysis.exe";
1314
export let bscNativeReScriptPartialPath = path.join(
1415
nodeModulesPlatformPath,
1516
bscExeName
1617
);
1718

18-
export let analysisDevPath = path.join(
19+
export let builtinAnalysisDevPath = path.join(
1920
path.dirname(__dirname),
2021
"..",
21-
"rescript-editor-analysis.exe"
22+
editorAnalysisName
2223
);
23-
export let analysisProdPath = path.join(
24+
export let builtinAnalysisProdPath = path.join(
2425
path.dirname(__dirname),
2526
"analysis_binaries",
2627
platformDir,
27-
"rescript-editor-analysis.exe"
28+
editorAnalysisName
2829
);
2930

3031
export let rescriptBinName = "rescript";

server/src/projectFiles.ts

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface projectFiles {
1111
filesDiagnostics: filesDiagnostics;
1212
rescriptVersion: string | undefined;
1313
bscBinaryLocation: string | null;
14+
editorAnalysisLocation: string | null;
1415
namespaceName: string | null;
1516

1617
bsbWatcherByEditor: null | cp.ChildProcess;

server/src/server.ts

+1
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ let openedFile = (fileUri: string, fileContent: string) => {
272272
rescriptVersion: utils.findReScriptVersion(projectRootPath),
273273
bsbWatcherByEditor: null,
274274
bscBinaryLocation: utils.findBscExeBinary(projectRootPath),
275+
editorAnalysisLocation: utils.findEditorAnalysisBinary(projectRootPath),
275276
hasPromptedToStartBuild: /(\/|\\)node_modules(\/|\\)/.test(
276277
projectRootPath
277278
)

server/src/utils.ts

+43-10
Original file line numberDiff line numberDiff line change
@@ -192,23 +192,19 @@ export let findReScriptVersion = (
192192
}
193193
};
194194

195-
let binaryPath: string | null = null;
196-
if (fs.existsSync(c.analysisDevPath)) {
197-
binaryPath = c.analysisDevPath;
198-
} else if (fs.existsSync(c.analysisProdPath)) {
199-
binaryPath = c.analysisProdPath;
200-
} else {
195+
// This is the path for the _builtin_ legacy analysis, that works for versions 11 and below.
196+
let builtinBinaryPath: string | null = null;
197+
if (fs.existsSync(c.builtinAnalysisDevPath)) {
198+
builtinBinaryPath = c.builtinAnalysisDevPath;
199+
} else if (fs.existsSync(c.builtinAnalysisProdPath)) {
200+
builtinBinaryPath = c.builtinAnalysisProdPath;
201201
}
202202

203203
export let runAnalysisAfterSanityCheck = (
204204
filePath: p.DocumentUri,
205205
args: Array<any>,
206206
projectRequired = false
207207
) => {
208-
if (binaryPath == null) {
209-
return null;
210-
}
211-
212208
let projectRootPath = findProjectRootOfFile(filePath);
213209
if (projectRootPath == null && projectRequired) {
214210
return null;
@@ -217,6 +213,35 @@ export let runAnalysisAfterSanityCheck = (
217213
projectsFiles.get(projectRootPath ?? "")?.rescriptVersion ??
218214
findReScriptVersion(filePath);
219215

216+
let binaryPath = builtinBinaryPath;
217+
218+
let project = projectRootPath ? projectsFiles.get(projectRootPath) : null;
219+
220+
/**
221+
* All versions including 12.0.0-alpha.5 and above should use the analysis binary
222+
* that now ships with the compiler. Previous versions use the legacy one we ship
223+
* with the extension itself.
224+
*/
225+
let shouldUseBuiltinAnalysis =
226+
rescriptVersion?.startsWith("9.") ||
227+
rescriptVersion?.startsWith("10.") ||
228+
rescriptVersion?.startsWith("11.") ||
229+
[
230+
"12.0.0-alpha.1",
231+
"12.0.0-alpha.2",
232+
"12.0.0-alpha.3",
233+
"12.0.0-alpha.4",
234+
].includes(rescriptVersion ?? "");
235+
236+
if (!shouldUseBuiltinAnalysis && project != null) {
237+
binaryPath = project.editorAnalysisLocation;
238+
} else if (!shouldUseBuiltinAnalysis && project == null) {
239+
// TODO: Warn user about broken state?
240+
return null;
241+
} else {
242+
binaryPath = builtinBinaryPath;
243+
}
244+
220245
let options: childProcess.ExecFileSyncOptions = {
221246
cwd: projectRootPath || undefined,
222247
maxBuffer: Infinity,
@@ -233,6 +258,11 @@ export let runAnalysisAfterSanityCheck = (
233258
: undefined,
234259
},
235260
};
261+
262+
if (binaryPath == null) {
263+
return null;
264+
}
265+
236266
let stdout = "";
237267
try {
238268
stdout = childProcess.execFileSync(binaryPath, args, options).toString();
@@ -737,3 +767,6 @@ let findPlatformPath = (projectRootPath: p.DocumentUri | null) => {
737767

738768
export let findBscExeBinary = (projectRootPath: p.DocumentUri | null) =>
739769
findBinary(findPlatformPath(projectRootPath), c.bscExeName);
770+
771+
export let findEditorAnalysisBinary = (projectRootPath: p.DocumentUri | null) =>
772+
findBinary(findPlatformPath(projectRootPath), c.editorAnalysisName);

0 commit comments

Comments
 (0)