-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Resolution cache defensive checks #19053
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
Conversation
…d because of exception Fixes #18975
@@ -141,7 +141,10 @@ namespace ts { | |||
resolvedModuleNames.clear(); | |||
resolvedTypeReferenceDirectives.clear(); | |||
allFilesHaveInvalidatedResolution = false; | |||
Debug.assert(perDirectoryResolvedModuleNames.size === 0 && perDirectoryResolvedTypeReferenceDirectives.size === 0); | |||
// perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update |
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.
Could just call startCachingPerDirectoryResolution
from here?
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.
Should an exception during program update be recoverable? Might it be more useful to crash tsserver if we throw during program update and don't catch until the event loop?
src/compiler/watch.ts
Outdated
@@ -322,21 +322,21 @@ namespace ts { | |||
|
|||
if (hasChangedCompilerOptions) { | |||
newLine = getNewLineCharacter(compilerOptions, system); | |||
if (changesAffectModuleResolution(program && program.getCompilerOptions(), compilerOptions)) { |
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.
Nit: Would prefer program && changesAffectModuleResolution(program.getCompilerOptions(), compilerOptions)
since if !program
, changesAffectModuleResolution
has nothing it can do.
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.
+1
@@ -7145,6 +7145,7 @@ declare namespace ts.server { | |||
getExternalFiles(): SortedReadonlyArray<string>; | |||
getSourceFile(path: Path): SourceFile; | |||
close(): void; | |||
private detachScriptInfoIfNotRoot(uncheckedFilename); |
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.
Would be nice to have #8306 so we didn't need to include this..
Fixes #19077 too? |
Handle the case when finishCachingPerDirectoryResolution is not called because of exception
Fixes #18975
Assert if the script info that is attached to closed project is present. This also releases external project files that get attached to the project when project is closed
Handle project close to release all the script infos held by the project. Above assert revealed that if the project update was pending and project is closed, the files added as root but not yet in program (because the project's update graph was pending/delayed) wont be released and hence those script infos holding onto the closed project.
Fixes #19003 and #18928