From 35abe268242207c58558d3e7d6077ffe09e2f779 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 12 Apr 2018 15:21:20 -0700 Subject: [PATCH] Force new typings resolution only if there are more or less script infos in the project. This helps in reducing number of forced typing installation requests We anyways use changes in unresolved import array to determine if we need to enqueue new typing request Hence there is no need to soley rely on hasChanges from updateGraph which just indicates that we didnt reused the program (that does not mean new files were added to the program or changes in unresolved imports) --- src/compiler/core.ts | 7 ++++--- src/server/project.ts | 6 +++++- src/server/scriptInfo.ts | 8 +++++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index cdf68cb2dfa..b427c689c96 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -2987,18 +2987,19 @@ namespace ts { } /** Remove the *first* occurrence of `item` from the array. */ - export function unorderedRemoveItem(array: T[], item: T): void { + export function unorderedRemoveItem(array: T[], item: T) { unorderedRemoveFirstItemWhere(array, element => element === item); } /** Remove the *first* element satisfying `predicate`. */ - function unorderedRemoveFirstItemWhere(array: T[], predicate: (element: T) => boolean): void { + function unorderedRemoveFirstItemWhere(array: T[], predicate: (element: T) => boolean) { for (let i = 0; i < array.length; i++) { if (predicate(array[i])) { unorderedRemoveItemAt(array, i); - break; + return true; } } + return false; } export type GetCanonicalFileName = (fileName: string) => string; diff --git a/src/server/project.ts b/src/server/project.ts index 23583d9c71b..47bfb03a189 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -92,6 +92,8 @@ namespace ts.server { cachedUnresolvedImportsPerFile = createMap>(); /*@internal*/ lastCachedUnresolvedImportsList: SortedReadonlyArray; + /*@internal*/ + hasMoreOrLessScriptInfos = false; private lastFileExceededProgramSize: string | undefined; @@ -777,6 +779,8 @@ namespace ts.server { this.resolutionCache.startRecordingFilesWithChangedResolutions(); let hasChanges = this.updateGraphWorker(); + const hasMoreOrLessScriptInfos = this.hasMoreOrLessScriptInfos; + this.hasMoreOrLessScriptInfos = false; const changedFiles: ReadonlyArray = this.resolutionCache.finishRecordingFilesWithChangedResolutions() || emptyArray; @@ -803,7 +807,7 @@ namespace ts.server { this.lastCachedUnresolvedImportsList = toDeduplicatedSortedArray(result); } - const cachedTypings = this.projectService.typingsCache.getTypingsForProject(this, this.lastCachedUnresolvedImportsList, hasChanges); + const cachedTypings = this.projectService.typingsCache.getTypingsForProject(this, this.lastCachedUnresolvedImportsList, hasMoreOrLessScriptInfos); if (!arrayIsEqualTo(this.typingFiles, cachedTypings)) { this.typingFiles = cachedTypings; this.markAsDirty(); diff --git a/src/server/scriptInfo.ts b/src/server/scriptInfo.ts index db56973d796..074fde298aa 100644 --- a/src/server/scriptInfo.ts +++ b/src/server/scriptInfo.ts @@ -304,6 +304,7 @@ namespace ts.server { const isNew = !this.isAttached(project); if (isNew) { this.containingProjects.push(project); + project.hasMoreOrLessScriptInfos = true; if (!project.getCompilerOptions().preserveSymlinks) { this.ensureRealPath(); } @@ -328,19 +329,24 @@ namespace ts.server { return; case 1: if (this.containingProjects[0] === project) { + project.hasMoreOrLessScriptInfos = true; this.containingProjects.pop(); } break; case 2: if (this.containingProjects[0] === project) { + project.hasMoreOrLessScriptInfos = true; this.containingProjects[0] = this.containingProjects.pop(); } else if (this.containingProjects[1] === project) { + project.hasMoreOrLessScriptInfos = true; this.containingProjects.pop(); } break; default: - unorderedRemoveItem(this.containingProjects, project); + if (unorderedRemoveItem(this.containingProjects, project)) { + project.hasMoreOrLessScriptInfos = true; + } break; } }