Skip to content

Commit 35abe26

Browse files
committed
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)
1 parent c9479f7 commit 35abe26

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/compiler/core.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2987,18 +2987,19 @@ namespace ts {
29872987
}
29882988

29892989
/** Remove the *first* occurrence of `item` from the array. */
2990-
export function unorderedRemoveItem<T>(array: T[], item: T): void {
2990+
export function unorderedRemoveItem<T>(array: T[], item: T) {
29912991
unorderedRemoveFirstItemWhere(array, element => element === item);
29922992
}
29932993

29942994
/** Remove the *first* element satisfying `predicate`. */
2995-
function unorderedRemoveFirstItemWhere<T>(array: T[], predicate: (element: T) => boolean): void {
2995+
function unorderedRemoveFirstItemWhere<T>(array: T[], predicate: (element: T) => boolean) {
29962996
for (let i = 0; i < array.length; i++) {
29972997
if (predicate(array[i])) {
29982998
unorderedRemoveItemAt(array, i);
2999-
break;
2999+
return true;
30003000
}
30013001
}
3002+
return false;
30023003
}
30033004

30043005
export type GetCanonicalFileName = (fileName: string) => string;

src/server/project.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ namespace ts.server {
9292
cachedUnresolvedImportsPerFile = createMap<ReadonlyArray<string>>();
9393
/*@internal*/
9494
lastCachedUnresolvedImportsList: SortedReadonlyArray<string>;
95+
/*@internal*/
96+
hasMoreOrLessScriptInfos = false;
9597

9698
private lastFileExceededProgramSize: string | undefined;
9799

@@ -777,6 +779,8 @@ namespace ts.server {
777779
this.resolutionCache.startRecordingFilesWithChangedResolutions();
778780

779781
let hasChanges = this.updateGraphWorker();
782+
const hasMoreOrLessScriptInfos = this.hasMoreOrLessScriptInfos;
783+
this.hasMoreOrLessScriptInfos = false;
780784

781785
const changedFiles: ReadonlyArray<Path> = this.resolutionCache.finishRecordingFilesWithChangedResolutions() || emptyArray;
782786

@@ -803,7 +807,7 @@ namespace ts.server {
803807
this.lastCachedUnresolvedImportsList = toDeduplicatedSortedArray(result);
804808
}
805809

806-
const cachedTypings = this.projectService.typingsCache.getTypingsForProject(this, this.lastCachedUnresolvedImportsList, hasChanges);
810+
const cachedTypings = this.projectService.typingsCache.getTypingsForProject(this, this.lastCachedUnresolvedImportsList, hasMoreOrLessScriptInfos);
807811
if (!arrayIsEqualTo(this.typingFiles, cachedTypings)) {
808812
this.typingFiles = cachedTypings;
809813
this.markAsDirty();

src/server/scriptInfo.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ namespace ts.server {
304304
const isNew = !this.isAttached(project);
305305
if (isNew) {
306306
this.containingProjects.push(project);
307+
project.hasMoreOrLessScriptInfos = true;
307308
if (!project.getCompilerOptions().preserveSymlinks) {
308309
this.ensureRealPath();
309310
}
@@ -328,19 +329,24 @@ namespace ts.server {
328329
return;
329330
case 1:
330331
if (this.containingProjects[0] === project) {
332+
project.hasMoreOrLessScriptInfos = true;
331333
this.containingProjects.pop();
332334
}
333335
break;
334336
case 2:
335337
if (this.containingProjects[0] === project) {
338+
project.hasMoreOrLessScriptInfos = true;
336339
this.containingProjects[0] = this.containingProjects.pop();
337340
}
338341
else if (this.containingProjects[1] === project) {
342+
project.hasMoreOrLessScriptInfos = true;
339343
this.containingProjects.pop();
340344
}
341345
break;
342346
default:
343-
unorderedRemoveItem(this.containingProjects, project);
347+
if (unorderedRemoveItem(this.containingProjects, project)) {
348+
project.hasMoreOrLessScriptInfos = true;
349+
}
344350
break;
345351
}
346352
}

0 commit comments

Comments
 (0)