@@ -1377,9 +1377,10 @@ namespace ts.server {
13771377 return { projectOptions, configFileErrors : errors , configFileSpecs : parsedCommandLine . configFileSpecs } ;
13781378 }
13791379
1380- private exceededTotalSizeLimitForNonTsFiles < T > ( name : string , options : CompilerOptions , fileNames : T [ ] , propertyReader : FilePropertyReader < T > ) {
1380+ /** Get a filename if the language service exceeds the maximum allowed program size; otherwise returns undefined. */
1381+ private getFilenameForExceededTotalSizeLimitForNonTsFiles < T > ( name : string , options : CompilerOptions , fileNames : T [ ] , propertyReader : FilePropertyReader < T > ) : string | undefined {
13811382 if ( options && options . disableSizeLimit || ! this . host . getFileSize ) {
1382- return false ;
1383+ return ;
13831384 }
13841385
13851386 let availableSpace = maxProgramSizeForNonTsFiles ;
@@ -1396,20 +1397,16 @@ namespace ts.server {
13961397
13971398 totalNonTsFileSize += this . host . getFileSize ( fileName ) ;
13981399
1399- if ( totalNonTsFileSize > maxProgramSizeForNonTsFiles ) {
1400+ if ( totalNonTsFileSize > maxProgramSizeForNonTsFiles || totalNonTsFileSize > availableSpace ) {
14001401 this . logger . info ( getExceedLimitMessage ( { propertyReader, hasTypeScriptFileExtension, host : this . host } , totalNonTsFileSize ) ) ;
14011402 // Keep the size as zero since it's disabled
1402- return true ;
1403+ return fileName ;
14031404 }
14041405 }
14051406
1406- if ( totalNonTsFileSize > availableSpace ) {
1407- this . logger . info ( getExceedLimitMessage ( { propertyReader, hasTypeScriptFileExtension, host : this . host } , totalNonTsFileSize ) ) ;
1408- return true ;
1409- }
1410-
14111407 this . projectToSizeMap . set ( name , totalNonTsFileSize ) ;
1412- return false ;
1408+
1409+ return ;
14131410
14141411 function getExceedLimitMessage ( context : { propertyReader : FilePropertyReader < any > , hasTypeScriptFileExtension : ( filename : string ) => boolean , host : ServerHost } , totalNonTsFileSize : number ) {
14151412 const files = getTop5LargestFiles ( context ) ;
@@ -1432,7 +1429,7 @@ namespace ts.server {
14321429 this ,
14331430 this . documentRegistry ,
14341431 compilerOptions ,
1435- /*languageServiceEnabled */ ! this . exceededTotalSizeLimitForNonTsFiles ( projectFileName , compilerOptions , files , externalFilePropertyReader ) ,
1432+ /*exceededFilename */ this . getFilenameForExceededTotalSizeLimitForNonTsFiles ( projectFileName , compilerOptions , files , externalFilePropertyReader ) ,
14361433 options . compileOnSave === undefined ? true : options . compileOnSave ) ;
14371434 project . excludedFiles = excludedFiles ;
14381435
@@ -1498,14 +1495,14 @@ namespace ts.server {
14981495 const cachedDirectoryStructureHost = createCachedDirectoryStructureHost ( this . host , this . host . getCurrentDirectory ( ) , this . host . useCaseSensitiveFileNames ) ;
14991496 const { projectOptions, configFileErrors, configFileSpecs } = this . convertConfigFileContentToProjectOptions ( configFileName , cachedDirectoryStructureHost ) ;
15001497 this . logger . info ( `Opened configuration file ${ configFileName } ` ) ;
1501- const languageServiceEnabled = ! this . exceededTotalSizeLimitForNonTsFiles ( configFileName , projectOptions . compilerOptions , projectOptions . files , fileNamePropertyReader ) ;
1498+ const exceededFilename = this . getFilenameForExceededTotalSizeLimitForNonTsFiles ( configFileName , projectOptions . compilerOptions , projectOptions . files , fileNamePropertyReader ) ;
15021499 const project = new ConfiguredProject (
15031500 configFileName ,
15041501 this ,
15051502 this . documentRegistry ,
15061503 projectOptions . configHasFilesProperty ,
15071504 projectOptions . compilerOptions ,
1508- languageServiceEnabled ,
1505+ exceededFilename ,
15091506 projectOptions . compileOnSave === undefined ? false : projectOptions . compileOnSave ,
15101507 cachedDirectoryStructureHost ) ;
15111508
@@ -1518,7 +1515,7 @@ namespace ts.server {
15181515 WatchType . ConfigFilePath ,
15191516 project
15201517 ) ;
1521- if ( languageServiceEnabled ) {
1518+ if ( ! exceededFilename ) {
15221519 project . watchWildcards ( projectOptions . wildcardDirectories ) ;
15231520 }
15241521
@@ -1631,8 +1628,9 @@ namespace ts.server {
16311628 // Update the project
16321629 project . configFileSpecs = configFileSpecs ;
16331630 project . setProjectErrors ( configFileErrors ) ;
1634- if ( this . exceededTotalSizeLimitForNonTsFiles ( project . canonicalConfigFilePath , projectOptions . compilerOptions , projectOptions . files , fileNamePropertyReader ) ) {
1635- project . disableLanguageService ( ) ;
1631+ const exceededFilename = this . getFilenameForExceededTotalSizeLimitForNonTsFiles ( project . canonicalConfigFilePath , projectOptions . compilerOptions , projectOptions . files , fileNamePropertyReader ) ;
1632+ if ( exceededFilename ) {
1633+ project . disableLanguageService ( exceededFilename ) ;
16361634 project . stopWatchingWildCards ( ) ;
16371635 }
16381636 else {
@@ -2396,8 +2394,9 @@ namespace ts.server {
23962394 externalProject . excludedFiles = excludedFiles ;
23972395 if ( ! tsConfigFiles ) {
23982396 const compilerOptions = convertCompilerOptions ( proj . options ) ;
2399- if ( this . exceededTotalSizeLimitForNonTsFiles ( proj . projectFileName , compilerOptions , proj . rootFiles , externalFilePropertyReader ) ) {
2400- externalProject . disableLanguageService ( ) ;
2397+ const exceededFilename = this . getFilenameForExceededTotalSizeLimitForNonTsFiles ( proj . projectFileName , compilerOptions , proj . rootFiles , externalFilePropertyReader ) ;
2398+ if ( exceededFilename ) {
2399+ externalProject . disableLanguageService ( exceededFilename ) ;
24012400 }
24022401 else {
24032402 externalProject . enableLanguageService ( ) ;
0 commit comments