@@ -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
203203export 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
738768export 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