Skip to content

Commit 51b65b3

Browse files
committed
Add noGetErrOnBackgroundUpdate session option to not queue diagnostics check for open files
This will ensure that the getErr will be queued in by host and hence would make sure that it is cancellable. Handles one of the scenario delaying completions in #19458
1 parent 440291e commit 51b65b3

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7445,10 +7445,17 @@ namespace ts.projectSystem {
74457445
});
74467446

74477447
describe("when event handler is not set but session is created with canUseEvents = true", () => {
7448-
verifyProjectsUpdatedInBackgroundEvent(createSessionThatUsesEvents);
7448+
describe("without noGetErrOnBackgroundUpdate, diagnostics for open files are queued", () => {
7449+
verifyProjectsUpdatedInBackgroundEvent(createSessionThatUsesEvents);
7450+
});
7451+
7452+
describe("with noGetErrOnBackgroundUpdate, diagnostics for open file are not queued", () => {
7453+
verifyProjectsUpdatedInBackgroundEvent(host => createSessionThatUsesEvents(host, /*noGetErrOnBackgroundUpdate*/ true));
7454+
});
74497455

7450-
function createSessionThatUsesEvents(host: TestServerHost): ProjectsUpdatedInBackgroundEventVerifier {
7451-
const session = createSession(host, { canUseEvents: true });
7456+
7457+
function createSessionThatUsesEvents(host: TestServerHost, noGetErrOnBackgroundUpdate?: boolean): ProjectsUpdatedInBackgroundEventVerifier {
7458+
const session = createSession(host, { canUseEvents: true, noGetErrOnBackgroundUpdate });
74527459

74537460
return {
74547461
session,
@@ -7480,6 +7487,10 @@ namespace ts.projectSystem {
74807487

74817488
// Verified the events, reset them
74827489
session.clearMessages();
7490+
7491+
if (events.length) {
7492+
host.checkTimeoutQueueLength(noGetErrOnBackgroundUpdate ? 0 : 1); // Error checking queued only if not noGetErrOnBackgroundUpdate
7493+
}
74837494
}
74847495
}
74857496
});

src/server/server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ namespace ts.server {
505505
canUseEvents: true,
506506
suppressDiagnosticEvents,
507507
syntaxOnly,
508+
noGetErrOnBackgroundUpdate,
508509
globalPlugins,
509510
pluginProbeLocations,
510511
allowLocalPluginLoads,
@@ -939,6 +940,7 @@ namespace ts.server {
939940
const suppressDiagnosticEvents = hasArgument("--suppressDiagnosticEvents");
940941
const syntaxOnly = hasArgument("--syntaxOnly");
941942
const telemetryEnabled = hasArgument(Arguments.EnableTelemetry);
943+
const noGetErrOnBackgroundUpdate = hasArgument("--noGetErrOnBackgroundUpdate");
942944

943945
logger.info(`Starting TS Server`);
944946
logger.info(`Version: ${version}`);

src/server/session.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ namespace ts.server {
295295
suppressDiagnosticEvents?: boolean;
296296
syntaxOnly?: boolean;
297297
throttleWaitMilliseconds?: number;
298+
noGetErrOnBackgroundUpdate?: boolean;
298299

299300
globalPlugins?: ReadonlyArray<string>;
300301
pluginProbeLocations?: ReadonlyArray<string>;
@@ -319,6 +320,7 @@ namespace ts.server {
319320
protected canUseEvents: boolean;
320321
private suppressDiagnosticEvents?: boolean;
321322
private eventHandler: ProjectServiceEventHandler;
323+
private readonly noGetErrOnBackgroundUpdate?: boolean;
322324

323325
constructor(opts: SessionOptions) {
324326
this.host = opts.host;
@@ -329,6 +331,7 @@ namespace ts.server {
329331
this.logger = opts.logger;
330332
this.canUseEvents = opts.canUseEvents;
331333
this.suppressDiagnosticEvents = opts.suppressDiagnosticEvents;
334+
this.noGetErrOnBackgroundUpdate = opts.noGetErrOnBackgroundUpdate;
332335

333336
const { throttleWaitMilliseconds } = opts;
334337

@@ -404,7 +407,7 @@ namespace ts.server {
404407
private projectsUpdatedInBackgroundEvent(openFiles: string[]): void {
405408
this.projectService.logger.info(`got projects updated in background, updating diagnostics for ${openFiles}`);
406409
if (openFiles.length) {
407-
if (!this.suppressDiagnosticEvents) {
410+
if (!this.suppressDiagnosticEvents && !this.noGetErrOnBackgroundUpdate) {
408411
const checkList = this.createCheckList(openFiles);
409412

410413
// For now only queue error checking for open files. We can change this to include non open files as well

0 commit comments

Comments
 (0)