Skip to content

Commit 4aba58c

Browse files
author
zhengbli
committed
online and offline CR feedback
1 parent 35b972e commit 4aba58c

6 files changed

Lines changed: 37 additions & 42 deletions

File tree

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,7 @@ namespace ts {
308308
},
309309
{
310310
name: "disableSizeLimit",
311-
type: "boolean",
312-
description: Diagnostics.Disable_the_upper_limit_for_the_total_file_size_of_a_project
311+
type: "boolean"
313312
}
314313
];
315314

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2458,10 +2458,6 @@
24582458
"category": "Message",
24592459
"code": 6112
24602460
},
2461-
"Disable the upper limit for the total file size of a project.": {
2462-
"category": "Message",
2463-
"code": 6113
2464-
},
24652461
"Variable '{0}' implicitly has an '{1}' type.": {
24662462
"category": "Error",
24672463
"code": 7005
@@ -2666,7 +2662,7 @@
26662662
"category": "Error",
26672663
"code": 17010
26682664
},
2669-
"Too many JavaScript files in the project. Use an exact 'files' list, or use the 'exclude' setting in project configuration to limit included source folders. The likely folder to exclude is '{0}'. To disable the project size limit, set the 'disableSizeLimit' compiler option to 'true'": {
2665+
"Too many JavaScript files in the project. Consider specifying the 'exclude' setting in project configuration to limit included source folders. The likely folder to exclude is '{0}'. To disable the project size limit, set the 'disableSizeLimit' compiler option to 'true'.": {
26702666
"category": "Error",
26712667
"code": 17012
26722668
}

src/compiler/program.ts

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ namespace ts {
348348
let diagnosticsProducingTypeChecker: TypeChecker;
349349
let noDiagnosticsTypeChecker: TypeChecker;
350350
let classifiableNames: Map<string>;
351+
let programSizeForNonTsFiles = 0;
351352

352353
let skipDefaultLib = options.noLib;
353354
const supportedExtensions = getSupportedExtensions(options);
@@ -401,34 +402,7 @@ namespace ts {
401402
}
402403

403404
if (!tryReuseStructureFromOldProgram()) {
404-
if (options.disableSizeLimit === true) {
405-
forEach(rootNames, name => processRootFile(name, /*isDefaultLib*/ false));
406-
}
407-
else {
408-
let programSize = 0;
409-
for (const name of rootNames) {
410-
const path = toPath(name, currentDirectory, getCanonicalFileName);
411-
if (programSize <= maxProgramSize) {
412-
processRootFile(name, /*isDefaultLib*/ false);
413-
const file = filesByName.get(path);
414-
if (!hasTypeScriptFileExtension(name) && file && file.text) {
415-
programSize += file.text.length;
416-
}
417-
}
418-
else {
419-
// If the program size limit was reached when processing a file, this file is
420-
// likely in the problematic folder than contains too many files
421-
const commonSourceDirectory = getCommonSourceDirectory();
422-
let rootLevelDirectory = path.substring(0, Math.max(commonSourceDirectory.length, path.indexOf(directorySeparator, commonSourceDirectory.length)));
423-
if (rootLevelDirectory[rootLevelDirectory.length - 1] !== directorySeparator) {
424-
rootLevelDirectory += directorySeparator;
425-
}
426-
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Too_many_JavaScript_files_in_the_project_Use_an_exact_files_list_or_use_the_exclude_setting_in_project_configuration_to_limit_included_source_folders_The_likely_folder_to_exclude_is_0_To_disable_the_project_size_limit_set_the_disableSizeLimit_compiler_option_to_true, rootLevelDirectory));
427-
break;
428-
}
429-
}
430-
}
431-
405+
forEach(rootNames, name => processRootFile(name, /*isDefaultLib*/ false));
432406
// Do not process the default library if:
433407
// - The '--noLib' flag is used.
434408
// - A 'no-default-lib' reference comment is encountered in
@@ -1115,6 +1089,27 @@ namespace ts {
11151089
return file;
11161090
}
11171091

1092+
if (!options.disableSizeLimit) {
1093+
if (programSizeForNonTsFiles === -1) {
1094+
return;
1095+
}
1096+
if (programSizeForNonTsFiles > maxProgramSizeForNonTsFiles) {
1097+
// If the program size limit was reached when processing a file, this file is
1098+
// likely in the problematic folder than contains too many files.
1099+
// Normally the folder is one level down from the commonSourceDirectory, for example,
1100+
// if the commonSourceDirectory is "/src/", and the last processed path was "/src/node_modules/a/b.js",
1101+
// we should show in the error message "/src/node_modules/".
1102+
const commonSourceDirectory = getCommonSourceDirectory();
1103+
let rootLevelDirectory = path.substring(0, Math.max(commonSourceDirectory.length, path.indexOf(directorySeparator, commonSourceDirectory.length)));
1104+
if (rootLevelDirectory[rootLevelDirectory.length - 1] !== directorySeparator) {
1105+
rootLevelDirectory += directorySeparator;
1106+
}
1107+
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Too_many_JavaScript_files_in_the_project_Consider_specifying_the_exclude_setting_in_project_configuration_to_limit_included_source_folders_The_likely_folder_to_exclude_is_0_To_disable_the_project_size_limit_set_the_disableSizeLimit_compiler_option_to_true, rootLevelDirectory));
1108+
programSizeForNonTsFiles = -1;
1109+
return;
1110+
}
1111+
}
1112+
11181113
// We haven't looked for this file, do so now and cache result
11191114
const file = host.getSourceFile(fileName, options.target, hostErrorMessage => {
11201115
if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) {
@@ -1126,6 +1121,10 @@ namespace ts {
11261121
}
11271122
});
11281123

