Skip to content

Commit

Permalink
Do not watch failed lookup locations in persistResolutions if resolve…
Browse files Browse the repository at this point in the history
…d to a file

This ensure --watch and editor behaviour matches with what happens without watch and there is no confusion as well as we are not watching unnecessary things
  • Loading branch information
sheetalkamat committed May 18, 2021
1 parent b79bf50 commit abe3b73
Show file tree
Hide file tree
Showing 10 changed files with 546 additions and 416 deletions.
22 changes: 15 additions & 7 deletions src/compiler/resolutionCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace ts {
refCount?: number;
// Files that have this resolution using
files?: Path[];
skipWatchingFailedLookup?: true;
}

interface ResolutionWithResolvedFileName {
Expand Down Expand Up @@ -600,18 +601,24 @@ namespace ts {
) {
if (resolution.refCount) {
resolution.refCount++;
Debug.assertDefined(resolution.files);
Debug.checkDefined(resolution.files);
}
else {
resolution.refCount = 1;
Debug.assert(length(resolution.files) === 0); // This resolution shouldnt be referenced by any file yet
if (isExternalModuleNameRelative(name)) {
watchFailedLookupLocationOfResolution(resolution);
const resolved = getResolutionWithResolvedFileName(resolution);
// Watch resolution only if not persisting resolutions or if its not resolved to a file
if (!resolutionHost.getCompilationSettings().persistResolutions || !resolved?.resolvedFileName) {
if (isExternalModuleNameRelative(name)) {
watchFailedLookupLocationOfResolution(resolution);
}
else {
nonRelativeExternalModuleResolutions.add(name, resolution);
}
}
else {
nonRelativeExternalModuleResolutions.add(name, resolution);
resolution.skipWatchingFailedLookup = true;
}
const resolved = getResolutionWithResolvedFileName(resolution);
if (resolved && resolved.resolvedFileName) {
resolvedFileToResolution.add(resolutionHost.toPath(resolved.resolvedFileName), resolution);
}
Expand Down Expand Up @@ -677,7 +684,7 @@ namespace ts {
filePath: Path,
getResolutionWithResolvedFileName: GetResolutionWithResolvedFileName<T, R>,
) {
unorderedRemoveItem(Debug.assertDefined(resolution.files), filePath);
unorderedRemoveItem(Debug.checkDefined(resolution.files), filePath);
resolution.refCount!--;
if (resolution.refCount) {
return;
Expand All @@ -687,6 +694,7 @@ namespace ts {
resolvedFileToResolution.remove(resolutionHost.toPath(resolved.resolvedFileName), resolution);
}

if (resolution.skipWatchingFailedLookup) return;
if (!unorderedRemoveItem(resolutionsWithFailedLookups, resolution)) {
// If not watching failed lookups, it wont be there in resolutionsWithFailedLookups
return;
Expand Down Expand Up @@ -779,7 +787,7 @@ namespace ts {
for (const resolution of resolutions) {
if (resolution.isInvalidated || !canInvalidate(resolution)) continue;
resolution.isInvalidated = invalidated = true;
for (const containingFilePath of Debug.assertDefined(resolution.files)) {
for (const containingFilePath of Debug.checkDefined(resolution.files)) {
(filesWithInvalidatedResolutions || (filesWithInvalidatedResolutions = new Set())).add(containingFilePath);
// When its a file with inferred types resolution, invalidate type reference directive resolution
hasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames || endsWith(containingFilePath, inferredTypesContainingFile);
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1411,27 +1411,24 @@ DirectoryWatcher:: Triggered with /user/username/projects/myproject/src/external
Scheduled: /user/username/projects/myproject/tsconfig.jsonFailedLookupInvalidation
Elapsed:: *ms DirectoryWatcher:: Triggered with /user/username/projects/myproject/src/externalThing.ts :: WatchInfo: /user/username/projects/myproject/src 1 undefined Project: /user/username/projects/myproject/tsconfig.json WatchType: Failed Lookup Locations
Running: /user/username/projects/myproject/tsconfig.json
Scheduled: *ensureProjectForOpenFiles*, Cancelled earlier one
FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/src/externalThing.ts 500 undefined WatchType: Closed Script info
Starting updateGraphWorker: Project: /user/username/projects/myproject/tsconfig.json
Reusing resolution of module './filePresent' from '/user/username/projects/myproject/src/anotherFileReusingResolution.ts' of old program, it was successfully resolved to '/user/username/projects/myproject/src/filePresent.ts'.
Reusing resolution of module './fileNotFound' from '/user/username/projects/myproject/src/anotherFileReusingResolution.ts' of old program, it was not resolved.
======== Resolving module 'externalThing' from '/user/username/projects/myproject/src/anotherFileReusingResolution.ts'. ========
Module resolution kind is not specified, using 'Classic'.
File '/user/username/projects/myproject/src/externalThing.ts' exist - use it as a name resolution result.
======== Module name 'externalThing' was successfully resolved to '/user/username/projects/myproject/src/externalThing.ts'. ========
Reusing resolution of module 'externalThing' from '/user/username/projects/myproject/src/anotherFileReusingResolution.ts' of old program, it was successfully resolved to '/user/username/projects/myproject/src/externalThing.d.ts'.
Reusing resolution of module 'externalThingNotPresent' from '/user/username/projects/myproject/src/anotherFileReusingResolution.ts' of old program, it was successfully resolved to '/user/username/projects/myproject/src/externalThingNotPresent.ts'.
Reusing resolution of module './fileNotFound' from '/user/username/projects/myproject/src/anotherFileReusingResolution.ts' of old program, it was not resolved.
Reusing resolution of module './newFile' from '/user/username/projects/myproject/src/main.ts' of old program, it was successfully resolved to '/user/username/projects/myproject/src/newFile.ts'.
Reusing resolution of module './filePresent' from '/user/username/projects/myproject/src/main.ts' of old program, it was successfully resolved to '/user/username/projects/myproject/src/filePresent.ts'.
Reusing resolution of module './fileNotFound' from '/user/username/projects/myproject/src/main.ts' of old program, it was not resolved.
Reusing resolution of module 'externalThing' from '/user/username/projects/myproject/src/main.ts' found in cache from location '/user/username/projects/myproject/src', it was successfully resolved to '/user/username/projects/myproject/src/externalThing.ts'.
Reusing resolution of module './filePresent' from '/user/username/projects/myproject/src/main.ts' of old program, it was successfully resolved to '/user/username/projects/myproject/src/filePresent.ts'.
Reusing resolution of module 'externalThing' from '/user/username/projects/myproject/src/main.ts' of old program, it was successfully resolved to '/user/username/projects/myproject/src/externalThing.d.ts'.
Reusing resolution of module 'externalThingNotPresent' from '/user/username/projects/myproject/src/main.ts' of old program, it was successfully resolved to '/user/username/projects/myproject/src/externalThingNotPresent.ts'.
Reusing resolution of module './fileNotFound' from '/user/username/projects/myproject/src/main.ts' of old program, it was not resolved.
Finishing updateGraphWorker: Project: /user/username/projects/myproject/tsconfig.json Version: 10 structureChanged: true structureIsReused:: SafeModules Elapsed:: *ms
Project '/user/username/projects/myproject/tsconfig.json' (Configured)
Files (14)
Files (15)
/a/lib/lib.d.ts
/user/username/projects/myproject/src/filePresent.ts
/user/username/projects/myproject/src/externalThing.ts
/user/username/projects/myproject/src/externalThing.d.ts
/user/username/projects/myproject/src/externalThingNotPresent.ts
/user/username/projects/myproject/src/anotherFileReusingResolution.ts
/user/username/projects/myproject/src/types.ts
Expand All @@ -1443,6 +1440,7 @@ Project '/user/username/projects/myproject/tsconfig.json' (Configured)
/user/username/projects/myproject/src/globalMain.ts
/user/username/projects/myproject/src/newFile.ts
/user/username/projects/myproject/src/main.ts
/user/username/projects/myproject/src/externalThing.ts


../../../../a/lib/lib.d.ts
Expand All @@ -1452,10 +1450,9 @@ Project '/user/username/projects/myproject/tsconfig.json' (Configured)
Matched by include pattern 'src/**/*.ts' in 'tsconfig.json'
Imported via "./filePresent" from file 'src/main.ts'
Imported via "./filePresent" from file 'src/main.ts'
src/externalThing.ts
src/externalThing.d.ts
Imported via "externalThing" from file 'src/anotherFileReusingResolution.ts'
Imported via "externalThing" from file 'src/main.ts'
Matched by include pattern 'src/**/*.ts' in 'tsconfig.json'
src/externalThingNotPresent.ts
Imported via "externalThingNotPresent" from file 'src/anotherFileReusingResolution.ts'
Imported via "externalThingNotPresent" from file 'src/main.ts'
Expand Down Expand Up @@ -1487,12 +1484,14 @@ Project '/user/username/projects/myproject/tsconfig.json' (Configured)
Matched by include pattern 'src/**/*.ts' in 'tsconfig.json'
src/main.ts
Matched by include pattern 'src/**/*.ts' in 'tsconfig.json'
src/externalThing.ts
Matched by include pattern 'src/**/*.ts' in 'tsconfig.json'

-----------------------------------------------
Running: *ensureProjectForOpenFiles*
Before ensureProjectForOpenFiles:
Project '/user/username/projects/myproject/tsconfig.json' (Configured)
Files (14)
Files (15)

-----------------------------------------------
Open files:
Expand All @@ -1502,7 +1501,7 @@ Open files:
Projects: /user/username/projects/myproject/tsconfig.json
After ensureProjectForOpenFiles:
Project '/user/username/projects/myproject/tsconfig.json' (Configured)
Files (14)
Files (15)

-----------------------------------------------
Open files:
Expand All @@ -1528,8 +1527,8 @@ interface Array<T> { length: number; [n: number]: T; }
{"fileName":"/user/username/projects/myproject/src/filePresent.ts","version":"11598859296-export function something() { return 10; }"}
export function something() { return 10; }

{"fileName":"/user/username/projects/myproject/src/externalThing.ts","version":"5618215488-export function externalThing1() { return 10; }"}
export function externalThing1() { return 10; }
{"fileName":"/user/username/projects/myproject/src/externalThing.d.ts","version":"5686005290-export function externalThing1(): number;"}
export function externalThing1(): number;

{"fileName":"/user/username/projects/myproject/src/externalThingNotPresent.ts","version":"5318862050-export function externalThing2() { return 20; }"}
export function externalThing2() { return 20; }
Expand Down Expand Up @@ -1582,3 +1581,6 @@ something();
import { externalThing1 } from "externalThing";
import { externalThing2 } from "externalThingNotPresent";

{"fileName":"/user/username/projects/myproject/src/externalThing.ts","version":"5618215488-export function externalThing1() { return 10; }"}
export function externalThing1() { return 10; }

Original file line number Diff line number Diff line change
Expand Up @@ -1411,27 +1411,24 @@ DirectoryWatcher:: Triggered with /user/username/projects/myproject/src/external
Scheduled: /user/username/projects/myproject/tsconfig.jsonFailedLookupInvalidation
Elapsed:: *ms DirectoryWatcher:: Triggered with /user/username/projects/myproject/src/externalThing.ts :: WatchInfo: /user/username/projects/myproject/src 1 undefined Project: /user/username/projects/myproject/tsconfig.json WatchType: Failed Lookup Locations
Running: /user/username/projects/myproject/tsconfig.json
Scheduled: *ensureProjectForOpenFiles*, Cancelled earlier one
FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/src/externalThing.ts 500 undefined WatchType: Closed Script info
Starting updateGraphWorker: Project: /user/username/projects/myproject/tsconfig.json
Reusing resolution of module './filePresent' from '/user/username/projects/myproject/src/anotherFileReusingResolution.ts' of old program, it was successfully resolved to '/user/username/projects/myproject/src/filePresent.ts'.
Reusing resolution of module './fileNotFound' from '/user/username/projects/myproject/src/anotherFileReusingResolution.ts' of old program, it was not resolved.
======== Resolving module 'externalThing' from '/user/username/projects/myproject/src/anotherFileReusingResolution.ts'. ========
Module resolution kind is not specified, using 'Classic'.
File '/user/username/projects/myproject/src/externalThing.ts' exist - use it as a name resolution result.
======== Module name 'externalThing' was successfully resolved to '/user/username/projects/myproject/src/externalThing.ts'. ========
Reusing resolution of module 'externalThing' from '/user/username/projects/myproject/src/anotherFileReusingResolution.ts' of old program, it was successfully resolved to '/user/username/projects/myproject/src/externalThing.d.ts'.
Reusing resolution of module 'externalThingNotPresent' from '/user/username/projects/myproject/src/anotherFileReusingResolution.ts' of old program, it was successfully resolved to '/user/username/projects/myproject/src/externalThingNotPresent.ts'.
Reusing resolution of module './fileNotFound' from '/user/username/projects/myproject/src/anotherFileReusingResolution.ts' of old program, it was not resolved.
Reusing resolution of module './newFile' from '/user/username/projects/myproject/src/main.ts' of old program, it was successfully resolved to '/user/username/projects/myproject/src/newFile.ts'.
Reusing resolution of module './filePresent' from '/user/username/projects/myproject/src/main.ts' of old program, it was successfully resolved to '/user/username/projects/myproject/src/filePresent.ts'.
Reusing resolution of module './fileNotFound' from '/user/username/projects/myproject/src/main.ts' of old program, it was not resolved.
Reusing resolution of module 'externalThing' from '/user/username/projects/myproject/src/main.ts' found in cache from location '/user/username/projects/myproject/src', it was successfully resolved to '/user/username/projects/myproject/src/externalThing.ts'.
Reusing resolution of module './filePresent' from '/user/username/projects/myproject/src/main.ts' of old program, it was successfully resolved to '/user/username/projects/myproject/src/filePresent.ts'.
Reusing resolution of module 'externalThing' from '/user/username/projects/myproject/src/main.ts' of old program, it was successfully resolved to '/user/username/projects/myproject/src/externalThing.d.ts'.
Reusing resolution of module 'externalThingNotPresent' from '/user/username/projects/myproject/src/main.ts' of old program, it was successfully resolved to '/user/username/projects/myproject/src/externalThingNotPresent.ts'.
Reusing resolution of module './fileNotFound' from '/user/username/projects/myproject/src/main.ts' of old program, it was not resolved.
Finishing updateGraphWorker: Project: /user/username/projects/myproject/tsconfig.json Version: 10 structureChanged: true structureIsReused:: SafeModules Elapsed:: *ms
Project '/user/username/projects/myproject/tsconfig.json' (Configured)
Files (14)
Files (15)
/a/lib/lib.d.ts
/user/username/projects/myproject/src/filePresent.ts
/user/username/projects/myproject/src/externalThing.ts
/user/username/projects/myproject/src/externalThing.d.ts
/user/username/projects/myproject/src/externalThingNotPresent.ts
/user/username/projects/myproject/src/anotherFileReusingResolution.ts
/user/username/projects/myproject/src/types.ts
Expand All @@ -1443,6 +1440,7 @@ Project '/user/username/projects/myproject/tsconfig.json' (Configured)
/user/username/projects/myproject/src/globalMain.ts
/user/username/projects/myproject/src/newFile.ts
/user/username/projects/myproject/src/main.ts
/user/username/projects/myproject/src/externalThing.ts


../../../../a/lib/lib.d.ts
Expand All @@ -1452,10 +1450,9 @@ Project '/user/username/projects/myproject/tsconfig.json' (Configured)
Matched by include pattern 'src/**/*.ts' in 'tsconfig.json'
Imported via "./filePresent" from file 'src/main.ts'
Imported via "./filePresent" from file 'src/main.ts'
src/externalThing.ts
src/externalThing.d.ts
Imported via "externalThing" from file 'src/anotherFileReusingResolution.ts'
Imported via "externalThing" from file 'src/main.ts'
Matched by include pattern 'src/**/*.ts' in 'tsconfig.json'
src/externalThingNotPresent.ts
Imported via "externalThingNotPresent" from file 'src/anotherFileReusingResolution.ts'
Imported via "externalThingNotPresent" from file 'src/main.ts'
Expand Down Expand Up @@ -1487,12 +1484,14 @@ Project '/user/username/projects/myproject/tsconfig.json' (Configured)
Matched by include pattern 'src/**/*.ts' in 'tsconfig.json'
src/main.ts
Matched by include pattern 'src/**/*.ts' in 'tsconfig.json'
src/externalThing.ts
Matched by include pattern 'src/**/*.ts' in 'tsconfig.json'

-----------------------------------------------
Running: *ensureProjectForOpenFiles*
Before ensureProjectForOpenFiles:
Project '/user/username/projects/myproject/tsconfig.json' (Configured)
Files (14)
Files (15)

-----------------------------------------------
Open files:
Expand All @@ -1502,7 +1501,7 @@ Open files:
Projects: /user/username/projects/myproject/tsconfig.json
After ensureProjectForOpenFiles:
Project '/user/username/projects/myproject/tsconfig.json' (Configured)
Files (14)
Files (15)

-----------------------------------------------
Open files:
Expand All @@ -1528,8 +1527,8 @@ interface Array<T> { length: number; [n: number]: T; }
{"fileName":"/user/username/projects/myproject/src/filePresent.ts","version":"11598859296-export function something() { return 10; }"}
export function something() { return 10; }

{"fileName":"/user/username/projects/myproject/src/externalThing.ts","version":"5618215488-export function externalThing1() { return 10; }"}
export function externalThing1() { return 10; }
{"fileName":"/user/username/projects/myproject/src/externalThing.d.ts","version":"5686005290-export function externalThing1(): number;"}
export function externalThing1(): number;

{"fileName":"/user/username/projects/myproject/src/externalThingNotPresent.ts","version":"5318862050-export function externalThing2() { return 20; }"}
export function externalThing2() { return 20; }
Expand Down Expand Up @@ -1582,3 +1581,6 @@ something();
import { externalThing1 } from "externalThing";
import { externalThing2 } from "externalThingNotPresent";

{"fileName":"/user/username/projects/myproject/src/externalThing.ts","version":"5618215488-export function externalThing1() { return 10; }"}
export function externalThing1() { return 10; }

Loading

0 comments on commit abe3b73

Please sign in to comment.