@@ -362,6 +362,12 @@ namespace ts.server {
362
362
RootOfInferredProjectFalse = "Open file was set as not inferred root" ,
363
363
}
364
364
365
+ const enum ConfigFileActionResult {
366
+ Continue ,
367
+ Return ,
368
+ Break ,
369
+ }
370
+
365
371
/*@internal */
366
372
interface ConfigFileExistenceInfo {
367
373
/**
@@ -1637,7 +1643,7 @@ namespace ts.server {
1637
1643
* The server must start searching from the directory containing
1638
1644
* the newly opened file.
1639
1645
*/
1640
- private forEachConfigFileLocation ( info : OpenScriptInfoOrClosedOrConfigFileInfo , action : ( configFileName : NormalizedPath , canonicalConfigFilePath : string ) => boolean | void ) {
1646
+ private forEachConfigFileLocation ( info : OpenScriptInfoOrClosedOrConfigFileInfo , action : ( configFileName : NormalizedPath , canonicalConfigFilePath : string ) => ConfigFileActionResult | void ) {
1641
1647
if ( this . syntaxOnly ) {
1642
1648
return undefined ;
1643
1649
}
@@ -1658,12 +1664,23 @@ namespace ts.server {
1658
1664
if ( searchInDirectory ) {
1659
1665
const canonicalSearchPath = normalizedPathToPath ( searchPath , this . currentDirectory , this . toCanonicalFileName ) ;
1660
1666
const tsconfigFileName = asNormalizedPath ( combinePaths ( searchPath , "tsconfig.json" ) ) ;
1661
- let result = action ( tsconfigFileName , combinePaths ( canonicalSearchPath , "tsconfig.json" ) ) ;
1662
- if ( result ) return tsconfigFileName ;
1667
+ const tsResult = action ( tsconfigFileName , combinePaths ( canonicalSearchPath , "tsconfig.json" ) ) ;
1668
+ if ( tsResult === ConfigFileActionResult . Return ) {
1669
+ return tsconfigFileName ;
1670
+ }
1663
1671
1664
1672
const jsconfigFileName = asNormalizedPath ( combinePaths ( searchPath , "jsconfig.json" ) ) ;
1665
- result = action ( jsconfigFileName , combinePaths ( canonicalSearchPath , "jsconfig.json" ) ) ;
1666
- if ( result ) return jsconfigFileName ;
1673
+ const jsResult = action ( jsconfigFileName , combinePaths ( canonicalSearchPath , "jsconfig.json" ) ) ;
1674
+ if ( jsResult === ConfigFileActionResult . Return ) {
1675
+ return jsconfigFileName ;
1676
+ }
1677
+
1678
+ if ( tsResult === ConfigFileActionResult . Break || jsResult === ConfigFileActionResult . Break ) {
1679
+ break ;
1680
+ }
1681
+
1682
+ Debug . assert ( ! tsResult ) ;
1683
+ Debug . assert ( ! jsResult ) ;
1667
1684
}
1668
1685
1669
1686
const parentPath = asNormalizedPath ( getDirectoryPath ( searchPath ) ) ;
@@ -1678,7 +1695,7 @@ namespace ts.server {
1678
1695
/*@internal */
1679
1696
findDefaultConfiguredProject ( info : ScriptInfo ) {
1680
1697
if ( ! info . isScriptOpen ( ) ) return undefined ;
1681
- const configFileName = this . getConfigFileNameForFile ( info ) ;
1698
+ const configFileName = this . getConfigFileNameForFile ( info , /*stopAtNodeModules*/ false ) ;
1682
1699
return configFileName &&
1683
1700
this . findConfiguredProjectByProjectName ( configFileName ) ;
1684
1701
}
@@ -1693,11 +1710,15 @@ namespace ts.server {
1693
1710
* If script info is passed in, it is asserted to be open script info
1694
1711
* otherwise just file name
1695
1712
*/
1696
- private getConfigFileNameForFile ( info : OpenScriptInfoOrClosedOrConfigFileInfo ) {
1713
+ private getConfigFileNameForFile ( info : OpenScriptInfoOrClosedOrConfigFileInfo , stopAtNodeModules : boolean ) {
1697
1714
if ( isOpenScriptInfo ( info ) ) Debug . assert ( info . isScriptOpen ( ) ) ;
1698
1715
this . logger . info ( `Search path: ${ getDirectoryPath ( info . fileName ) } ` ) ;
1699
1716
const configFileName = this . forEachConfigFileLocation ( info , ( configFileName , canonicalConfigFilePath ) =>
1700
- this . configFileExists ( configFileName , canonicalConfigFilePath , info ) ) ;
1717
+ this . configFileExists ( configFileName , canonicalConfigFilePath , info )
1718
+ ? ConfigFileActionResult . Return
1719
+ : stopAtNodeModules && isNodeModulesDirectory ( getDirectoryPath ( canonicalConfigFilePath ) as Path )
1720
+ ? ConfigFileActionResult . Break
1721
+ : ConfigFileActionResult . Continue ) ;
1701
1722
if ( configFileName ) {
1702
1723
this . logger . info ( `For info: ${ info . fileName } :: Config file name: ${ configFileName } ` ) ;
1703
1724
}
@@ -2706,7 +2727,7 @@ namespace ts.server {
2706
2727
// we first detect if there is already a configured project created for it: if so,
2707
2728
// we re- read the tsconfig file content and update the project only if we havent already done so
2708
2729
// otherwise we create a new one.
2709
- const configFileName = this . getConfigFileNameForFile ( info ) ;
2730
+ const configFileName = this . getConfigFileNameForFile ( info , /*stopAtNodeModules*/ true ) ;
2710
2731
if ( configFileName ) {
2711
2732
const project = this . findConfiguredProjectByProjectName ( configFileName ) || this . createConfiguredProject ( configFileName ) ;
2712
2733
if ( ! updatedProjects . has ( configFileName ) ) {
@@ -2803,7 +2824,7 @@ namespace ts.server {
2803
2824
if ( ! this . getScriptInfo ( fileName ) && ! this . host . fileExists ( fileName ) ) return undefined ;
2804
2825
2805
2826
const originalFileInfo : OriginalFileInfo = { fileName : toNormalizedPath ( fileName ) , path : this . toPath ( fileName ) } ;
2806
- const configFileName = this . getConfigFileNameForFile ( originalFileInfo ) ;
2827
+ const configFileName = this . getConfigFileNameForFile ( originalFileInfo , /*stopAtNodeModules*/ false ) ;
2807
2828
if ( ! configFileName ) return undefined ;
2808
2829
2809
2830
const configuredProject = this . findConfiguredProjectByProjectName ( configFileName ) ||
@@ -2857,7 +2878,7 @@ namespace ts.server {
2857
2878
let project : ConfiguredProject | ExternalProject | undefined = this . findExternalProjectContainingOpenScriptInfo ( info ) ;
2858
2879
let defaultConfigProject : ConfiguredProject | undefined ;
2859
2880
if ( ! project && ! this . syntaxOnly ) { // Checking syntaxOnly is an optimization
2860
- configFileName = this . getConfigFileNameForFile ( info ) ;
2881
+ configFileName = this . getConfigFileNameForFile ( info , /*stopAtNodeModules*/ true ) ;
2861
2882
if ( configFileName ) {
2862
2883
project = this . findConfiguredProjectByProjectName ( configFileName ) ;
2863
2884
if ( ! project ) {
@@ -2920,7 +2941,7 @@ namespace ts.server {
2920
2941
fileName : project . getConfigFilePath ( ) ,
2921
2942
path : info . path ,
2922
2943
configFileInfo : true
2923
- } ) ;
2944
+ } , /*stopAtNodeModules*/ true ) ;
2924
2945
if ( ! configFileName ) return ;
2925
2946
2926
2947
// find or delay load the project
0 commit comments