@@ -484,8 +484,16 @@ namespace ts.server {
484484
485485 const updatedProjects : Project [ ] = [ ] ;
486486 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 :
489497 ! project . projectRootPath || ! this . compilerOptionsForInferredProjectsPerProjectRoot . has ( project . projectRootPath ) ) {
490498 project . setCompilerOptions ( compilerOptions ) ;
491499 project . compileOnSaveEnabled = compilerOptions . compileOnSave ;
@@ -1320,7 +1328,7 @@ namespace ts.server {
13201328 return this . createInferredProject ( /*isSingleInferredProject*/ false , projectRootPath ) ;
13211329 }
13221330
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
13241332 // that more closely contains the file.
13251333 let bestMatch : InferredProject ;
13261334 for ( const project of this . inferredProjects ) {
@@ -1342,11 +1350,11 @@ namespace ts.server {
13421350 return undefined ;
13431351 }
13441352
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
13471355 // then we want to put all files that are not opened with a `projectRootPath` into
13481356 // the same inferred project.
1349- //
1357+ //
13501358 // To avoid the cost of searching through the array and to optimize for the case where
13511359 // `useInferredProjectPerProjectRoot` is not enabled, we will always put the inferred
13521360 // project for non-rooted files at the front of the array.
0 commit comments