Skip to content

Add noGetErrOnBackgroundUpdate session option to not queue diagnostics check for open files #24298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/harness/unittests/tsserverProjectSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7445,10 +7445,17 @@ namespace ts.projectSystem {
});

describe("when event handler is not set but session is created with canUseEvents = true", () => {
verifyProjectsUpdatedInBackgroundEvent(createSessionThatUsesEvents);
describe("without noGetErrOnBackgroundUpdate, diagnostics for open files are queued", () => {
verifyProjectsUpdatedInBackgroundEvent(createSessionThatUsesEvents);
});

describe("with noGetErrOnBackgroundUpdate, diagnostics for open file are not queued", () => {
verifyProjectsUpdatedInBackgroundEvent(host => createSessionThatUsesEvents(host, /*noGetErrOnBackgroundUpdate*/ true));
});

function createSessionThatUsesEvents(host: TestServerHost): ProjectsUpdatedInBackgroundEventVerifier {
const session = createSession(host, { canUseEvents: true });

function createSessionThatUsesEvents(host: TestServerHost, noGetErrOnBackgroundUpdate?: boolean): ProjectsUpdatedInBackgroundEventVerifier {
const session = createSession(host, { canUseEvents: true, noGetErrOnBackgroundUpdate });

return {
session,
Expand Down Expand Up @@ -7480,6 +7487,10 @@ namespace ts.projectSystem {

// Verified the events, reset them
session.clearMessages();

if (events.length) {
host.checkTimeoutQueueLength(noGetErrOnBackgroundUpdate ? 0 : 1); // Error checking queued only if not noGetErrOnBackgroundUpdate
}
}
}
});
Expand Down
2 changes: 2 additions & 0 deletions src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ namespace ts.server {
canUseEvents: true,
suppressDiagnosticEvents,
syntaxOnly,
noGetErrOnBackgroundUpdate,
globalPlugins,
pluginProbeLocations,
allowLocalPluginLoads,
Expand Down Expand Up @@ -939,6 +940,7 @@ namespace ts.server {
const suppressDiagnosticEvents = hasArgument("--suppressDiagnosticEvents");
const syntaxOnly = hasArgument("--syntaxOnly");
const telemetryEnabled = hasArgument(Arguments.EnableTelemetry);
const noGetErrOnBackgroundUpdate = hasArgument("--noGetErrOnBackgroundUpdate");

logger.info(`Starting TS Server`);
logger.info(`Version: ${version}`);
Expand Down
5 changes: 4 additions & 1 deletion src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ namespace ts.server {
suppressDiagnosticEvents?: boolean;
syntaxOnly?: boolean;
throttleWaitMilliseconds?: number;
noGetErrOnBackgroundUpdate?: boolean;

globalPlugins?: ReadonlyArray<string>;
pluginProbeLocations?: ReadonlyArray<string>;
Expand All @@ -319,6 +320,7 @@ namespace ts.server {
protected canUseEvents: boolean;
private suppressDiagnosticEvents?: boolean;
private eventHandler: ProjectServiceEventHandler;
private readonly noGetErrOnBackgroundUpdate?: boolean;

constructor(opts: SessionOptions) {
this.host = opts.host;
Expand All @@ -329,6 +331,7 @@ namespace ts.server {
this.logger = opts.logger;
this.canUseEvents = opts.canUseEvents;
this.suppressDiagnosticEvents = opts.suppressDiagnosticEvents;
this.noGetErrOnBackgroundUpdate = opts.noGetErrOnBackgroundUpdate;

const { throttleWaitMilliseconds } = opts;

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

// For now only queue error checking for open files. We can change this to include non open files as well
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8391,6 +8391,7 @@ declare namespace ts.server {
suppressDiagnosticEvents?: boolean;
syntaxOnly?: boolean;
throttleWaitMilliseconds?: number;
noGetErrOnBackgroundUpdate?: boolean;
globalPlugins?: ReadonlyArray<string>;
pluginProbeLocations?: ReadonlyArray<string>;
allowLocalPluginLoads?: boolean;
Expand All @@ -8410,6 +8411,7 @@ declare namespace ts.server {
protected canUseEvents: boolean;
private suppressDiagnosticEvents?;
private eventHandler;
private readonly noGetErrOnBackgroundUpdate?;
constructor(opts: SessionOptions);
private sendRequestCompletedEvent;
private defaultEventHandler;
Expand Down