@@ -467,27 +467,28 @@ namespace ts.server {
467
467
}
468
468
469
469
setCompilerOptionsForInferredProjects ( projectCompilerOptions : protocol . ExternalProjectCompilerOptions , projectRootPath ?: string ) : void {
470
- // ignore this settings if we are not creating inferred projects per project root.
471
- if ( projectRootPath && ! this . useInferredProjectPerProjectRoot ) return ;
470
+ Debug . assert ( projectRootPath === undefined || this . useInferredProjectPerProjectRoot , "Setting compiler options per project root path is only supported when useInferredProjectPerProjectRoot is enabled" ) ;
472
471
473
- const compilerOptionsForInferredProjects = convertCompilerOptions ( projectCompilerOptions ) ;
472
+ const compilerOptions = convertCompilerOptions ( projectCompilerOptions ) ;
474
473
475
474
// always set 'allowNonTsExtensions' for inferred projects since user cannot configure it from the outside
476
475
// previously we did not expose a way for user to change these settings and this option was enabled by default
477
- compilerOptionsForInferredProjects . allowNonTsExtensions = true ;
476
+ compilerOptions . allowNonTsExtensions = true ;
478
477
479
478
if ( projectRootPath ) {
480
- this . compilerOptionsForInferredProjectsPerProjectRoot . set ( projectRootPath , compilerOptionsForInferredProjects ) ;
479
+ this . compilerOptionsForInferredProjectsPerProjectRoot . set ( projectRootPath , compilerOptions ) ;
481
480
}
482
481
else {
483
- this . compilerOptionsForInferredProjects = compilerOptionsForInferredProjects ;
482
+ this . compilerOptionsForInferredProjects = compilerOptions ;
484
483
}
485
484
486
485
const updatedProjects : Project [ ] = [ ] ;
487
486
for ( const project of this . inferredProjects ) {
488
- if ( project . projectRootPath === projectRootPath || ( project . projectRootPath && ! this . compilerOptionsForInferredProjectsPerProjectRoot . has ( project . projectRootPath ) ) ) {
489
- project . setCompilerOptions ( compilerOptionsForInferredProjects ) ;
490
- project . compileOnSaveEnabled = compilerOptionsForInferredProjects . compileOnSave ;
487
+ if ( projectRootPath ?
488
+ project . projectRootPath === projectRootPath :
489
+ ! project . projectRootPath || ! this . compilerOptionsForInferredProjectsPerProjectRoot . has ( project . projectRootPath ) ) {
490
+ project . setCompilerOptions ( compilerOptions ) ;
491
+ project . compileOnSaveEnabled = compilerOptions . compileOnSave ;
491
492
updatedProjects . push ( project ) ;
492
493
}
493
494
}
@@ -1319,7 +1320,8 @@ namespace ts.server {
1319
1320
return this . createInferredProject ( /*isSingleInferredProject*/ false , projectRootPath ) ;
1320
1321
}
1321
1322
1322
- // we don't have an explicit root path, so we should try to find an inferred project that best matches the file.
1323
+ // we don't have an explicit root path, so we should try to find an inferred project
1324
+ // that more closely contains the file.
1323
1325
let bestMatch : InferredProject ;
1324
1326
for ( const project of this . inferredProjects ) {
1325
1327
// ignore single inferred projects (handled elsewhere)
@@ -1340,6 +1342,14 @@ namespace ts.server {
1340
1342
return undefined ;
1341
1343
}
1342
1344
1345
+ // If `useInferredProjectPerProjectRoot` is not enabled, then there will only be one
1346
+ // inferred project for all files. If `useInferredProjectPerProjectRoot` is enabled
1347
+ // then we want to put all files that are not opened with a `projectRootPath` into
1348
+ // the same inferred project.
1349
+ //
1350
+ // To avoid the cost of searching through the array and to optimize for the case where
1351
+ // `useInferredProjectPerProjectRoot` is not enabled, we will always put the inferred
1352
+ // project for non-rooted files at the front of the array.
1343
1353
if ( this . inferredProjects . length > 0 && this . inferredProjects [ 0 ] . projectRootPath === undefined ) {
1344
1354
return this . inferredProjects [ 0 ] ;
1345
1355
}
0 commit comments