Skip to content

Commit b771223

Browse files
committed
Do not check for ambient module to determine if resolution should be watched.
1 parent 7591c06 commit b771223

11 files changed

+66
-38
lines changed

src/compiler/checker.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,11 +1794,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
17941794
tryGetMemberInModuleExports: (name, symbol) => tryGetMemberInModuleExports(escapeLeadingUnderscores(name), symbol),
17951795
tryGetMemberInModuleExportsAndProperties: (name, symbol) => tryGetMemberInModuleExportsAndProperties(escapeLeadingUnderscores(name), symbol),
17961796
tryFindAmbientModule: moduleName => tryFindAmbientModule(moduleName, /*withAugmentations*/ true),
1797-
tryFindAmbientModuleWithoutAugmentations: moduleName => {
1798-
// we deliberately exclude augmentations
1799-
// since we are only interested in declarations of the module itself
1800-
return tryFindAmbientModule(moduleName, /*withAugmentations*/ false);
1801-
},
18021797
getApparentType,
18031798
getUnionType,
18041799
isTypeAssignableTo,

src/compiler/resolutionCache.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
CompilerOptions,
77
createModeAwareCache,
88
createModuleResolutionCache,
9-
createMultiMap,
109
createTypeReferenceDirectiveResolutionCache,
1110
createTypeReferenceResolutionLoader,
1211
Debug,
@@ -598,7 +597,7 @@ export function createResolutionCache(
598597
rootDirForResolution: string,
599598
): ResolutionCache {
600599
let filesWithInvalidatedResolutions: Set<Path> | undefined;
601-
const nonRelativeExternalModuleResolutions = createMultiMap<string, ResolutionWithFailedLookupLocations>();
600+
const nonRelativeExternalModuleResolutions = new Set<ResolutionWithFailedLookupLocations>();
602601

603602
const resolutionsWithFailedLookups = new Set<ResolutionWithFailedLookupLocations>();
604603
const resolutionsWithOnlyAffectingLocations = new Set<ResolutionWithFailedLookupLocations>();
@@ -775,8 +774,7 @@ export function createResolutionCache(
775774
libraryResolutionCache.clearAllExceptPackageJsonInfoCache();
776775
// perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update
777776
// (between startCachingPerDirectoryResolution and finishCachingPerDirectoryResolution)
778-
nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
779-
nonRelativeExternalModuleResolutions.clear();
777+
watchFailedLookupLocationOfNonRelativeModuleResolutions();
780778
isSymlinkCache.clear();
781779
}
782780

@@ -798,8 +796,7 @@ export function createResolutionCache(
798796
resolutionsWithGlobalCachePassAreInvalidated = false;
799797
resolutionsWithoutGlobalCachePassAreInvalidated = false;
800798
unresolvedResolutionsWithGlobalCachePassAreInvalidated = false;
801-
nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
802-
nonRelativeExternalModuleResolutions.clear();
799+
watchFailedLookupLocationOfNonRelativeModuleResolutions();
803800
// Update file watches
804801
if (newProgram !== oldProgram) {
805802
cleanupLibResolutionWatching(newProgram);
@@ -1111,7 +1108,7 @@ export function createResolutionCache(
11111108
watchFailedLookupLocationOfResolution(resolution);
11121109
}
11131110
else {
1114-
nonRelativeExternalModuleResolutions.add(name, resolution);
1111+
nonRelativeExternalModuleResolutions.add(resolution);
11151112
}
11161113
const resolved = getResolutionWithResolvedFileName(resolution);
11171114
if (resolved && resolved.resolvedFileName) {
@@ -1244,14 +1241,9 @@ export function createResolutionCache(
12441241
packageJsonMap?.delete(resolutionHost.toPath(path));
12451242
}
12461243

1247-
function watchFailedLookupLocationOfNonRelativeModuleResolutions(resolutions: ResolutionWithFailedLookupLocations[], name: string) {
1248-
const program = resolutionHost.getCurrentProgram();
1249-
if (!program || !program.getTypeChecker().tryFindAmbientModuleWithoutAugmentations(name)) {
1250-
resolutions.forEach(watchFailedLookupLocationOfResolution);
1251-
}
1252-
else {
1253-
resolutions.forEach(resolution => watchAffectingLocationsOfResolution(resolution, /*addToResolutionsWithOnlyAffectingLocations*/ true));
1254-
}
1244+
function watchFailedLookupLocationOfNonRelativeModuleResolutions() {
1245+
nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfResolution);
1246+
nonRelativeExternalModuleResolutions.clear();
12551247
}
12561248

12571249
function createDirectoryWatcherForPackageDir(

src/compiler/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5200,7 +5200,6 @@ export interface TypeChecker {
52005200
/** @internal */ createIndexInfo(keyType: Type, type: Type, isReadonly: boolean, declaration?: SignatureDeclaration): IndexInfo;
52015201
/** @internal */ isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node | undefined, meaning: SymbolFlags, shouldComputeAliasToMarkVisible: boolean): SymbolAccessibilityResult;
52025202
/** @internal */ tryFindAmbientModule(moduleName: string): Symbol | undefined;
5203-
/** @internal */ tryFindAmbientModuleWithoutAugmentations(moduleName: string): Symbol | undefined;
52045203

52055204
/** @internal */ getSymbolWalker(accept?: (symbol: Symbol) => boolean): SymbolWalker;
52065205

src/testRunner/unittests/helpers/tscWatch.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ export interface TscWatchCompileChange<T extends ts.BuilderProgram = ts.EmitAndS
4040
programs: readonly CommandLineProgram[],
4141
watchOrSolution: WatchOrSolution<T>,
4242
) => void;
43-
// TODO:: sheetal: Needing these fields are technically issues that need to be fixed later
44-
skipStructureCheck?: true;
4543
}
4644
export interface TscWatchCheckOptions {
4745
baselineSourceMap?: boolean;
@@ -214,7 +212,7 @@ export function runWatchBaseline<T extends ts.BuilderProgram = ts.EmitAndSemanti
214212
});
215213

216214
if (edits) {
217-
for (const { caption, edit, timeouts, skipStructureCheck } of edits) {
215+
for (const { caption, edit, timeouts } of edits) {
218216
applyEdit(sys, baseline, edit, caption);
219217
timeouts(sys, programs, watchOrSolution);
220218
programs = watchBaseline({
@@ -225,7 +223,7 @@ export function runWatchBaseline<T extends ts.BuilderProgram = ts.EmitAndSemanti
225223
baselineSourceMap,
226224
baselineDependencies,
227225
caption,
228-
resolutionCache: !skipStructureCheck ? (watchOrSolution as ts.WatchOfConfigFile<T> | undefined)?.getResolutionCache?.() : undefined,
226+
resolutionCache: (watchOrSolution as ts.WatchOfConfigFile<T> | undefined)?.getResolutionCache?.(),
229227
useSourceOfProjectReferenceRedirect,
230228
});
231229
}

src/testRunner/unittests/tscWatch/resolutionCache.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,6 @@ declare module "fs" {
302302
`,
303303
),
304304
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
305-
// This is currently issue with ambient modules in same file not leading to resolution watching
306-
// In this case initially resolution is watched and will continued to be watched but
307-
// incremental check will determine that the resolution should not be watched as thats what would have happened if we had started tsc --watch at this state.
308-
skipStructureCheck: true,
309305
},
310306
],
311307
});

src/testRunner/unittests/tsserver/resolutionCache.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,8 @@ export const x = 10;`,
549549
const host = createServerHost(files);
550550
const session = new TestSession(host);
551551
openFilesForSession([{ file: srcFile.path, content: srcFile.content, scriptKindName: "TS", projectRootPath: "/user/username/projects/myproject" }], session);
552+
host.writeFile("/user/username/projects/myproject/src/somefolder/module1.js", "export const x = 10;");
553+
host.runQueuedTimeoutCallbacks();
552554
baselineTsserverLogs("resolutionCache", scenario, session);
553555
});
554556
}

tests/baselines/reference/tscWatch/resolutionCache/works-when-module-resolution-changes-to-ambient-module.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,10 @@ Output::
143143
//// [/users/username/projects/project/foo.js] file written with same contents
144144

145145
PolledWatches::
146-
/users/username/projects/node_modules/@types:
147-
{"pollingInterval":500}
148-
149-
PolledWatches *deleted*::
150146
/users/username/projects/node_modules:
151147
{"pollingInterval":500}
148+
/users/username/projects/node_modules/@types:
149+
{"pollingInterval":500}
152150

153151
FsWatches::
154152
/a/lib/lib.d.ts:
@@ -161,12 +159,10 @@ FsWatches::
161159
{}
162160

163161
FsWatchesRecursive::
164-
/users/username/projects/project/node_modules/@types:
165-
{}
166-
167-
FsWatchesRecursive *deleted*::
168162
/users/username/projects/project/node_modules:
169163
{}
164+
/users/username/projects/project/node_modules/@types:
165+
{}
170166

171167
Timeout callback:: count: 0
172168
16: timerToInvalidateFailedLookupResolutions *deleted*

tests/baselines/reference/tsserver/completions/works-when-files-are-included-from-two-different-drives-of-windows.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: e:/myproject/node
142142
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: e:/myproject/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations
143143
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: c:/typescript/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations
144144
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: c:/typescript/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations
145-
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: c:/typescript/node_modules/@types/react/package.json 2000 undefined Project: /dev/null/inferredProject1* WatchType: File location affecting resolution
146145
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: e:/myproject/node_modules/react-router-dom/package.json 2000 undefined Project: /dev/null/inferredProject1* WatchType: File location affecting resolution
147146
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: c:/typescript/node_modules/@types/react-router-dom/package.json 2000 undefined Project: /dev/null/inferredProject1* WatchType: File location affecting resolution
147+
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: c:/typescript/node_modules/@types/react/package.json 2000 undefined Project: /dev/null/inferredProject1* WatchType: File location affecting resolution
148148
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: e:/myproject/src/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots
149149
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: e:/myproject/src/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots
150150
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: e:/myproject/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots

tests/baselines/reference/tsserver/projectErrors/correct-errors-when-resolution-resolves-to-file-that-has-same-ambient-module-and-is-also-module.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /us
7777
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /users/username/projects/myproject/node_modules 1 undefined Project: /users/username/projects/myproject/tsconfig.json WatchType: Failed Lookup Locations
7878
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /users/username/projects/myproject/node_modules 1 undefined Project: /users/username/projects/myproject/tsconfig.json WatchType: Failed Lookup Locations
7979
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /a/lib/lib.d.ts 500 undefined WatchType: Closed Script info
80+
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /users/username/projects/myproject/src 1 undefined Project: /users/username/projects/myproject/tsconfig.json WatchType: Failed Lookup Locations
81+
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /users/username/projects/myproject/src 1 undefined Project: /users/username/projects/myproject/tsconfig.json WatchType: Failed Lookup Locations
8082
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /users/username/projects/myproject/node_modules/@types 1 undefined Project: /users/username/projects/myproject/tsconfig.json WatchType: Type roots
8183
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /users/username/projects/myproject/node_modules/@types 1 undefined Project: /users/username/projects/myproject/tsconfig.json WatchType: Type roots
8284
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /users/username/projects/node_modules/@types 1 undefined Project: /users/username/projects/myproject/tsconfig.json WatchType: Type roots

tests/baselines/reference/tsserver/resolutionCache/when-resolution-fails.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,21 @@ ScriptInfos::
289289
version: Text-1
290290
containingProjects: 1
291291
/user/username/projects/myproject/src/tsconfig.json
292+
293+
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Triggered with /user/username/projects/myproject/src/somefolder/module1.js :: WatchInfo: /user/username/projects/myproject/src/somefolder 1 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Failed Lookup Locations
294+
Info seq [hh:mm:ss:mss] Scheduled: /user/username/projects/myproject/src/tsconfig.jsonFailedLookupInvalidation
295+
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Triggered with /user/username/projects/myproject/src/somefolder/module1.js :: WatchInfo: /user/username/projects/myproject/src/somefolder 1 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Failed Lookup Locations
296+
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Triggered with /user/username/projects/myproject/src/somefolder/module1.js :: WatchInfo: /user/username/projects/myproject/src 1 undefined Config: /user/username/projects/myproject/src/tsconfig.json WatchType: Wild card directory
297+
Info seq [hh:mm:ss:mss] Project: /user/username/projects/myproject/src/tsconfig.json Detected file add/remove of non supported extension: /user/username/projects/myproject/src/somefolder/module1.js
298+
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Triggered with /user/username/projects/myproject/src/somefolder/module1.js :: WatchInfo: /user/username/projects/myproject/src 1 undefined Config: /user/username/projects/myproject/src/tsconfig.json WatchType: Wild card directory
299+
Before running Timeout callback:: count: 1
300+
1: /user/username/projects/myproject/src/tsconfig.jsonFailedLookupInvalidation
301+
//// [/user/username/projects/myproject/src/somefolder/module1.js]
302+
export const x = 10;
303+
304+
305+
Timeout callback:: count: 1
306+
1: /user/username/projects/myproject/src/tsconfig.jsonFailedLookupInvalidation *new*
307+
308+
Info seq [hh:mm:ss:mss] Running: /user/username/projects/myproject/src/tsconfig.jsonFailedLookupInvalidation
309+
After running Timeout callback:: count: 0

tests/baselines/reference/tsserver/resolutionCache/when-resolves-to-ambient-module.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/username/pr
120120
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/node_modules 1 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Failed Lookup Locations
121121
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/src/typings 1 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Failed Lookup Locations
122122
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/src/typings 1 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Failed Lookup Locations
123+
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject 0 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Failed Lookup Locations
124+
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject 0 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Failed Lookup Locations
125+
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects 0 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Failed Lookup Locations
126+
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects 0 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Failed Lookup Locations
127+
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/src 0 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Failed Lookup Locations
128+
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/src 0 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Failed Lookup Locations
123129
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/src/typings 1 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Type roots
124130
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/src/typings 1 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Type roots
125131
Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /user/username/projects/myproject/src/tsconfig.json projectStateVersion: 1 projectProgramVersion: 0 structureChanged: true structureIsReused:: Not Elapsed:: *ms
@@ -252,6 +258,12 @@ PolledWatches::
252258
FsWatches::
253259
/a/lib/lib.d.ts: *new*
254260
{}
261+
/user/username/projects: *new*
262+
{}
263+
/user/username/projects/myproject: *new*
264+
{}
265+
/user/username/projects/myproject/src: *new*
266+
{}
255267
/user/username/projects/myproject/src/somefolder/module1.ts: *new*
256268
{}
257269
/user/username/projects/myproject/src/tsconfig.json: *new*
@@ -295,3 +307,21 @@ ScriptInfos::
295307
version: Text-1
296308
containingProjects: 1
297309
/user/username/projects/myproject/src/tsconfig.json
310+
311+
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Triggered with /user/username/projects/myproject/src/somefolder/module1.js :: WatchInfo: /user/username/projects/myproject/src/somefolder 1 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Failed Lookup Locations
312+
Info seq [hh:mm:ss:mss] Scheduled: /user/username/projects/myproject/src/tsconfig.jsonFailedLookupInvalidation
313+
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Triggered with /user/username/projects/myproject/src/somefolder/module1.js :: WatchInfo: /user/username/projects/myproject/src/somefolder 1 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Failed Lookup Locations
314+
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Triggered with /user/username/projects/myproject/src/somefolder/module1.js :: WatchInfo: /user/username/projects/myproject/src 1 undefined Config: /user/username/projects/myproject/src/tsconfig.json WatchType: Wild card directory
315+
Info seq [hh:mm:ss:mss] Project: /user/username/projects/myproject/src/tsconfig.json Detected file add/remove of non supported extension: /user/username/projects/myproject/src/somefolder/module1.js
316+
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Triggered with /user/username/projects/myproject/src/somefolder/module1.js :: WatchInfo: /user/username/projects/myproject/src 1 undefined Config: /user/username/projects/myproject/src/tsconfig.json WatchType: Wild card directory
317+
Before running Timeout callback:: count: 1
318+
1: /user/username/projects/myproject/src/tsconfig.jsonFailedLookupInvalidation
319+
//// [/user/username/projects/myproject/src/somefolder/module1.js]
320+
export const x = 10;
321+
322+
323+
Timeout callback:: count: 1
324+
1: /user/username/projects/myproject/src/tsconfig.jsonFailedLookupInvalidation *new*
325+
326+
Info seq [hh:mm:ss:mss] Running: /user/username/projects/myproject/src/tsconfig.jsonFailedLookupInvalidation
327+
After running Timeout callback:: count: 0

0 commit comments

Comments
 (0)