1
1
import * as cp from "child_process" ;
2
+ import * as fs from "fs" ;
2
3
import * as path from "path" ;
3
4
import {
4
5
window ,
@@ -11,7 +12,6 @@ import {
11
12
CodeAction ,
12
13
CodeActionKind ,
13
14
WorkspaceEdit ,
14
- DiagnosticTag ,
15
15
} from "vscode" ;
16
16
17
17
export type DiagnosticsResultCodeActionsMap = Map <
@@ -126,6 +126,30 @@ let resultsToDiagnostics = (
126
126
} ;
127
127
} ;
128
128
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
+
129
153
export const runCodeAnalysisWithReanalyze = (
130
154
targetDir : string | null ,
131
155
diagnosticsCollection : DiagnosticCollection ,
@@ -134,7 +158,13 @@ export const runCodeAnalysisWithReanalyze = (
134
158
let currentDocument = window . activeTextEditor . document ;
135
159
let cwd = targetDir ?? path . dirname ( currentDocument . uri . fsPath ) ;
136
160
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" ] , {
138
168
cwd,
139
169
} ) ;
140
170
@@ -167,6 +197,7 @@ export const runCodeAnalysisWithReanalyze = (
167
197
168
198
p . on ( "close" , ( ) => {
169
199
diagnosticsResultCodeActions . clear ( ) ;
200
+
170
201
try {
171
202
var json = JSON . parse ( data ) ;
172
203
} catch ( e ) {
0 commit comments