Skip to content

Commit 8b047c6

Browse files
committed
Dont watch resolutions in dynamic files
1 parent b6eafc0 commit 8b047c6

File tree

4 files changed

+35
-44
lines changed

4 files changed

+35
-44
lines changed

src/compiler/resolutionCache.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ export interface ResolutionCacheHost extends MinimalResolutionCacheHost {
199199
fileIsOpen(filePath: Path): boolean;
200200
onDiscoveredSymlink?(): void;
201201

202+
skipWatchingFailedLookups?(path: Path): boolean | undefined;
203+
202204
// For incremental testing
203205
beforeResolveSingleModuleNameWithoutWatching?(
204206
moduleResolutionCache: ModuleResolutionCache,
@@ -895,7 +897,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
895897
resolutionHost.onDiscoveredSymlink();
896898
}
897899
resolutionsInFile.set(name, mode, resolution);
898-
if (resolution !== existingResolution) {
900+
if (resolution !== existingResolution && !resolutionHost.skipWatchingFailedLookups?.(path)) {
899901
watchFailedLookupLocationsOfExternalModuleResolutions(name, resolution, path, getResolutionWithResolvedFileName, deferWatchingNonRelativeResolution);
900902
if (existingResolution) {
901903
stopWatchFailedLookupLocationOfResolution(existingResolution, path, getResolutionWithResolvedFileName);
@@ -921,10 +923,10 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
921923
Diagnostics.Reusing_resolution_of_module_0_from_1_of_old_program_it_was_successfully_resolved_to_2 :
922924
Diagnostics.Reusing_resolution_of_module_0_from_1_of_old_program_it_was_not_resolved :
923925
resolved?.resolvedFileName ?
924-
resolved.packageId ?
925-
Diagnostics.Reusing_resolution_of_type_reference_directive_0_from_1_of_old_program_it_was_successfully_resolved_to_2_with_Package_ID_3 :
926-
Diagnostics.Reusing_resolution_of_type_reference_directive_0_from_1_of_old_program_it_was_successfully_resolved_to_2 :
927-
Diagnostics.Reusing_resolution_of_type_reference_directive_0_from_1_of_old_program_it_was_not_resolved,
926+
resolved.packageId ?
927+
Diagnostics.Reusing_resolution_of_type_reference_directive_0_from_1_of_old_program_it_was_successfully_resolved_to_2_with_Package_ID_3 :
928+
Diagnostics.Reusing_resolution_of_type_reference_directive_0_from_1_of_old_program_it_was_successfully_resolved_to_2 :
929+
Diagnostics.Reusing_resolution_of_type_reference_directive_0_from_1_of_old_program_it_was_not_resolved,
928930
name,
929931
containingFile,
930932
resolved?.resolvedFileName,
@@ -947,7 +949,9 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
947949
// Stop watching and remove the unused name
948950
resolutionsInFile.forEach((resolution, name, mode) => {
949951
if (!seenNamesInFile.has(name, mode)) {
950-
stopWatchFailedLookupLocationOfResolution(resolution, path, getResolutionWithResolvedFileName);
952+
if (!resolutionHost.skipWatchingFailedLookups?.(path)) {
953+
stopWatchFailedLookupLocationOfResolution(resolution, path, getResolutionWithResolvedFileName);
954+
}
951955
resolutionsInFile.delete(name, mode);
952956
}
953957
});
@@ -1434,13 +1438,15 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
14341438
// Deleted file, stop watching failed lookups for all the resolutions in the file
14351439
const resolutions = cache.get(filePath);
14361440
if (resolutions) {
1437-
resolutions.forEach(resolution =>
1438-
stopWatchFailedLookupLocationOfResolution(
1439-
resolution,
1440-
filePath,
1441-
getResolutionWithResolvedFileName,
1442-
)
1443-
);
1441+
if (!resolutionHost.skipWatchingFailedLookups?.(filePath)) {
1442+
resolutions.forEach(resolution =>
1443+
stopWatchFailedLookupLocationOfResolution(
1444+
resolution,
1445+
filePath,
1446+
getResolutionWithResolvedFileName,
1447+
)
1448+
);
1449+
}
14441450
cache.delete(filePath);
14451451
}
14461452
}

src/harness/incrementalUtils.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ interface ResolutionInfo {
107107
fileName: string;
108108
name: string;
109109
mode: ts.ResolutionMode;
110+
watched: boolean;
110111
}
111112

112113
function getResolutionCacheDetails<File, T extends ts.ResolutionWithFailedLookupLocations>(
@@ -254,8 +255,8 @@ export function verifyResolutionCache(
254255
// Verify ref count
255256
resolutionToRefs.forEach((info, resolution) => {
256257
ts.Debug.assert(
257-
resolution.files?.size === info.length,
258-
`${projectName}:: Expected Resolution ref count ${info.length} but got ${resolution.files?.size}`,
258+
(resolution.files?.size ?? 0) === info.filter(i => i.watched).length,
259+
`${projectName}:: Expected Resolution ref count ${info.filter(i => i.watched).length} but got ${resolution.files?.size}`,
259260
() =>
260261
`Expected from:: ${JSON.stringify(info, undefined, " ")}` +
261262
`Actual from: ${resolution.files?.size}`,
@@ -317,12 +318,13 @@ export function verifyResolutionCache(
317318
): ExpectedResolution {
318319
const existing = resolutionToRefs.get(resolved);
319320
let expectedResolution: ExpectedResolution;
321+
const watched = !resolutionHostCacheHost.skipWatchingFailedLookups?.(fileName);
320322
if (existing) {
321-
existing.push({ cacheType, fileName, name, mode });
323+
existing.push({ cacheType, fileName, name, mode, watched });
322324
expectedResolution = resolutionToExpected.get(resolved)!;
323325
}
324326
else {
325-
resolutionToRefs.set(resolved, [{ cacheType, fileName, name, mode }]);
327+
resolutionToRefs.set(resolved, [{ cacheType, fileName, name, mode, watched }]);
326328
expectedResolution = {
327329
resolvedModule: (resolved as any).resolvedModule,
328330
resolvedTypeReferenceDirective: (resolved as any).resolvedTypeReferenceDirective,
@@ -333,7 +335,9 @@ export function verifyResolutionCache(
333335
expectedToResolution.set(expectedResolution, resolved);
334336
resolutionToExpected.set(resolved, expectedResolution);
335337
}
336-
expected.watchFailedLookupLocationsOfExternalModuleResolutions(name, expectedResolution, fileName, () => ({ resolvedFileName }), deferWatchingNonRelativeResolution);
338+
if (watched) {
339+
expected.watchFailedLookupLocationsOfExternalModuleResolutions(name, expectedResolution, fileName, () => ({ resolvedFileName }), deferWatchingNonRelativeResolution);
340+
}
337341
return expectedResolution;
338342
}
339343

@@ -527,6 +531,7 @@ function verifyProgram(service: ts.server.ProjectService, project: ts.server.Pro
527531
getGlobalTypingsCacheLocation: project.getGlobalTypingsCacheLocation.bind(project),
528532
globalCacheResolutionModuleName: project.globalCacheResolutionModuleName.bind(project),
529533
fileIsOpen: project.fileIsOpen.bind(project),
534+
skipWatchingFailedLookups: project.skipWatchingFailedLookups.bind(project),
530535
getCurrentProgram: () => project.getCurrentProgram(),
531536

532537
preferNonRecursiveWatch: project.preferNonRecursiveWatch,

src/server/project.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,12 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
16261626
});
16271627
}
16281628

1629+
/** @internal */
1630+
skipWatchingFailedLookups(path: Path): boolean | undefined {
1631+
const info = this.projectService.getScriptInfoForPath(path);
1632+
return info?.isDynamic;
1633+
}
1634+
16291635
/** @internal */
16301636
getCurrentProgram(): Program | undefined {
16311637
return this.program;

tests/baselines/reference/tsserver/dynamicFiles/chat-block-with-imports.js

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,6 @@ Info seq [hh:mm:ss:mss] request:
314314
Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: ^/vscode-chat-code-block/dnnjb2rllwnoyxqtc2vzc2lvbjovl2xvy2fsl1peag1oelv6tkdvde9uvtvnuzawtxpbnuxxstrare10tvrobfpuvtbpvgmytudwaq/response_6b1244f1-9aca-4b8b-8f65-0ff7ed4e6b4e/2#{"references":[]} ProjectRootPath: /:: Result: undefined
315315
Info seq [hh:mm:ss:mss] Creating InferredProject: /dev/null/inferredProject2*, currentDirectory: /
316316
Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /dev/null/inferredProject2*
317-
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /^/vscode-chat-code-block/dnnjb2rllwnoyxqtc2vzc2lvbjovl2xvy2fsl1peag1oelv6tkdvde9uvtvnuzawtxpbnuxxstrare10tvrobfpuvtbpvgmytudwaq 1 undefined Project: /dev/null/inferredProject2* WatchType: Failed Lookup Locations
318-
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /^/vscode-chat-code-block/dnnjb2rllwnoyxqtc2vzc2lvbjovl2xvy2fsl1peag1oelv6tkdvde9uvtvnuzawtxpbnuxxstrare10tvrobfpuvtbpvgmytudwaq 1 undefined Project: /dev/null/inferredProject2* WatchType: Failed Lookup Locations
319317
Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /dev/null/inferredProject2* projectStateVersion: 1 projectProgramVersion: 0 structureChanged: true structureIsReused:: Not Elapsed:: *ms
320318
Info seq [hh:mm:ss:mss] Project '/dev/null/inferredProject2*' (Inferred)
321319
Info seq [hh:mm:ss:mss] Files (2)
@@ -361,30 +359,6 @@ Info seq [hh:mm:ss:mss] response:
361359
}
362360
After request
363361

364-
PolledWatches::
365-
/^/vscode-chat-code-block/dnnjb2rllwnoyxqtc2vzc2lvbjovl2xvy2fsl1peag1oelv6tkdvde9uvtvnuzawtxpbnuxxstrare10tvrobfpuvtbpvgmytudwaq: *new*
366-
{"pollingInterval":500}
367-
/home/src/Vscode/Projects/bin/node_modules/@types:
368-
{"pollingInterval":500}
369-
/home/src/Vscode/Projects/node_modules/@types:
370-
{"pollingInterval":500}
371-
/home/src/Vscode/node_modules/@types:
372-
{"pollingInterval":500}
373-
/user/username/projects/myproject/node_modules/@types:
374-
{"pollingInterval":500}
375-
/user/username/projects/node_modules/@types:
376-
{"pollingInterval":500}
377-
378-
FsWatches::
379-
/home/src/tslibs/TS/Lib/lib.d.ts:
380-
{}
381-
/user/username/projects/myproject/tsconfig.json:
382-
{}
383-
384-
FsWatchesRecursive::
385-
/user/username/projects/myproject:
386-
{}
387-
388362
Projects::
389363
/dev/null/inferredProject1* (Inferred)
390364
projectStateVersion: 1

0 commit comments

Comments
 (0)