Don’t try to create auto import provider when host program doesn’t exist (#45126)

* Guard against creating auto import provider without host program

* Also don’t pre-seed auto import provider if updateGraph didn’t produce a program

* Rename `isFirstLoad`
This commit is contained in:
Andrew Branch
2021-07-20 11:16:58 -07:00
committed by GitHub
parent 365b25693c
commit 31d98ec44a

View File

@@ -1070,7 +1070,7 @@ namespace ts.server {
this.lastCachedUnresolvedImportsList = undefined;
}
const isFirstLoad = this.projectProgramVersion === 0;
const isFirstProgramLoad = this.projectProgramVersion === 0 && hasNewProgram;
if (hasNewProgram) {
this.projectProgramVersion++;
}
@@ -1078,7 +1078,7 @@ namespace ts.server {
if (!this.autoImportProviderHost) this.autoImportProviderHost = undefined;
this.autoImportProviderHost?.markAsDirty();
}
if (isFirstLoad) {
if (isFirstProgramLoad) {
// Preload auto import provider so it's not created during completions request
this.getPackageJsonAutoImportProvider();
}
@@ -1902,6 +1902,11 @@ namespace ts.server {
return ts.emptyArray;
}
const program = hostProject.getCurrentProgram();
if (!program) {
return ts.emptyArray;
}
let dependencyNames: Set<string> | undefined;
let rootNames: string[] | undefined;
const rootFileName = combinePaths(hostProject.currentDirectory, inferredTypesContainingFile);
@@ -1918,7 +1923,6 @@ namespace ts.server {
compilerOptions,
moduleResolutionHost));
const program = hostProject.getCurrentProgram()!;
const symlinkCache = hostProject.getSymlinkCache();
for (const resolution of resolutions) {
if (!resolution.resolvedTypeReferenceDirective?.resolvedFileName) continue;