Skip to content

Commit

Permalink
Don’t try to create auto import provider when host program doesn’t ex…
Browse files Browse the repository at this point in the history
…ist (#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`
  • Loading branch information
andrewbranch authored Jul 20, 2021
1 parent 365b256 commit 31d98ec
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/server/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1070,15 +1070,15 @@ namespace ts.server {
this.lastCachedUnresolvedImportsList = undefined;
}

const isFirstLoad = this.projectProgramVersion === 0;
const isFirstProgramLoad = this.projectProgramVersion === 0 && hasNewProgram;
if (hasNewProgram) {
this.projectProgramVersion++;
}
if (hasAddedorRemovedFiles) {
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();
}
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 31d98ec

Please sign in to comment.