@@ -10,6 +10,7 @@ import config, { send } from "./config";
1010import * as c from "./constants" ;
1111import * as chokidar from "chokidar" ;
1212import { fileCodeActions } from "./codeActions" ;
13+ import { projectsFiles } from "./projectFiles" ;
1314
1415function debug ( ) {
1516 return (
@@ -75,8 +76,6 @@ type IncrementallyCompiledFileInfo = {
7576 callArgs : Promise < Array < string > | null > ;
7677 /** The location of the incremental folder for this project. */
7778 incrementalFolderPath : string ;
78- /** The ReScript version. */
79- rescriptVersion : string ;
8079 } ;
8180 /** Any code actions for this incremental file. */
8281 codeActions : Array < fileCodeActions > ;
@@ -284,6 +283,8 @@ function getBscArgs(
284283 } ) ;
285284 } else if ( buildSystem === "rewatch" ) {
286285 try {
286+ const project = projectsFiles . get ( entry . project . rootPath ) ;
287+ if ( project ?. rescriptVersion == null ) return ;
287288 let rewatchPath = path . resolve (
288289 entry . project . workspaceRootPath ,
289290 "node_modules/@rolandpeelen/rewatch/rewatch"
@@ -292,7 +293,7 @@ function getBscArgs(
292293 cp
293294 . execFileSync ( rewatchPath , [
294295 "--rescript-version" ,
295- entry . project . rescriptVersion ,
296+ project . rescriptVersion ,
296297 "--compiler-args" ,
297298 entry . file . sourceFilePath ,
298299 ] )
@@ -364,21 +365,21 @@ function triggerIncrementalCompilationOfFile(
364365 if ( incrementalFileCacheEntry == null ) {
365366 // New file
366367 const projectRootPath = utils . findProjectRootOfFile ( filePath ) ;
367- const workspaceRootPath = projectRootPath
368- ? utils . findProjectRootOfFile ( projectRootPath )
369- : null ;
370368 if ( projectRootPath == null ) {
371369 if ( debug ( ) )
372370 console . log ( "Did not find project root path for " + filePath ) ;
373371 return ;
374372 }
375- const namespaceName = utils . getNamespaceNameFromConfigFile ( projectRootPath ) ;
376- if ( namespaceName . kind === "error" ) {
377- if ( debug ( ) )
378- console . log ( "Getting namespace config errored for " + filePath ) ;
373+ const project = projectsFiles . get ( projectRootPath ) ;
374+ if ( project == null ) {
375+ if ( debug ( ) ) console . log ( "Did not find open project for " + filePath ) ;
379376 return ;
380377 }
381- const bscBinaryLocation = utils . findBscExeBinary ( projectRootPath ) ;
378+ const workspaceRootPath = projectRootPath
379+ ? utils . findProjectRootOfFile ( projectRootPath )
380+ : null ;
381+
382+ const bscBinaryLocation = project . bscBinaryLocation ;
382383 if ( bscBinaryLocation == null ) {
383384 if ( debug ( ) )
384385 console . log ( "Could not find bsc binary location for " + filePath ) ;
@@ -387,28 +388,15 @@ function triggerIncrementalCompilationOfFile(
387388 const ext = filePath . endsWith ( ".resi" ) ? ".resi" : ".res" ;
388389 const moduleName = path . basename ( filePath , ext ) ;
389390 const moduleNameNamespaced =
390- namespaceName . result !== ""
391- ? `${ moduleName } -${ namespaceName . result } `
391+ project . namespaceName != null
392+ ? `${ moduleName } -${ project . namespaceName } `
392393 : moduleName ;
393394
394395 const incrementalFolderPath = path . join (
395396 projectRootPath ,
396397 INCREMENTAL_FILE_FOLDER_LOCATION
397398 ) ;
398399
399- let rescriptVersion = "" ;
400- try {
401- rescriptVersion = cp
402- . execFileSync ( bscBinaryLocation , [ "-version" ] )
403- . toString ( )
404- . trim ( ) ;
405- } catch ( e ) {
406- console . error ( e ) ;
407- }
408- if ( rescriptVersion . startsWith ( "ReScript " ) ) {
409- rescriptVersion = rescriptVersion . replace ( "ReScript " , "" ) ;
410- }
411-
412400 let originalTypeFileLocation = path . resolve (
413401 projectRootPath ,
414402 "lib/bs" ,
@@ -436,7 +424,6 @@ function triggerIncrementalCompilationOfFile(
436424 callArgs : Promise . resolve ( [ ] ) ,
437425 bscBinaryLocation,
438426 incrementalFolderPath,
439- rescriptVersion,
440427 } ,
441428 buildRewatch : null ,
442429 buildNinja : null ,
@@ -488,6 +475,16 @@ function verifyTriggerToken(filePath: string, triggerToken: number): boolean {
488475 ) ;
489476}
490477async function figureOutBscArgs ( entry : IncrementallyCompiledFileInfo ) {
478+ const project = projectsFiles . get ( entry . project . rootPath ) ;
479+ if ( project ?. rescriptVersion == null ) {
480+ if ( debug ( ) ) {
481+ console . log (
482+ "Found no project (or ReScript version) for " +
483+ entry . file . sourceFilePath
484+ ) ;
485+ }
486+ return null ;
487+ }
491488 const res = await getBscArgs ( entry ) ;
492489 if ( res == null ) return null ;
493490 let astArgs : Array < Array < string > > = [ ] ;
@@ -547,7 +544,7 @@ async function figureOutBscArgs(entry: IncrementallyCompiledFileInfo) {
547544 } ) ;
548545
549546 callArgs . push ( "-color" , "never" ) ;
550- if ( parseInt ( entry . project . rescriptVersion . split ( "." ) [ 0 ] ?? "10" ) >= 11 ) {
547+ if ( parseInt ( project . rescriptVersion . split ( "." ) [ 0 ] ?? "10" ) >= 11 ) {
551548 // Only available in v11+
552549 callArgs . push ( "-ignore-parse-errors" ) ;
553550 }
0 commit comments