Skip to content

Commit 6d543ea

Browse files
committed
Schedule update graph only if typings change
Fixes #39326
1 parent d606b70 commit 6d543ea

File tree

6 files changed

+24
-30
lines changed

6 files changed

+24
-30
lines changed

src/server/editorServices.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,6 @@ namespace ts.server {
922922
case ActionSet:
923923
// Update the typing files and update the project
924924
project.updateTypingFiles(this.typingsCache.updateTypingsForProject(response.projectName, response.compilerOptions, response.typeAcquisition, response.unresolvedImports, response.typings));
925-
this.delayUpdateProjectGraphAndEnsureProjectStructureForOpenFiles(project);
926925
return;
927926
case ActionInvalidate:
928927
// Do not clear resolution cache, there was changes detected in typings, so enque typing request and let it get us correct results

src/server/project.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,13 +1057,16 @@ namespace ts.server {
10571057

10581058
/*@internal*/
10591059
updateTypingFiles(typingFiles: SortedReadonlyArray<string>) {
1060-
enumerateInsertsAndDeletes<string, string>(typingFiles, this.typingFiles, getStringComparer(!this.useCaseSensitiveFileNames()),
1060+
if (enumerateInsertsAndDeletes<string, string>(typingFiles, this.typingFiles, getStringComparer(!this.useCaseSensitiveFileNames()),
10611061
/*inserted*/ noop,
10621062
removed => this.detachScriptInfoFromProject(removed)
1063-
);
1064-
this.typingFiles = typingFiles;
1065-
// Invalidate files with unresolved imports
1066-
this.resolutionCache.setFilesWithInvalidatedNonRelativeUnresolvedImports(this.cachedUnresolvedImportsPerFile);
1063+
)) {
1064+
// If typing files changed, then only schedule project update
1065+
this.typingFiles = typingFiles;
1066+
// Invalidate files with unresolved imports
1067+
this.resolutionCache.setFilesWithInvalidatedNonRelativeUnresolvedImports(this.cachedUnresolvedImportsPerFile);
1068+
this.projectService.delayUpdateProjectGraphAndEnsureProjectStructureForOpenFiles(this);
1069+
}
10671070
}
10681071

10691072
/* @internal */

src/testRunner/unittests/tsserver/projectErrors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ namespace ts.projectSystem {
409409
checkErrors([serverUtilities.path, app.path]);
410410

411411
function checkErrors(openFiles: [string, string]) {
412-
verifyGetErrRequestNoErrors({ session, host, files: openFiles, existingTimeouts: 2 });
412+
verifyGetErrRequestNoErrors({ session, host, files: openFiles });
413413
}
414414
});
415415

src/testRunner/unittests/tsserver/projects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ namespace ts.projectSystem {
419419
unresolvedImports: response.unresolvedImports,
420420
});
421421

422-
host.checkTimeoutQueueLengthAndRun(1);
422+
host.checkTimeoutQueueLength(0);
423423
assert.isUndefined(request);
424424
});
425425