1124+
if (!options.disableSizeLimit && file && file.text && !hasTypeScriptFileExtension(file.fileName)) {
1125+
programSizeForNonTsFiles += file.text.length;
1126+
}
1127+
11291128
filesByName.set(path, file);
11301129
if (file) {
11311130
file.path = path;

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2863,5 +2863,5 @@ namespace ts {
28632863
return node.flags & NodeFlags.AccessibilityModifier && node.parent.kind === SyntaxKind.Constructor && isClassLike(node.parent.parent);
28642864
}
28652865

2866-
export const maxProgramSize = 20 * 1024 * 1024;
2866+
export const maxProgramSizeForNonTsFiles = 20 * 1024 * 1024;
28672867
}

src/server/editorServices.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,15 +1217,15 @@ namespace ts.server {
12171217
}
12181218
else {
12191219
const project = this.createProject(configFilename, projectOptions);
1220-
let programSize = 0;
1220+
let programSizeForNonTsFiles = 0;
12211221

12221222
// As the project openning might not be complete if there are too many files,
12231223
// therefore to surface the diagnostics we need to make sure the given client file is opened.
12241224
if (clientFileName) {
12251225
if (this.host.fileExists(clientFileName)) {
12261226
const currentClientFileInfo = this.openFile(clientFileName, /*openedByClient*/ true);
12271227
project.addRoot(currentClientFileInfo);
1228-
programSize += currentClientFileInfo.content.length;
1228+
programSizeForNonTsFiles += currentClientFileInfo.content.length;
12291229
}
12301230
else {
12311231
return { errorMsg: "specified file " + clientFileName + " not found" };
@@ -1238,15 +1238,15 @@ namespace ts.server {
12381238
}
12391239

12401240
if (this.host.fileExists(rootFilename)) {
1241-
if (projectOptions.compilerOptions.disableSizeLimit === true) {
1241+
if (projectOptions.compilerOptions.disableSizeLimit) {
12421242
const info = this.openFile(rootFilename, /*openedByClient*/ false);
12431243
project.addRoot(info);
12441244
}
1245-
else if (programSize <= maxProgramSize) {
1245+
else if (programSizeForNonTsFiles <= maxProgramSizeForNonTsFiles) {
12461246
const info = this.openFile(rootFilename, /*openedByClient*/ false);
12471247
project.addRoot(info);
12481248
if (!hasTypeScriptFileExtension(rootFilename)) {
1249-
programSize += info.content.length;
1249+
programSizeForNonTsFiles += info.content.length;
12501250
}
12511251
}
12521252
else {

src/services/services.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2759,7 +2759,8 @@ namespace ts {
27592759
oldSettings.module !== newSettings.module ||
27602760
oldSettings.noResolve !== newSettings.noResolve ||
27612761
oldSettings.jsx !== newSettings.jsx ||
2762-
oldSettings.allowJs !== newSettings.allowJs);
2762+
oldSettings.allowJs !== newSettings.allowJs ||
2763+
oldSettings.disableSizeLimit !== oldSettings.disableSizeLimit);
27632764

27642765
// Now create a new compiler
27652766
const compilerHost: CompilerHost = {

0 commit comments

Comments
 (0)