@@ -254,6 +254,7 @@ namespace ts.server {
254
254
255
255
private compilerOptionsForInferredProjects : CompilerOptions ;
256
256
private compileOnSaveForInferredProjects : boolean ;
257
+ private readonly projectToSizeMap : Map < number > = createMap < number > ( ) ;
257
258
private readonly directoryWatchers : DirectoryWatchers ;
258
259
private readonly throttledOperations : ThrottledOperations ;
259
260
@@ -563,9 +564,11 @@ namespace ts.server {
563
564
switch ( project . projectKind ) {
564
565
case ProjectKind . External :
565
566
removeItemFromSet ( this . externalProjects , < ExternalProject > project ) ;
567
+ this . projectToSizeMap . delete ( ( project as ExternalProject ) . externalProjectName ) ;
566
568
break ;
567
569
case ProjectKind . Configured :
568
570
removeItemFromSet ( this . configuredProjects , < ConfiguredProject > project ) ;
571
+ this . projectToSizeMap . delete ( ( project as ConfiguredProject ) . canonicalConfigFilePath ) ;
569
572
break ;
570
573
case ProjectKind . Inferred :
571
574
removeItemFromSet ( this . inferredProjects , < InferredProject > project ) ;
@@ -852,10 +855,15 @@ namespace ts.server {
852
855
return { success : true , projectOptions, configFileErrors : errors } ;
853
856
}
854
857
855
- private exceededTotalSizeLimitForNonTsFiles < T > ( options : CompilerOptions , fileNames : T [ ] , propertyReader : FilePropertyReader < T > ) {
858
+ private exceededTotalSizeLimitForNonTsFiles < T > ( name : string , options : CompilerOptions , fileNames : T [ ] , propertyReader : FilePropertyReader < T > ) {
856
859
if ( options && options . disableSizeLimit || ! this . host . getFileSize ) {
857
860
return false ;
858
861
}
862
+
863
+ let availableSpace = maxProgramSizeForNonTsFiles ;
864
+ this . projectToSizeMap . set ( name , 0 ) ;
865
+ this . projectToSizeMap . forEach ( val => ( availableSpace -= ( val || 0 ) ) ) ;
866
+
859
867
let totalNonTsFileSize = 0 ;
860
868
for ( const f of fileNames ) {
861
869
const fileName = propertyReader . getFileName ( f ) ;
@@ -864,9 +872,16 @@ namespace ts.server {
864
872
}
865
873
totalNonTsFileSize += this . host . getFileSize ( fileName ) ;
866
874
if ( totalNonTsFileSize > maxProgramSizeForNonTsFiles ) {
875
+ // Keep the size as zero since it's disabled
867
876
return true ;
868
877
}
869
878
}
879
+
880
+ if ( totalNonTsFileSize > availableSpace ) {
881
+ return true ;
882
+ }
883
+
884
+ this . projectToSizeMap . set ( name , totalNonTsFileSize ) ;
870
885
return false ;
871
886
}
872
887
@@ -877,7 +892,7 @@ namespace ts.server {
877
892
this ,
878
893
this . documentRegistry ,
879
894
compilerOptions ,
880
- /*languageServiceEnabled*/ ! this . exceededTotalSizeLimitForNonTsFiles ( compilerOptions , files , externalFilePropertyReader ) ,
895
+ /*languageServiceEnabled*/ ! this . exceededTotalSizeLimitForNonTsFiles ( projectFileName , compilerOptions , files , externalFilePropertyReader ) ,
881
896
options . compileOnSave === undefined ? true : options . compileOnSave ) ;
882
897
883
898
this . addFilesToProjectAndUpdateGraph ( project , files , externalFilePropertyReader , /*clientFileName*/ undefined , typeAcquisition , /*configFileErrors*/ undefined ) ;
@@ -897,7 +912,7 @@ namespace ts.server {
897
912
}
898
913
899
914
private createAndAddConfiguredProject ( configFileName : NormalizedPath , projectOptions : ProjectOptions , configFileErrors : Diagnostic [ ] , clientFileName ?: string ) {
900
- const sizeLimitExceeded = this . exceededTotalSizeLimitForNonTsFiles ( projectOptions . compilerOptions , projectOptions . files , fileNamePropertyReader ) ;
915
+ const sizeLimitExceeded = this . exceededTotalSizeLimitForNonTsFiles ( configFileName , projectOptions . compilerOptions , projectOptions . files , fileNamePropertyReader ) ;
901
916
const project = new ConfiguredProject (
902
917
configFileName ,
903
918
this ,
@@ -1050,7 +1065,7 @@ namespace ts.server {
1050
1065
return configFileErrors ;
1051
1066
}
1052
1067
1053
- if ( this . exceededTotalSizeLimitForNonTsFiles ( projectOptions . compilerOptions , projectOptions . files , fileNamePropertyReader ) ) {
1068
+ if ( this . exceededTotalSizeLimitForNonTsFiles ( project . canonicalConfigFilePath , projectOptions . compilerOptions , projectOptions . files , fileNamePropertyReader ) ) {
1054
1069
project . setCompilerOptions ( projectOptions . compilerOptions ) ;
1055
1070
if ( ! project . languageServiceEnabled ) {
1056
1071
// language service is already disabled
@@ -1414,7 +1429,7 @@ namespace ts.server {
1414
1429
if ( externalProject ) {
1415
1430
if ( ! tsConfigFiles ) {
1416
1431
const compilerOptions = convertCompilerOptions ( proj . options ) ;
1417
- if ( this . exceededTotalSizeLimitForNonTsFiles ( compilerOptions , proj . rootFiles , externalFilePropertyReader ) ) {
1432
+ if ( this . exceededTotalSizeLimitForNonTsFiles ( proj . projectFileName , compilerOptions , proj . rootFiles , externalFilePropertyReader ) ) {
1418
1433
externalProject . disableLanguageService ( ) ;
1419
1434
}
1420
1435
else {
0 commit comments