src/testRunner/unittests/tsserver/resolutionCache.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,7 @@ namespace ts.projectSystem {
198198

199199
checkNumberOfProjects(service, { inferredProjects: 1 });
200200
session.clearMessages();
201-
host.checkTimeoutQueueLengthAndRun(2);
202-
203-
checkProjectUpdatedInBackgroundEvent(session, [file.path]);
204-
201+
host.checkTimeoutQueueLength(0);
205202
verifyGetErrRequest({
206203
session,
207204
host,
@@ -240,10 +237,7 @@ namespace ts.projectSystem {
240237

241238
checkNumberOfProjects(service, { inferredProjects: 1 });
242239
session.clearMessages();
243-
host.checkTimeoutQueueLengthAndRun(2);
244-
245-
checkProjectUpdatedInBackgroundEvent(session, [file.path]);
246-
240+
host.checkTimeoutQueueLength(0);
247241
verifyGetErrRequest({
248242
session,
249243
host,

src/testRunner/unittests/tsserver/typingsInstaller.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ namespace ts.projectSystem {
244244
checkProjectActualFiles(p, [jqueryJs.path]);
245245

246246
installer.installAll(/*expectedCount*/ 0);
247-
host.checkTimeoutQueueLengthAndRun(2);
247+
host.checkTimeoutQueueLength(0);
248248
checkNumberOfProjects(projectService, { inferredProjects: 1 });
249249
// files should not be removed from project if ATA is skipped
250250
checkProjectActualFiles(p, [jqueryJs.path]);
@@ -1024,9 +1024,8 @@ namespace ts.projectSystem {
10241024
service.openClientFile(f.path);
10251025

10261026
installer.checkPendingCommands(/*expectedCount*/ 0);
1027-
10281027
host.writeFile(fixedPackageJson.path, fixedPackageJson.content);
1029-
host.checkTimeoutQueueLengthAndRun(2); // To refresh the project and refresh inferred projects
1028+
host.checkTimeoutQueueLength(0);
10301029
// expected install request
10311030
installer.installAll(/*expectedCount*/ 1);
10321031
host.checkTimeoutQueueLengthAndRun(2);
@@ -1212,7 +1211,8 @@ namespace ts.projectSystem {
12121211
}
12131212
};
12141213
session.executeCommand(changeRequest);
1215-
host.checkTimeoutQueueLengthAndRun(2); // This enqueues the updategraph and refresh inferred projects
1214+
host.checkTimeoutQueueLength(0);
1215+
proj.updateGraph();
12161216
const version2 = proj.lastCachedUnresolvedImportsList;
12171217
assert.strictEqual(version1, version2, "set of unresolved imports should change");
12181218
});
@@ -1884,8 +1884,8 @@ namespace ts.projectSystem {
18841884
}]));
18851885
host.runQueuedTimeoutCallbacks(); // Update the graph
18861886
// Update the typing
1887-
host.checkTimeoutQueueLength(2);
1888-
assert.isTrue(proj.resolutionCache.isFileWithInvalidatedNonRelativeUnresolvedImports(app.path as Path));
1887+
host.checkTimeoutQueueLength(0);
1888+
assert.isFalse(proj.resolutionCache.isFileWithInvalidatedNonRelativeUnresolvedImports(app.path as Path));
18891889
}
18901890

18911891
it("correctly invalidate the resolutions with typing names", () => {
@@ -1947,7 +1947,7 @@ declare module "stream" {
19471947
executeCommand(this, host, ["node"], [nodeTyping], cb);
19481948
}
19491949
})();
1950-
const projectService = createProjectService(host, { typingsInstaller: installer, logger: createLoggerWritingToConsole() });
1950+
const projectService = createProjectService(host, { typingsInstaller: installer });
19511951
projectService.openClientFile(file.path);
19521952
projectService.checkNumberOfProjects({ inferredProjects: 1 });
19531953

@@ -1975,11 +1975,8 @@ declare module "stream" {
19751975
host.checkTimeoutQueueLengthAndRun(2);
19761976
checkProjectActualFiles(proj, [file.path, libFile.path, nodeTyping.path]);
19771977

1978-
// Here, since typings doesnt contain node typings and resolution fails and
1979-
// node typings go out of project,
1980-
// but because we handle core node modules when resolving from typings cache
1981-
// node typings are included in the project
1982-
host.checkTimeoutQueueLengthAndRun(2);
1978+
// Here, since typings dont change, there is no timeout scheduled
1979+
host.checkTimeoutQueueLength(0);
19831980
checkProjectActualFiles(proj, [file.path, libFile.path, nodeTyping.path]);
19841981
projectService.applyChangesInOpenFiles(/*openFiles*/ undefined, arrayIterator([{
19851982
fileName: file.path,
@@ -1989,9 +1986,10 @@ declare module "stream" {
19891986
}])
19901987
}]));
19911988
proj.updateGraph(); // Update the graph
1989+
checkProjectActualFiles(proj, [file.path, libFile.path, nodeTyping.path]);
19921990
// Update the typing
1993-
host.checkTimeoutQueueLength(2);
1994-
assert.isTrue(proj.resolutionCache.isFileWithInvalidatedNonRelativeUnresolvedImports(file.path as Path));
1991+
host.checkTimeoutQueueLength(0);
1992+
assert.isFalse(proj.resolutionCache.isFileWithInvalidatedNonRelativeUnresolvedImports(file.path as Path));
19951993
});
19961994
});
19971995

0 commit comments

Comments
 (0)