@@ -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,21 +855,31 @@ 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 ( size => {
866
+ availableSpace -= size ;
867
+ } ) ;
868
+
859
869
let totalNonTsFileSize = 0 ;
860
870
for ( const f of fileNames ) {
861
871
const fileName = propertyReader . getFileName ( f ) ;
862
872
if ( hasTypeScriptFileExtension ( fileName ) ) {
863
873
continue ;
864
874
}
865
875
totalNonTsFileSize += this . host . getFileSize ( fileName ) ;
866
- if ( totalNonTsFileSize > maxProgramSizeForNonTsFiles ) {
876
+ if ( totalNonTsFileSize > availableSpace ) {
877
+ this . projectToSizeMap . set ( name , totalNonTsFileSize ) ;
867
878
return true ;
868
879
}
869
880
}
881
+
882
+ this . projectToSizeMap . set ( name , totalNonTsFileSize ) ;
870
883
return false ;
871
884
}
872
885
@@ -877,7 +890,7 @@ namespace ts.server {
877
890
this ,
878
891
this . documentRegistry ,
879
892
compilerOptions ,
880
- /*languageServiceEnabled*/ ! this . exceededTotalSizeLimitForNonTsFiles ( compilerOptions , files , externalFilePropertyReader ) ,
893
+ /*languageServiceEnabled*/ ! this . exceededTotalSizeLimitForNonTsFiles ( projectFileName , compilerOptions , files , externalFilePropertyReader ) ,
881
894
options . compileOnSave === undefined ? true : options . compileOnSave ) ;
882
895
883
896
this . addFilesToProjectAndUpdateGraph ( project , files , externalFilePropertyReader , /*clientFileName*/ undefined , typeAcquisition , /*configFileErrors*/ undefined ) ;
@@ -897,7 +910,7 @@ namespace ts.server {
897
910
}
898
911
899
912
private createAndAddConfiguredProject ( configFileName : NormalizedPath , projectOptions : ProjectOptions , configFileErrors : Diagnostic [ ] , clientFileName ?: string ) {
900
- const sizeLimitExceeded = this . exceededTotalSizeLimitForNonTsFiles ( projectOptions . compilerOptions , projectOptions . files , fileNamePropertyReader ) ;
913
+ const sizeLimitExceeded = this . exceededTotalSizeLimitForNonTsFiles ( configFileName , projectOptions . compilerOptions , projectOptions . files , fileNamePropertyReader ) ;
901
914
const project = new ConfiguredProject (
902
915
configFileName ,
903
916
this ,
@@ -1050,7 +1063,7 @@ namespace ts.server {
1050
1063
return configFileErrors ;
1051
1064
}
1052
1065
1053
- if ( this . exceededTotalSizeLimitForNonTsFiles ( projectOptions . compilerOptions , projectOptions . files , fileNamePropertyReader ) ) {
1066
+ if ( this . exceededTotalSizeLimitForNonTsFiles ( project . canonicalConfigFilePath , projectOptions . compilerOptions , projectOptions . files , fileNamePropertyReader ) ) {
1054
1067
project . setCompilerOptions ( projectOptions . compilerOptions ) ;
1055
1068
if ( ! project . languageServiceEnabled ) {
1056
1069
// language service is already disabled
@@ -1414,7 +1427,7 @@ namespace ts.server {
1414
1427
if ( externalProject ) {
1415
1428
if ( ! tsConfigFiles ) {
1416
1429
const compilerOptions = convertCompilerOptions ( proj . options ) ;
1417
- if ( this . exceededTotalSizeLimitForNonTsFiles ( compilerOptions , proj . rootFiles , externalFilePropertyReader ) ) {
1430
+ if ( this . exceededTotalSizeLimitForNonTsFiles ( proj . projectFileName , compilerOptions , proj . rootFiles , externalFilePropertyReader ) ) {
1418
1431
externalProject . disableLanguageService ( ) ;
1419
1432
}
1420
1433
else {
0 commit comments