@@ -484,8 +484,16 @@ namespace ts.server {
484
484
485
485
const updatedProjects : Project [ ] = [ ] ;
486
486
for ( const project of this . inferredProjects ) {
487
- if ( projectRootPath ?
488
- project . projectRootPath === projectRootPath :
487
+ // Only update compiler options in the following cases:
488
+ // - Inferred projects without a projectRootPath, if the new options do not apply to
489
+ // a workspace root
490
+ // - Inferred projects with a projectRootPath, if the new options do not apply to a
491
+ // workspace root and there is no more specific set of options for that project's
492
+ // root path
493
+ // - Inferred projects with a projectRootPath, if the new options apply to that
494
+ // project root path.
495
+ if ( projectRootPath ?
496
+ project . projectRootPath === projectRootPath :
489
497
! project . projectRootPath || ! this . compilerOptionsForInferredProjectsPerProjectRoot . has ( project . projectRootPath ) ) {
490
498
project . setCompilerOptions ( compilerOptions ) ;
491
499
project . compileOnSaveEnabled = compilerOptions . compileOnSave ;
@@ -1320,7 +1328,7 @@ namespace ts.server {
1320
1328
return this . createInferredProject ( /*isSingleInferredProject*/ false , projectRootPath ) ;
1321
1329
}
1322
1330
1323
- // we don't have an explicit root path, so we should try to find an inferred project
1331
+ // we don't have an explicit root path, so we should try to find an inferred project
1324
1332
// that more closely contains the file.
1325
1333
let bestMatch : InferredProject ;
1326
1334
for ( const project of this . inferredProjects ) {
@@ -1342,11 +1350,11 @@ namespace ts.server {
1342
1350
return undefined ;
1343
1351
}
1344
1352
1345
- // If `useInferredProjectPerProjectRoot` is not enabled, then there will only be one
1346
- // inferred project for all files. If `useInferredProjectPerProjectRoot` is enabled
1353
+ // If `useInferredProjectPerProjectRoot` is not enabled, then there will only be one
1354
+ // inferred project for all files. If `useInferredProjectPerProjectRoot` is enabled
1347
1355
// then we want to put all files that are not opened with a `projectRootPath` into
1348
1356
// the same inferred project.
1349
- //
1357
+ //
1350
1358
// To avoid the cost of searching through the array and to optimize for the case where
1351
1359
// `useInferredProjectPerProjectRoot` is not enabled, we will always put the inferred
1352
1360
// project for non-rooted files at the front of the array.
0 commit comments