Eagerly resolve module specifiers for auto-import completions in --moduleResolution node12+ (#48752)

* Add failing test

* Block auto-import module specifiers including node_modules path

* Eagerly resolve module specifiers in completions in nodenext so failures can be filtered

* Add completion info flags for telemetry

* Update API baseline

* Update completions baselines

* Fix missed boolean flip

* Fix remaining tests
This commit is contained in:
Andrew Branch
2022-04-27 16:07:15 -07:00
committed by GitHub
parent 717a1be3c9
commit 476fc625df
26 changed files with 239 additions and 73 deletions
@@ -52,6 +52,7 @@ namespace ts.projectSystem {
assert.isString(exportMapKey);
delete (response?.entries[0].data as any).exportMapKey;
assert.deepEqual<protocol.CompletionInfo | undefined>(response, {
flags: CompletionInfoFlags.MayIncludeAutoImports,
isGlobalCompletion: true,
isIncomplete: undefined,
isMemberCompletion: false,
@@ -77,6 +77,7 @@ namespace ts.projectSystem {
command: protocol.CommandTypes.CompletionInfo,
arguments: completionRequestArgs
}, {
flags: 0,
isGlobalCompletion: false,
isMemberCompletion: true,
isNewIdentifierLocation: false,
@@ -39,7 +39,7 @@ namespace ts.projectSystem {
describe("unittests:: tsserver:: moduleSpecifierCache", () => {
it("caches importability within a file", () => {
const { moduleSpecifierCache } = setup();
assert.isTrue(moduleSpecifierCache.get(bTs.path as Path, aTs.path as Path, {}, {})?.isAutoImportable);
assert.isFalse(moduleSpecifierCache.get(bTs.path as Path, aTs.path as Path, {}, {})?.isBlockedByPackageJsonDependencies);
});
it("caches module specifiers within a file", () => {
@@ -54,7 +54,7 @@ namespace ts.projectSystem {
isRedirect: false
}],
moduleSpecifiers: ["mobx"],
isAutoImportable: true,
isBlockedByPackageJsonDependencies: false,
});
});
@@ -72,7 +72,7 @@ namespace ts.projectSystem {
const { host, moduleSpecifierCache } = setup();
host.writeFile("/src/a2.ts", aTs.content);
host.runQueuedTimeoutCallbacks();
assert.isTrue(moduleSpecifierCache.get(bTs.path as Path, aTs.path as Path, {}, {})?.isAutoImportable);
assert.isFalse(moduleSpecifierCache.get(bTs.path as Path, aTs.path as Path, {}, {})?.isBlockedByPackageJsonDependencies);
});
it("invalidates the cache when symlinks are added or removed", () => {