@@ -10,6 +10,7 @@ import config, { send } from "./config";
10
10
import * as c from "./constants" ;
11
11
import * as chokidar from "chokidar" ;
12
12
import { fileCodeActions } from "./codeActions" ;
13
+ import { projectsFiles } from "./projectFiles" ;
13
14
14
15
function debug ( ) {
15
16
return (
@@ -75,8 +76,6 @@ type IncrementallyCompiledFileInfo = {
75
76
callArgs : Promise < Array < string > | null > ;
76
77
/** The location of the incremental folder for this project. */
77
78
incrementalFolderPath : string ;
78
- /** The ReScript version. */
79
- rescriptVersion : string ;
80
79
} ;
81
80
/** Any code actions for this incremental file. */
82
81
codeActions : Array < fileCodeActions > ;
@@ -284,6 +283,8 @@ function getBscArgs(
284
283
} ) ;
285
284
} else if ( buildSystem === "rewatch" ) {
286
285
try {
286
+ const project = projectsFiles . get ( entry . project . rootPath ) ;
287
+ if ( project ?. rescriptVersion == null ) return ;
287
288
let rewatchPath = path . resolve (
288
289
entry . project . workspaceRootPath ,
289
290
"node_modules/@rolandpeelen/rewatch/rewatch"
@@ -292,7 +293,7 @@ function getBscArgs(
292
293
cp
293
294
. execFileSync ( rewatchPath , [
294
295
"--rescript-version" ,
295
- entry . project . rescriptVersion ,
296
+ project . rescriptVersion ,
296
297
"--compiler-args" ,
297
298
entry . file . sourceFilePath ,
298
299
] )
@@ -364,21 +365,21 @@ function triggerIncrementalCompilationOfFile(
364
365
if ( incrementalFileCacheEntry == null ) {
365
366
// New file
366
367
const projectRootPath = utils . findProjectRootOfFile ( filePath ) ;
367
- const workspaceRootPath = projectRootPath
368
- ? utils . findProjectRootOfFile ( projectRootPath )
369
- : null ;
370
368
if ( projectRootPath == null ) {
371
369
if ( debug ( ) )
372
370
console . log ( "Did not find project root path for " + filePath ) ;
373
371
return ;
374
372
}
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 ) ;
379
376
return ;
380
377
}
381
- const bscBinaryLocation = utils . findBscExeBinary ( projectRootPath ) ;
378
+ const workspaceRootPath = projectRootPath
379
+ ? utils . findProjectRootOfFile ( projectRootPath )
380
+ : null ;
381
+
382
+ const bscBinaryLocation = project . bscBinaryLocation ;
382
383
if ( bscBinaryLocation == null ) {
383
384
if ( debug ( ) )
384
385
console . log ( "Could not find bsc binary location for " + filePath ) ;
@@ -387,28 +388,15 @@ function triggerIncrementalCompilationOfFile(
387
388
const ext = filePath . endsWith ( ".resi" ) ? ".resi" : ".res" ;
388
389
const moduleName = path . basename ( filePath , ext ) ;
389
390
const moduleNameNamespaced =
390
- namespaceName . result !== ""
391
- ? `${ moduleName } -${ namespaceName . result } `
391
+ project . namespaceName != null
392
+ ? `${ moduleName } -${ project . namespaceName } `
392
393
: moduleName ;
393
394
394
395
const incrementalFolderPath = path . join (
395
396
projectRootPath ,
396
397
INCREMENTAL_FILE_FOLDER_LOCATION
397
398
) ;
398
399
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
-
412
400
let originalTypeFileLocation = path . resolve (
413
401
projectRootPath ,
414
402
"lib/bs" ,
@@ -436,7 +424,6 @@ function triggerIncrementalCompilationOfFile(
436
424
callArgs : Promise . resolve ( [ ] ) ,
437
425
bscBinaryLocation,
438
426
incrementalFolderPath,
439
- rescriptVersion,
440
427
} ,
441
428
buildRewatch : null ,
442
429
buildNinja : null ,
@@ -488,6 +475,16 @@ function verifyTriggerToken(filePath: string, triggerToken: number): boolean {
488
475
) ;
489
476
}
490
477
async 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
+ }
491
488
const res = await getBscArgs ( entry ) ;
492
489
if ( res == null ) return null ;
493
490
let astArgs : Array < Array < string > > = [ ] ;
@@ -547,7 +544,7 @@ async function figureOutBscArgs(entry: IncrementallyCompiledFileInfo) {
547
544
} ) ;
548
545
549
546
callArgs . push ( "-color" , "never" ) ;
550
- if ( parseInt ( entry . project . rescriptVersion . split ( "." ) [ 0 ] ?? "10" ) >= 11 ) {
547
+ if ( parseInt ( project . rescriptVersion . split ( "." ) [ 0 ] ?? "10" ) >= 11 ) {
551
548
// Only available in v11+
552
549
callArgs . push ( "-ignore-parse-errors" ) ;
553
550
}
0 commit comments