Skip to content

Commit bf1084e

Browse files
committed
Use reanalyze embedded inside the editor binary.
1 parent 3b859f5 commit bf1084e

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

client/src/commands/code_analysis.ts

+33-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as cp from "child_process";
2+
import * as fs from "fs";
23
import * as path from "path";
34
import {
45
window,
@@ -11,7 +12,6 @@ import {
1112
CodeAction,
1213
CodeActionKind,
1314
WorkspaceEdit,
14-
DiagnosticTag,
1515
} from "vscode";
1616

1717
export type DiagnosticsResultCodeActionsMap = Map<
@@ -126,6 +126,30 @@ let resultsToDiagnostics = (
126126
};
127127
};
128128

129+
let analysisDevPath = path.join(
130+
path.dirname(__dirname),
131+
"..",
132+
"..",
133+
"analysis",
134+
"rescript-editor-analysis.exe"
135+
);
136+
let analysisProdPath = path.join(
137+
path.dirname(__dirname),
138+
"analysis_binaries",
139+
process.platform,
140+
"rescript-editor-analysis.exe"
141+
);
142+
143+
let getBinaryPath = () : string | null => {
144+
if (fs.existsSync(analysisDevPath)) {
145+
return analysisDevPath;
146+
} else if (fs.existsSync(analysisProdPath)) {
147+
return analysisProdPath;
148+
} else {
149+
return null;
150+
}
151+
};
152+
129153
export const runCodeAnalysisWithReanalyze = (
130154
targetDir: string | null,
131155
diagnosticsCollection: DiagnosticCollection,
@@ -134,7 +158,13 @@ export const runCodeAnalysisWithReanalyze = (
134158
let currentDocument = window.activeTextEditor.document;
135159
let cwd = targetDir ?? path.dirname(currentDocument.uri.fsPath);
136160

137-
let p = cp.spawn("npx", ["reanalyze@2.22.0", "-json"], {
161+
let binaryPath = getBinaryPath();
162+
if (binaryPath === null) {
163+
window.showErrorMessage("Binary executable not found.", analysisDevPath);
164+
return;
165+
}
166+
167+
let p = cp.spawn(analysisDevPath, ["reanalyze", "-json"], {
138168
cwd,
139169
});
140170

@@ -167,6 +197,7 @@ export const runCodeAnalysisWithReanalyze = (
167197

168198
p.on("close", () => {
169199
diagnosticsResultCodeActions.clear();
200+
170201
try {
171202
var json = JSON.parse(data);
172203
} catch (e) {

0 commit comments

Comments
 (0)