Handle delayed or missed watches for project updates (#59625)

This commit is contained in:
Sheetal Nandi
2024-08-13 17:58:08 -07:00
committed by GitHub
parent 195203e971
commit 7753487591
13 changed files with 2202 additions and 246 deletions

View File

@@ -21,6 +21,7 @@ import {
FileWatcherCallback,
FileWatcherEventKind,
find,
forEachAncestorDirectory,
getAllowJSCompilerOption,
getBaseFileName,
getDirectoryPath,
@@ -291,6 +292,13 @@ export function createCachedDirectoryStructureHost(host: DirectoryStructureHost,
return host.realpath ? host.realpath(s) : s;
}
function clearFirstAncestorEntry(fileOrDirectoryPath: Path) {
forEachAncestorDirectory(
getDirectoryPath(fileOrDirectoryPath),
ancestor => cachedReadDirectoryResult.delete(ensureTrailingDirectorySeparator(ancestor)) ? true : undefined,
);
}
function addOrDeleteFileOrDirectory(fileOrDirectory: string, fileOrDirectoryPath: Path) {
const existingResult = getCachedFileSystemEntries(fileOrDirectoryPath);
if (existingResult !== undefined) {
@@ -302,6 +310,7 @@ export function createCachedDirectoryStructureHost(host: DirectoryStructureHost,
const parentResult = getCachedFileSystemEntriesForBaseDir(fileOrDirectoryPath);
if (!parentResult) {
clearFirstAncestorEntry(fileOrDirectoryPath);
return undefined;
}
@@ -339,6 +348,9 @@ export function createCachedDirectoryStructureHost(host: DirectoryStructureHost,
if (parentResult) {
updateFilesOfFileSystemEntry(parentResult, getBaseNameOfFileName(fileName), eventKind === FileWatcherEventKind.Created);
}
else {
clearFirstAncestorEntry(filePath);
}
}
function updateFilesOfFileSystemEntry(parentResult: SortedAndCanonicalizedMutableFileSystemEntries, baseName: string, fileExists: boolean): void {