Skip to content

Commit 8c443b1

Browse files
author
Benjamin Lichtman
committed
Stop invalidating resolution when file stays open
1 parent 953153e commit 8c443b1

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

src/compiler/resolutionCache.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ namespace ts {
5454
writeLog(s: string): void;
5555
maxNumberOfFilesToIterateForInvalidation?: number;
5656
getCurrentProgram(): Program | undefined;
57+
fileIsOpen(filePath: Path): boolean;
5758
}
5859

5960
interface DirectoryWatchesOfFailedLookup {
@@ -713,6 +714,10 @@ namespace ts {
713714
if (!isPathWithDefaultFailedLookupExtension(fileOrDirectoryPath) && !customFailedLookupPaths.has(fileOrDirectoryPath)) {
714715
return false;
715716
}
717+
// prevent saving an open file from over-eagerly triggering invalidation
718+
if (resolutionHost.fileIsOpen(fileOrDirectoryPath)) {
719+
return;
720+
}
716721
// Ignore emits from the program
717722
if (isEmittedFileOfProgram(resolutionHost.getCurrentProgram(), fileOrDirectoryPath)) {
718723
return false;

src/compiler/watch.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,7 @@ namespace ts {
691691
hasChangedAutomaticTypeDirectiveNames = true;
692692
scheduleProgramUpdate();
693693
};
694+
compilerHost.fileIsOpen = () => false;
694695
compilerHost.maxNumberOfFilesToIterateForInvalidation = host.maxNumberOfFilesToIterateForInvalidation;
695696
compilerHost.getCurrentProgram = getCurrentProgram;
696697
compilerHost.writeLog = writeLog;

src/server/project.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,11 @@ namespace ts.server {
457457
return this.getTypeAcquisition().enable ? this.projectService.typingsInstaller.globalTypingsCacheLocation : undefined;
458458
}
459459

460+
/*@internal*/
461+
fileIsOpen(filePath: Path) {
462+
return this.projectService.openFiles.has(filePath);
463+
}
464+
460465
/*@internal*/
461466
writeLog(s: string) {
462467
this.projectService.logger.info(s);

0 commit comments

Comments
 (0)