diff --git a/lib/tsc.js b/lib/tsc.js index f5d85ee65da..00d01da568a 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -63104,8 +63104,9 @@ var ts; if (isInDirectoryPath(rootPath, failedLookupLocationPath)) { return { dir: rootDir, dirPath: rootPath }; } - var dir = ts.getDirectoryPath(ts.getNormalizedAbsolutePath(failedLookupLocation, getCurrentDirectory())); - var dirPath = ts.getDirectoryPath(failedLookupLocationPath); + return getDirectoryToWatchFromFailedLookupLocationDirectory(ts.getDirectoryPath(ts.getNormalizedAbsolutePath(failedLookupLocation, getCurrentDirectory())), ts.getDirectoryPath(failedLookupLocationPath)); + } + function getDirectoryToWatchFromFailedLookupLocationDirectory(dir, dirPath) { while (ts.stringContains(dirPath, "/node_modules/")) { dir = ts.getDirectoryPath(dir); dirPath = ts.getDirectoryPath(dirPath); @@ -63307,13 +63308,27 @@ var ts; function closeTypeRootsWatch() { ts.clearMap(typeRootsWatches, ts.closeFileWatcher); } - function createTypeRootsWatch(_typeRootPath, typeRoot) { + function getDirectoryToWatchFailedLookupLocationFromTypeRoot(typeRoot, typeRootPath) { + if (allFilesHaveInvalidatedResolution) { + return undefined; + } + if (isInDirectoryPath(rootPath, typeRootPath)) { + return rootPath; + } + var _a = getDirectoryToWatchFromFailedLookupLocationDirectory(typeRoot, typeRootPath), dirPath = _a.dirPath, ignore = _a.ignore; + return !ignore && directoryWatchesOfFailedLookups.has(dirPath) && dirPath; + } + function createTypeRootsWatch(typeRootPath, typeRoot) { return resolutionHost.watchTypeRootsDirectory(typeRoot, function (fileOrDirectory) { var fileOrDirectoryPath = resolutionHost.toPath(fileOrDirectory); if (cachedDirectoryStructureHost) { cachedDirectoryStructureHost.addOrDeleteFileOrDirectory(fileOrDirectory, fileOrDirectoryPath); } resolutionHost.onChangedAutomaticTypeDirectiveNames(); + var dirPath = getDirectoryToWatchFailedLookupLocationFromTypeRoot(typeRoot, typeRootPath); + if (dirPath && invalidateResolutionOfFailedLookupLocation(fileOrDirectoryPath, dirPath === fileOrDirectoryPath)) { + resolutionHost.onInvalidatedResolution(); + } }, 1); } function updateTypeRootsWatch() { diff --git a/lib/tsserver.js b/lib/tsserver.js index ff68e8cc867..845fa815403 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -79274,6 +79274,7 @@ var ts; if (!newClassDeclaration) { return undefined; } + copyComments(ctorDeclaration, newClassDeclaration, sourceFile); changes.insertNodeAfter(sourceFile, precedingNode, newClassDeclaration); for (var _i = 0, deletes_1 = deletes; _i < deletes_1.length; _i++) { var deleteCallback = deletes_1[_i]; @@ -87032,8 +87033,9 @@ var ts; if (isInDirectoryPath(rootPath, failedLookupLocationPath)) { return { dir: rootDir, dirPath: rootPath }; } - var dir = ts.getDirectoryPath(ts.getNormalizedAbsolutePath(failedLookupLocation, getCurrentDirectory())); - var dirPath = ts.getDirectoryPath(failedLookupLocationPath); + return getDirectoryToWatchFromFailedLookupLocationDirectory(ts.getDirectoryPath(ts.getNormalizedAbsolutePath(failedLookupLocation, getCurrentDirectory())), ts.getDirectoryPath(failedLookupLocationPath)); + } + function getDirectoryToWatchFromFailedLookupLocationDirectory(dir, dirPath) { while (ts.stringContains(dirPath, "/node_modules/")) { dir = ts.getDirectoryPath(dir); dirPath = ts.getDirectoryPath(dirPath); @@ -87235,13 +87237,27 @@ var ts; function closeTypeRootsWatch() { ts.clearMap(typeRootsWatches, ts.closeFileWatcher); } - function createTypeRootsWatch(_typeRootPath, typeRoot) { + function getDirectoryToWatchFailedLookupLocationFromTypeRoot(typeRoot, typeRootPath) { + if (allFilesHaveInvalidatedResolution) { + return undefined; + } + if (isInDirectoryPath(rootPath, typeRootPath)) { + return rootPath; + } + var _a = getDirectoryToWatchFromFailedLookupLocationDirectory(typeRoot, typeRootPath), dirPath = _a.dirPath, ignore = _a.ignore; + return !ignore && directoryWatchesOfFailedLookups.has(dirPath) && dirPath; + } + function createTypeRootsWatch(typeRootPath, typeRoot) { return resolutionHost.watchTypeRootsDirectory(typeRoot, function (fileOrDirectory) { var fileOrDirectoryPath = resolutionHost.toPath(fileOrDirectory); if (cachedDirectoryStructureHost) { cachedDirectoryStructureHost.addOrDeleteFileOrDirectory(fileOrDirectory, fileOrDirectoryPath); } resolutionHost.onChangedAutomaticTypeDirectiveNames(); + var dirPath = getDirectoryToWatchFailedLookupLocationFromTypeRoot(typeRoot, typeRootPath); + if (dirPath && invalidateResolutionOfFailedLookupLocation(fileOrDirectoryPath, dirPath === fileOrDirectoryPath)) { + resolutionHost.onInvalidatedResolution(); + } }, 1); } function updateTypeRootsWatch() { diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index e799becc910..858ba9e2805 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -94589,6 +94589,7 @@ var ts; this.changes.push({ kind: ChangeKind.Remove, sourceFile: sourceFile, range: range }); return this; }; + /** Warning: This deletes comments too. See `copyComments` in `convertFunctionToEs6Class`. */ ChangeTracker.prototype.deleteNode = function (sourceFile, node, options) { if (options === void 0) { options = {}; } var startPosition = getAdjustedStartPosition(sourceFile, node, options, Position.FullStart); @@ -95585,6 +95586,7 @@ var ts; if (!newClassDeclaration) { return undefined; } + copyComments(ctorDeclaration, newClassDeclaration, sourceFile); // Because the preceding node could be touched, we need to insert nodes before delete nodes. changes.insertNodeAfter(sourceFile, precedingNode, newClassDeclaration); for (var _i = 0, deletes_1 = deletes; _i < deletes_1.length; _i++) { @@ -106407,8 +106409,9 @@ var ts; if (isInDirectoryPath(rootPath, failedLookupLocationPath)) { return { dir: rootDir, dirPath: rootPath }; } - var dir = ts.getDirectoryPath(ts.getNormalizedAbsolutePath(failedLookupLocation, getCurrentDirectory())); - var dirPath = ts.getDirectoryPath(failedLookupLocationPath); + return getDirectoryToWatchFromFailedLookupLocationDirectory(ts.getDirectoryPath(ts.getNormalizedAbsolutePath(failedLookupLocation, getCurrentDirectory())), ts.getDirectoryPath(failedLookupLocationPath)); + } + function getDirectoryToWatchFromFailedLookupLocationDirectory(dir, dirPath) { // If directory path contains node module, get the most parent node_modules directory for watching while (ts.stringContains(dirPath, "/node_modules/")) { dir = ts.getDirectoryPath(dir); @@ -106635,7 +106638,17 @@ var ts; function closeTypeRootsWatch() { ts.clearMap(typeRootsWatches, ts.closeFileWatcher); } - function createTypeRootsWatch(_typeRootPath, typeRoot) { + function getDirectoryToWatchFailedLookupLocationFromTypeRoot(typeRoot, typeRootPath) { + if (allFilesHaveInvalidatedResolution) { + return undefined; + } + if (isInDirectoryPath(rootPath, typeRootPath)) { + return rootPath; + } + var _a = getDirectoryToWatchFromFailedLookupLocationDirectory(typeRoot, typeRootPath), dirPath = _a.dirPath, ignore = _a.ignore; + return !ignore && directoryWatchesOfFailedLookups.has(dirPath) && dirPath; + } + function createTypeRootsWatch(typeRootPath, typeRoot) { // Create new watch and recursive info return resolutionHost.watchTypeRootsDirectory(typeRoot, function (fileOrDirectory) { var fileOrDirectoryPath = resolutionHost.toPath(fileOrDirectory); @@ -106647,6 +106660,12 @@ var ts; // We could potentially store more data here about whether it was/would be really be used or not // and with that determine to trigger compilation but for now this is enough resolutionHost.onChangedAutomaticTypeDirectiveNames(); + // Since directory watchers invoked are flaky, the failed lookup location events might not be triggered + // So handle to failed lookup locations here as well to ensure we are invalidating resolutions + var dirPath = getDirectoryToWatchFailedLookupLocationFromTypeRoot(typeRoot, typeRootPath); + if (dirPath && invalidateResolutionOfFailedLookupLocation(fileOrDirectoryPath, dirPath === fileOrDirectoryPath)) { + resolutionHost.onInvalidatedResolution(); + } }, 1 /* Recursive */); } /** diff --git a/lib/typescript.js b/lib/typescript.js index 827452e5715..0153fb9c7c9 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -78594,8 +78594,9 @@ var ts; if (isInDirectoryPath(rootPath, failedLookupLocationPath)) { return { dir: rootDir, dirPath: rootPath }; } - var dir = ts.getDirectoryPath(ts.getNormalizedAbsolutePath(failedLookupLocation, getCurrentDirectory())); - var dirPath = ts.getDirectoryPath(failedLookupLocationPath); + return getDirectoryToWatchFromFailedLookupLocationDirectory(ts.getDirectoryPath(ts.getNormalizedAbsolutePath(failedLookupLocation, getCurrentDirectory())), ts.getDirectoryPath(failedLookupLocationPath)); + } + function getDirectoryToWatchFromFailedLookupLocationDirectory(dir, dirPath) { // If directory path contains node module, get the most parent node_modules directory for watching while (ts.stringContains(dirPath, "/node_modules/")) { dir = ts.getDirectoryPath(dir); @@ -78822,7 +78823,17 @@ var ts; function closeTypeRootsWatch() { ts.clearMap(typeRootsWatches, ts.closeFileWatcher); } - function createTypeRootsWatch(_typeRootPath, typeRoot) { + function getDirectoryToWatchFailedLookupLocationFromTypeRoot(typeRoot, typeRootPath) { + if (allFilesHaveInvalidatedResolution) { + return undefined; + } + if (isInDirectoryPath(rootPath, typeRootPath)) { + return rootPath; + } + var _a = getDirectoryToWatchFromFailedLookupLocationDirectory(typeRoot, typeRootPath), dirPath = _a.dirPath, ignore = _a.ignore; + return !ignore && directoryWatchesOfFailedLookups.has(dirPath) && dirPath; + } + function createTypeRootsWatch(typeRootPath, typeRoot) { // Create new watch and recursive info return resolutionHost.watchTypeRootsDirectory(typeRoot, function (fileOrDirectory) { var fileOrDirectoryPath = resolutionHost.toPath(fileOrDirectory); @@ -78834,6 +78845,12 @@ var ts; // We could potentially store more data here about whether it was/would be really be used or not // and with that determine to trigger compilation but for now this is enough resolutionHost.onChangedAutomaticTypeDirectiveNames(); + // Since directory watchers invoked are flaky, the failed lookup location events might not be triggered + // So handle to failed lookup locations here as well to ensure we are invalidating resolutions + var dirPath = getDirectoryToWatchFailedLookupLocationFromTypeRoot(typeRoot, typeRootPath); + if (dirPath && invalidateResolutionOfFailedLookupLocation(fileOrDirectoryPath, dirPath === fileOrDirectoryPath)) { + resolutionHost.onInvalidatedResolution(); + } }, 1 /* Recursive */); } /** @@ -96151,6 +96168,7 @@ var ts; this.changes.push({ kind: ChangeKind.Remove, sourceFile: sourceFile, range: range }); return this; }; + /** Warning: This deletes comments too. See `copyComments` in `convertFunctionToEs6Class`. */ ChangeTracker.prototype.deleteNode = function (sourceFile, node, options) { if (options === void 0) { options = {}; } var startPosition = getAdjustedStartPosition(sourceFile, node, options, Position.FullStart); @@ -97147,6 +97165,7 @@ var ts; if (!newClassDeclaration) { return undefined; } + copyComments(ctorDeclaration, newClassDeclaration, sourceFile); // Because the preceding node could be touched, we need to insert nodes before delete nodes. changes.insertNodeAfter(sourceFile, precedingNode, newClassDeclaration); for (var _i = 0, deletes_1 = deletes; _i < deletes_1.length; _i++) { diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index 827452e5715..0153fb9c7c9 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -78594,8 +78594,9 @@ var ts; if (isInDirectoryPath(rootPath, failedLookupLocationPath)) { return { dir: rootDir, dirPath: rootPath }; } - var dir = ts.getDirectoryPath(ts.getNormalizedAbsolutePath(failedLookupLocation, getCurrentDirectory())); - var dirPath = ts.getDirectoryPath(failedLookupLocationPath); + return getDirectoryToWatchFromFailedLookupLocationDirectory(ts.getDirectoryPath(ts.getNormalizedAbsolutePath(failedLookupLocation, getCurrentDirectory())), ts.getDirectoryPath(failedLookupLocationPath)); + } + function getDirectoryToWatchFromFailedLookupLocationDirectory(dir, dirPath) { // If directory path contains node module, get the most parent node_modules directory for watching while (ts.stringContains(dirPath, "/node_modules/")) { dir = ts.getDirectoryPath(dir); @@ -78822,7 +78823,17 @@ var ts; function closeTypeRootsWatch() { ts.clearMap(typeRootsWatches, ts.closeFileWatcher); } - function createTypeRootsWatch(_typeRootPath, typeRoot) { + function getDirectoryToWatchFailedLookupLocationFromTypeRoot(typeRoot, typeRootPath) { + if (allFilesHaveInvalidatedResolution) { + return undefined; + } + if (isInDirectoryPath(rootPath, typeRootPath)) { + return rootPath; + } + var _a = getDirectoryToWatchFromFailedLookupLocationDirectory(typeRoot, typeRootPath), dirPath = _a.dirPath, ignore = _a.ignore; + return !ignore && directoryWatchesOfFailedLookups.has(dirPath) && dirPath; + } + function createTypeRootsWatch(typeRootPath, typeRoot) { // Create new watch and recursive info return resolutionHost.watchTypeRootsDirectory(typeRoot, function (fileOrDirectory) { var fileOrDirectoryPath = resolutionHost.toPath(fileOrDirectory); @@ -78834,6 +78845,12 @@ var ts; // We could potentially store more data here about whether it was/would be really be used or not // and with that determine to trigger compilation but for now this is enough resolutionHost.onChangedAutomaticTypeDirectiveNames(); + // Since directory watchers invoked are flaky, the failed lookup location events might not be triggered + // So handle to failed lookup locations here as well to ensure we are invalidating resolutions + var dirPath = getDirectoryToWatchFailedLookupLocationFromTypeRoot(typeRoot, typeRootPath); + if (dirPath && invalidateResolutionOfFailedLookupLocation(fileOrDirectoryPath, dirPath === fileOrDirectoryPath)) { + resolutionHost.onInvalidatedResolution(); + } }, 1 /* Recursive */); } /** @@ -96151,6 +96168,7 @@ var ts; this.changes.push({ kind: ChangeKind.Remove, sourceFile: sourceFile, range: range }); return this; }; + /** Warning: This deletes comments too. See `copyComments` in `convertFunctionToEs6Class`. */ ChangeTracker.prototype.deleteNode = function (sourceFile, node, options) { if (options === void 0) { options = {}; } var startPosition = getAdjustedStartPosition(sourceFile, node, options, Position.FullStart); @@ -97147,6 +97165,7 @@ var ts; if (!newClassDeclaration) { return undefined; } + copyComments(ctorDeclaration, newClassDeclaration, sourceFile); // Because the preceding node could be touched, we need to insert nodes before delete nodes. changes.insertNodeAfter(sourceFile, precedingNode, newClassDeclaration); for (var _i = 0, deletes_1 = deletes; _i < deletes_1.length; _i++) {