-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Port #7486 to release 1.8 #7513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3b55558
708fb97
35b972e
4aba58c
6ed14c2
cfa83e9
5e74ebd
4d0f488
f13a9c7
7547f2f
23184f5
760c163
b0fc9e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1217,10 +1217,45 @@ namespace ts.server { | |
} | ||
else { | ||
const project = this.createProject(configFilename, projectOptions); | ||
let programSizeForNonTsFiles = 0; | ||
|
||
// 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) { | ||
if (this.host.fileExists(clientFileName)) { | ||
const currentClientFileInfo = this.openFile(clientFileName, /*openedByClient*/ true); | ||
project.addRoot(currentClientFileInfo); | ||
if (!hasTypeScriptFileExtension(currentClientFileInfo.fileName) && currentClientFileInfo.content) { | ||
programSizeForNonTsFiles += currentClientFileInfo.content.length; | ||
} | ||
} | ||
else { | ||
return { errorMsg: "specified file " + clientFileName + " not found" }; | ||
} | ||
} | ||
|
||
for (const rootFilename of projectOptions.files) { | ||
if (rootFilename === clientFileName) { | ||
continue; | ||
} | ||
|
||
if (this.host.fileExists(rootFilename)) { | ||
const info = this.openFile(rootFilename, /*openedByClient*/ clientFileName == rootFilename); | ||
project.addRoot(info); | ||
if (projectOptions.compilerOptions.disableSizeLimit) { | ||
const info = this.openFile(rootFilename, /*openedByClient*/ false); | ||
project.addRoot(info); | ||
} | ||
else if (programSizeForNonTsFiles <= maxProgramSizeForNonTsFiles) { | ||
const info = this.openFile(rootFilename, /*openedByClient*/ false); | ||
project.addRoot(info); | ||
if (!hasTypeScriptFileExtension(rootFilename)) { | ||
programSizeForNonTsFiles += info.content.length; | ||
} | ||
} | ||
else { | ||
// The project size is too large. Stop loading the files on the server, | ||
// and let the compiler issue an diagnostic via `createProgram`. | ||
break; | ||
} | ||
} | ||
else { | ||
return { errorMsg: "specified file " + rootFilename + " not found" }; | ||
|
@@ -1251,7 +1286,10 @@ namespace ts.server { | |
return error; | ||
} | ||
else { | ||
const oldFileNames = project.compilerService.host.roots.map(info => info.fileName); | ||
// if the project is too large, the root files might not have been all loaded if the total | ||
// program size reached the upper limit. In that case project.projectOptions.files should | ||
// be more precise. However this would only happen for configured project. | ||
const oldFileNames = project.projectOptions ? project.projectOptions.files : project.compilerService.host.roots.map(info => info.fileName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
const newFileNames = projectOptions.files; | ||
const fileNamesToRemove = oldFileNames.filter(f => newFileNames.indexOf(f) < 0); | ||
const fileNamesToAdd = newFileNames.filter(f => oldFileNames.indexOf(f) < 0); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the intent to just stop loading files at this point without issuing an error, and to let
createProgram
issue the error when it adds up the file sizes? If so, add a comment here to explain this, so that future readers know why you are just breaking out of the loop without any kind of error.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly, as I can't create a diagnostic within
editorServices.ts
, the error returned here would be only used for logging. Adding a comment