Skip to content

Commit 29e5a30

Browse files
committed
Watch failed lookups, affecting locations only if reoslution failed
1 parent dd1e258 commit 29e5a30

535 files changed

Lines changed: 6097 additions & 14746 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/compiler/resolutionCache.ts

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
576576
let filesWithChangedSetOfUnresolvedImports: Path[] | undefined;
577577
let filesWithInvalidatedResolutions: Set<Path> | undefined;
578578
let filesWithInvalidatedNonRelativeUnresolvedImports: ReadonlyMap<Path, readonly string[]> | undefined;
579-
const nonRelativeExternalModuleResolutions = new Set<ResolutionWithFailedLookupLocations>();
579+
const nonRelativeExternalModuleResolutions = new Set<ResolvedModuleWithFailedLookupLocations>();
580580

581581
const resolutionsWithFailedLookups = new Set<ResolutionWithFailedLookupLocations>();
582582
const resolutionsWithOnlyAffectingLocations = new Set<ResolutionWithFailedLookupLocations>();
@@ -1103,10 +1103,10 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
11031103
(resolution.files ??= new Set()).add(filePath);
11041104
if (resolution.files.size !== 1) return;
11051105
if (!deferWatchingNonRelativeResolution || isExternalModuleNameRelative(name)) {
1106-
watchFailedLookupLocationOfResolution(resolution);
1106+
watchFailedLookupLocationOfResolution(resolution, getResolutionWithResolvedFileName);
11071107
}
11081108
else {
1109-
nonRelativeExternalModuleResolutions.add(resolution);
1109+
nonRelativeExternalModuleResolutions.add(resolution as unknown as ResolvedModuleWithFailedLookupLocations);
11101110
}
11111111
const resolved = getResolutionWithResolvedFileName(resolution);
11121112
if (resolved && resolved.resolvedFileName) {
@@ -1143,25 +1143,34 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
11431143
return setAtRoot;
11441144
}
11451145

