From 35b972e1d8910caba5718aa55ecfe83b942dfb08 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Mon, 14 Mar 2016 14:51:24 -0700 Subject: [PATCH] CR feedback / Change upper limit / Add disableSizeLimit compiler option # Conflicts: # src/compiler/commandLineParser.ts # src/compiler/diagnosticMessages.json --- src/compiler/commandLineParser.ts | 5 ++++ src/compiler/diagnosticMessages.json | 6 ++++- src/compiler/program.ts | 38 +++++++++++++++++++--------- src/compiler/sys.ts | 20 ++++++++------- src/compiler/types.ts | 1 + src/compiler/utilities.ts | 2 +- src/server/editorServices.ts | 23 ++++++++++++----- 7 files changed, 65 insertions(+), 30 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 652582c270f..66c9be50869 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -305,6 +305,11 @@ namespace ts { name: "noCustomAsyncPromise", type: "boolean", experimental: true + }, + { + name: "disableSizeLimit", + type: "boolean", + description: Diagnostics.Disable_the_upper_limit_for_the_total_file_size_of_a_project } ]; diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index d54cddb245c..ad7b1da0a5c 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2458,6 +2458,10 @@ "category": "Message", "code": 6112 }, + "Disable the upper limit for the total file size of a project.": { + "category": "Message", + "code": 6113 + }, "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", "code": 7005 @@ -2662,7 +2666,7 @@ "category": "Error", "code": 17010 }, - "Too many javascript files in the project. Consider add to the `exclude` list in the config file.": { + "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'": { "category": "Error", "code": 17012 } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 59b6a1512fe..122e2e315b8 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -394,24 +394,38 @@ namespace ts { (oldOptions.target !== options.target) || (oldOptions.noLib !== options.noLib) || (oldOptions.jsx !== options.jsx) || - (oldOptions.allowJs !== options.allowJs)) { + (oldOptions.allowJs !== options.allowJs) || + (oldOptions.disableSizeLimit !== options.disableSizeLimit)) { oldProgram = undefined; } } if (!tryReuseStructureFromOldProgram()) { - let programSize = 0; - for (const name of rootNames) { - const path = toPath(name, currentDirectory, getCanonicalFileName); - if (programSize <= maxProgramSize) { - processRootFile(name, /*isDefaultLib*/ false); - if (!hasTypeScriptFileExtension(name) && filesByName.get(path)) { - programSize += filesByName.get(path).text.length; + if (options.disableSizeLimit === true) { + forEach(rootNames, name => processRootFile(name, /*isDefaultLib*/ false)); + } + else { + let programSize = 0; + for (const name of rootNames) { + const path = toPath(name, currentDirectory, getCanonicalFileName); + if (programSize <= maxProgramSize) { + processRootFile(name, /*isDefaultLib*/ false); + const file = filesByName.get(path); + if (!hasTypeScriptFileExtension(name) && file && file.text) { + programSize += file.text.length; + } + } + else { + // If the program size limit was reached when processing a file, this file is + // likely in the problematic folder than contains too many files + const commonSourceDirectory = getCommonSourceDirectory(); + let rootLevelDirectory = path.substring(0, Math.max(commonSourceDirectory.length, path.indexOf(directorySeparator, commonSourceDirectory.length))); + if (rootLevelDirectory[rootLevelDirectory.length - 1] !== directorySeparator) { + rootLevelDirectory += directorySeparator; + } + 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)); + break; } - } - else { - programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Too_many_javascript_files_in_the_project_Consider_add_to_the_exclude_list_in_the_config_file)); - break; } } diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index f8c8a355b38..5aa0b8dd2f4 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -478,17 +478,19 @@ namespace ts { const name = combinePaths(path, current); if (!contains(exclude, getCanonicalPath(name))) { // fs.statSync would throw an exception if the file is a symlink - // whose linked file doesn't exist. fs.lstatSync would return a stat - // object for the symlink file itself in this case - const stat = _fs.lstatSync(name); - if (stat.isFile()) { - if (!extension || fileExtensionIs(name, extension)) { - result.push(name); + // whose linked file doesn't exist. + try { + const stat = _fs.statSync(name); + if (stat.isFile()) { + if (!extension || fileExtensionIs(name, extension)) { + result.push(name); + } + } + else if (stat.isDirectory()) { + directories.push(name); } } - else if (stat.isDirectory()) { - directories.push(name); - } + catch (e) { } } } for (const current of directories) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index d0cd0ae6080..2692354258f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2437,6 +2437,7 @@ namespace ts { allowSyntheticDefaultImports?: boolean; allowJs?: boolean; noImplicitUseStrict?: boolean; + disableSizeLimit?: boolean; /* @internal */ stripInternal?: boolean; // Skip checking lib.d.ts to help speed up tests. diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 22fc5b73e55..f2d6cd79c92 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2863,5 +2863,5 @@ namespace ts { return node.flags & NodeFlags.AccessibilityModifier && node.parent.kind === SyntaxKind.Constructor && isClassLike(node.parent.parent); } - export const maxProgramSize = 35 * 1024 * 1024; + export const maxProgramSize = 20 * 1024 * 1024; } diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 4dff284f5de..8ed9e8af0b6 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -1222,9 +1222,14 @@ namespace ts.server { // As the project openning might not be complete if there are too many files, // therefore to surface the diagnostics we need to make sure the given client file is opened. if (clientFileName) { - const currentClientFileInfo = this.openFile(clientFileName, /*openedByClient*/ true); - project.addRoot(currentClientFileInfo); - programSize += currentClientFileInfo.content.length; + if (this.host.fileExists(clientFileName)) { + const currentClientFileInfo = this.openFile(clientFileName, /*openedByClient*/ true); + project.addRoot(currentClientFileInfo); + programSize += currentClientFileInfo.content.length; + } + else { + return { errorMsg: "specified file " + clientFileName + " not found" }; + } } for (const rootFilename of projectOptions.files) { @@ -1232,8 +1237,12 @@ namespace ts.server { continue; } - if (programSize <= maxProgramSize) { - if (this.host.fileExists(rootFilename)) { + if (this.host.fileExists(rootFilename)) { + if (projectOptions.compilerOptions.disableSizeLimit === true) { + const info = this.openFile(rootFilename, /*openedByClient*/ false); + project.addRoot(info); + } + else if (programSize <= maxProgramSize) { const info = this.openFile(rootFilename, /*openedByClient*/ false); project.addRoot(info); if (!hasTypeScriptFileExtension(rootFilename)) { @@ -1241,11 +1250,11 @@ namespace ts.server { } } else { - return { errorMsg: "specified file " + rootFilename + " not found" }; + break; } } else { - break; + return { errorMsg: "specified file " + rootFilename + " not found" }; } } project.finishGraph();