@@ -192,23 +192,19 @@ export let findReScriptVersion = (
192
192
}
193
193
} ;
194
194
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 ;
201
201
}
202
202
203
203
export let runAnalysisAfterSanityCheck = (
204
204
filePath : p . DocumentUri ,
205
205
args : Array < any > ,
206
206
projectRequired = false
207
207
) => {
208
- if ( binaryPath == null ) {
209
- return null ;
210
- }
211
-
212
208
let projectRootPath = findProjectRootOfFile ( filePath ) ;
213
209
if ( projectRootPath == null && projectRequired ) {
214
210
return null ;
@@ -217,6 +213,35 @@ export let runAnalysisAfterSanityCheck = (
217
213
projectsFiles . get ( projectRootPath ?? "" ) ?. rescriptVersion ??
218
214
findReScriptVersion ( filePath ) ;
219
215
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
+
220
245
let options : childProcess . ExecFileSyncOptions = {
221
246
cwd : projectRootPath || undefined ,
222
247
maxBuffer : Infinity ,
@@ -233,6 +258,11 @@ export let runAnalysisAfterSanityCheck = (
233
258
: undefined ,
234
259
} ,
235
260
} ;
261
+
262
+ if ( binaryPath == null ) {
263
+ return null ;
264
+ }
265
+
236
266
let stdout = "" ;
237
267
try {
238
268
stdout = childProcess . execFileSync ( binaryPath , args , options ) . toString ( ) ;
@@ -737,3 +767,6 @@ let findPlatformPath = (projectRootPath: p.DocumentUri | null) => {
737
767
738
768
export let findBscExeBinary = ( projectRootPath : p . DocumentUri | null ) =>
739
769
findBinary ( findPlatformPath ( projectRootPath ) , c . bscExeName ) ;
770
+
771
+ export let findEditorAnalysisBinary = ( projectRootPath : p . DocumentUri | null ) =>
772
+ findBinary ( findPlatformPath ( projectRootPath ) , c . editorAnalysisName ) ;
0 commit comments