1146-
function watchFailedLookupLocationOfResolution(resolution: ResolutionWithFailedLookupLocations) {
1146+
function watchFailedLookupLocationOfModule(resolution: ResolvedModuleWithFailedLookupLocations) {
1147+
watchFailedLookupLocationOfResolution(resolution, getResolvedModuleFromResolution);
1148+
}
1149+
1150+
function watchFailedLookupLocationOfResolution<T extends ResolutionWithFailedLookupLocations, R extends ResolutionWithResolvedFileName>(
1151+
resolution: T,
1152+
getResolutionWithResolvedFileName: GetResolutionWithResolvedFileName<T, R>,
1153+
) {
11471154
Debug.assert(!!resolution.files?.size);
11481155

11491156
const { failedLookupLocations, affectingLocations, alternateResult } = resolution;
11501157
if (!failedLookupLocations?.length && !affectingLocations?.length && !alternateResult) return;
1151-
if (failedLookupLocations?.length || alternateResult) resolutionsWithFailedLookups.add(resolution);
1152-
1153-
let setAtRoot = false;
1154-
if (failedLookupLocations) {
1155-
for (const failedLookupLocation of failedLookupLocations) {
1156-
setAtRoot = watchFailedLookupLocation(failedLookupLocation, setAtRoot);
1158+
const resolvedFileName = getResolutionWithResolvedFileName(resolution)?.resolvedFileName;
1159+
if (!resolvedFileName) {
1160+
if (failedLookupLocations?.length || alternateResult) resolutionsWithFailedLookups.add(resolution);
1161+
let setAtRoot = false;
1162+
if (failedLookupLocations) {
1163+
for (const failedLookupLocation of failedLookupLocations) {
1164+
setAtRoot = watchFailedLookupLocation(failedLookupLocation, setAtRoot);
1165+
}
11571166
}
1167+
if (alternateResult) setAtRoot = watchFailedLookupLocation(alternateResult, setAtRoot);
1168+
if (setAtRoot) {
1169+
// This is always non recursive
1170+
setDirectoryWatcher(rootDir, rootPath, /*packageDir*/ undefined, /*packageDirPath*/ undefined, /*nonRecursive*/ true);
1171+
}
1172+
watchAffectingLocationsOfResolution(resolution, !!resolvedFileName);
11581173
}
1159-
if (alternateResult) setAtRoot = watchFailedLookupLocation(alternateResult, setAtRoot);
1160-
if (setAtRoot) {
1161-
// This is always non recursive
1162-
setDirectoryWatcher(rootDir, rootPath, /*packageDir*/ undefined, /*packageDirPath*/ undefined, /*nonRecursive*/ true);
1163-
}
1164-
watchAffectingLocationsOfResolution(resolution, !failedLookupLocations?.length && !alternateResult);
11651174
}
11661175

11671176
function watchAffectingLocationsOfResolution(resolution: ResolutionWithFailedLookupLocations, addToResolutionsWithOnlyAffectingLocations: boolean) {
@@ -1241,7 +1250,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
12411250
}
12421251

12431252
function watchFailedLookupLocationOfNonRelativeModuleResolutions() {
1244-
nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfResolution);
1253+
nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfModule);
12451254
nonRelativeExternalModuleResolutions.clear();
12461255
}
12471256

@@ -1384,26 +1393,27 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
13841393
const resolutions = resolvedFileToResolution.get(key);
13851394
if (resolutions?.delete(resolution) && !resolutions.size) resolvedFileToResolution.delete(key);
13861395
}
1387-
1388-
const { failedLookupLocations, affectingLocations, alternateResult } = resolution;
1389-
if (resolutionsWithFailedLookups.delete(resolution)) {
1390-
let removeAtRoot = false;
1391-
if (failedLookupLocations) {
1392-
for (const failedLookupLocation of failedLookupLocations) {
1393-
removeAtRoot = stopWatchFailedLookupLocation(failedLookupLocation, removeAtRoot);
1396+
else {
1397+
const { failedLookupLocations, affectingLocations, alternateResult } = resolution;
1398+
if (resolutionsWithFailedLookups.delete(resolution)) {
1399+
let removeAtRoot = false;
1400+
if (failedLookupLocations) {
1401+
for (const failedLookupLocation of failedLookupLocations) {
1402+
removeAtRoot = stopWatchFailedLookupLocation(failedLookupLocation, removeAtRoot);
1403+
}
13941404
}
1405+
if (alternateResult) removeAtRoot = stopWatchFailedLookupLocation(alternateResult, removeAtRoot);
1406+
if (removeAtRoot) removeDirectoryWatcher(rootPath);
1407+
}
1408+
else if (affectingLocations?.length) {
1409+
resolutionsWithOnlyAffectingLocations.delete(resolution);
13951410
}
1396-
if (alternateResult) removeAtRoot = stopWatchFailedLookupLocation(alternateResult, removeAtRoot);
1397-
if (removeAtRoot) removeDirectoryWatcher(rootPath);
1398-
}
1399-
else if (affectingLocations?.length) {
1400-
resolutionsWithOnlyAffectingLocations.delete(resolution);
1401-
}
14021411

1403-
if (affectingLocations) {
1404-
for (const affectingLocation of affectingLocations) {
1405-
const watcher = fileWatchesOfAffectingLocations.get(affectingLocation)!;
1406-
watcher.resolutions--;
1412+
if (affectingLocations) {
1413+
for (const affectingLocation of affectingLocations) {
1414+
const watcher = fileWatchesOfAffectingLocations.get(affectingLocation)!;
1415+
watcher.resolutions--;
1416+
}
14071417
}
14081418
}
14091419
}

tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependencies/deepImportChanges/errors-for-.d.ts-change-with-incremental.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ PolledWatches::
135135
FsWatches::
136136
/home/src/tslibs/TS/Lib/lib.d.ts: *new*
137137
{}
138-
/user/username/projects/myproject: *new*
139-
{}
140138
/user/username/projects/myproject/a.ts: *new*
141139
{}
142140
/user/username/projects/myproject/b.d.ts: *new*
@@ -150,9 +148,6 @@ FsWatchesRecursive::
150148
/user/username/projects/myproject: *new*
151149
{}
152150

153-
Timeout callback:: count: 1
154-
2: timerToInvalidateFailedLookupResolutions *new*
155-
156151
Program root files: [
157152
"/user/username/projects/myproject/a.ts",
158153
"/user/username/projects/myproject/b.d.ts",
@@ -195,13 +190,11 @@ export class C
195190
}
196191

197192

198-
Timeout callback:: count: 2
199-
2: timerToInvalidateFailedLookupResolutions
200-
3: timerToUpdateProgram *new*
193+
Timeout callback:: count: 1
194+
1: timerToUpdateProgram *new*
201195

202-
Before running Timeout callback:: count: 2
203-
2: timerToInvalidateFailedLookupResolutions
204-
3: timerToUpdateProgram
196+
Before running Timeout callback:: count: 1
197+
1: timerToUpdateProgram
205198

206199
Host is moving to new time
207200
After running Timeout callback:: count: 0
@@ -324,10 +317,10 @@ export class C
324317

325318

326319
Timeout callback:: count: 1
327-
4: timerToUpdateProgram *new*
320+
2: timerToUpdateProgram *new*
328321

329322
Before running Timeout callback:: count: 1
330-
4: timerToUpdateProgram
323+
2: timerToUpdateProgram
331324

332325
Host is moving to new time
333326
After running Timeout callback:: count: 0
@@ -450,10 +443,10 @@ export class C
450443

451444

452445
Timeout callback:: count: 1
453-
5: timerToUpdateProgram *new*
446+
3: timerToUpdateProgram *new*
454447

455448
Before running Timeout callback:: count: 1
456-
5: timerToUpdateProgram
449+
3: timerToUpdateProgram
457450

458451
Host is moving to new time
459452
After running Timeout callback:: count: 0

tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependencies/deepImportChanges/errors-for-.d.ts-change.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ PolledWatches::
6565
FsWatches::
6666
/home/src/tslibs/TS/Lib/lib.d.ts: *new*
6767
{}
68-
/user/username/projects/myproject: *new*
69-
{}
7068
/user/username/projects/myproject/a.ts: *new*
7169
{}
7270
/user/username/projects/myproject/b.d.ts: *new*

tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependenciesAndD/deepImportChanges/errors-for-.d.ts-change-with-incremental.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,6 @@ PolledWatches::
144144
FsWatches::
145145
/home/src/tslibs/TS/Lib/lib.d.ts: *new*
146146
{}
147-
/user/username/projects/myproject: *new*
148-
{}
149147
/user/username/projects/myproject/a.ts: *new*
150148
{}
151149
/user/username/projects/myproject/b.d.ts: *new*
@@ -159,9 +157,6 @@ FsWatchesRecursive::
159157
/user/username/projects/myproject: *new*
160158
{}
161159

162-
Timeout callback:: count: 1
163-
2: timerToInvalidateFailedLookupResolutions *new*
164-
165160
Program root files: [
166161
"/user/username/projects/myproject/a.ts",
167162
"/user/username/projects/myproject/b.d.ts",
@@ -205,13 +200,11 @@ export class C
205200
}
206201

207202

208-
Timeout callback:: count: 2
209-
2: timerToInvalidateFailedLookupResolutions
210-
3: timerToUpdateProgram *new*
203+
Timeout callback:: count: 1
204+
1: timerToUpdateProgram *new*
211205

212-
Before running Timeout callback:: count: 2
213-
2: timerToInvalidateFailedLookupResolutions
214-
3: timerToUpdateProgram
206+
Before running Timeout callback:: count: 1
207+
1: timerToUpdateProgram
215208

216209
Host is moving to new time
217210
After running Timeout callback:: count: 0
@@ -340,10 +333,10 @@ export class C
340333

341334

342335
Timeout callback:: count: 1
343-
4: timerToUpdateProgram *new*
336+
2: timerToUpdateProgram *new*
344337

345338
Before running Timeout callback:: count: 1
346-
4: timerToUpdateProgram
339+
2: timerToUpdateProgram
347340

348341
Host is moving to new time
349342
After running Timeout callback:: count: 0
@@ -472,10 +465,10 @@ export class C
472465

473466

474467
Timeout callback:: count: 1
475-
5: timerToUpdateProgram *new*
468+
3: timerToUpdateProgram *new*
476469

477470
Before running Timeout callback:: count: 1
478-
5: timerToUpdateProgram
471+
3: timerToUpdateProgram
479472

480473
Host is moving to new time
481474
After running Timeout callback:: count: 0

tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependenciesAndD/deepImportChanges/errors-for-.d.ts-change.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ PolledWatches::
6969
FsWatches::
7070
/home/src/tslibs/TS/Lib/lib.d.ts: *new*
7171
{}
72-
/user/username/projects/myproject: *new*
73-
{}
7472
/user/username/projects/myproject/a.ts: *new*
7573
{}
7674
/user/username/projects/myproject/b.d.ts: *new*

tests/baselines/reference/tscWatch/emitAndErrorUpdates/default/deepImportChanges/errors-for-.d.ts-change-with-incremental.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ PolledWatches::
132132
FsWatches::
133133
/home/src/tslibs/TS/Lib/lib.d.ts: *new*
134134
{}
135-
/user/username/projects/myproject: *new*
136-
{}
137135
/user/username/projects/myproject/a.ts: *new*
138136
{}
139137
/user/username/projects/myproject/b.d.ts: *new*
@@ -147,9 +145,6 @@ FsWatchesRecursive::
147145
/user/username/projects/myproject: *new*
148146
{}
149147

150-
Timeout callback:: count: 1
151-
2: timerToInvalidateFailedLookupResolutions *new*
152-
153148
Program root files: [
154149
"/user/username/projects/myproject/a.ts",
155150
"/user/username/projects/myproject/b.d.ts",
@@ -191,13 +186,11 @@ export class C
191186
}
192187

193188

194-
Timeout callback:: count: 2
195-
2: timerToInvalidateFailedLookupResolutions
196-
3: timerToUpdateProgram *new*
189+
Timeout callback:: count: 1
190+
1: timerToUpdateProgram *new*
197191

198-
Before running Timeout callback:: count: 2
199-
2: timerToInvalidateFailedLookupResolutions
200-
3: timerToUpdateProgram
192+
Before running Timeout callback:: count: 1
193+
1: timerToUpdateProgram
201194

202195
Host is moving to new time
203196
After running Timeout callback:: count: 0
@@ -337,10 +330,10 @@ export class C
337330

338331

339332
Timeout callback:: count: 1
340-
4: timerToUpdateProgram *new*
333+
2: timerToUpdateProgram *new*
341334

342335
Before running Timeout callback:: count: 1
343-
4: timerToUpdateProgram
336+
2: timerToUpdateProgram
344337

345338
Host is moving to new time
346339
After running Timeout callback:: count: 0
@@ -461,10 +454,10 @@ export class C
461454

462455

463456
Timeout callback:: count: 1
464-
5: timerToUpdateProgram *new*
457+
3: timerToUpdateProgram *new*
465458

466459
Before running Timeout callback:: count: 1
467-
5: timerToUpdateProgram
460+
3: timerToUpdateProgram
468461

469462
Host is moving to new time
470463
After running Timeout callback:: count: 0

tests/baselines/reference/tscWatch/emitAndErrorUpdates/default/deepImportChanges/errors-for-.d.ts-change.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ PolledWatches::
6565
FsWatches::
6666
/home/src/tslibs/TS/Lib/lib.d.ts: *new*
6767
{}
68-
/user/username/projects/myproject: *new*
69-
{}
7068
/user/username/projects/myproject/a.ts: *new*
7169
{}
7270
/user/username/projects/myproject/b.d.ts: *new*

0 commit comments

Comments
 (0)