Skip to content

Commit 517cf6a

Browse files
committed
Add support for suppressing project events
VS doesn't consume (e.g.) `syntaxDiag` events, so there's no reason to do the work to compute their payloads.
1 parent 810b386 commit 517cf6a

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

src/server/editorServices.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ namespace ts.server {
305305
useInferredProjectPerProjectRoot: boolean;
306306
typingsInstaller: ITypingsInstaller;
307307
eventHandler?: ProjectServiceEventHandler;
308+
suppressDiagnosticEvents?: boolean;
308309
throttleWaitMilliseconds?: number;
309310
globalPlugins?: ReadonlyArray<string>;
310311
pluginProbeLocations?: ReadonlyArray<string>;
@@ -392,6 +393,7 @@ namespace ts.server {
392393
public readonly typingsInstaller: ITypingsInstaller;
393394
public readonly throttleWaitMilliseconds?: number;
394395
private readonly eventHandler?: ProjectServiceEventHandler;
396+
private readonly suppressDiagnosticEvents?: boolean;
395397

396398
public readonly globalPlugins: ReadonlyArray<string>;
397399
public readonly pluginProbeLocations: ReadonlyArray<string>;
@@ -413,6 +415,7 @@ namespace ts.server {
413415
this.typingsInstaller = opts.typingsInstaller || nullTypingsInstaller;
414416
this.throttleWaitMilliseconds = opts.throttleWaitMilliseconds;
415417
this.eventHandler = opts.eventHandler;
418+
this.suppressDiagnosticEvents = opts.suppressDiagnosticEvents;
416419
this.globalPlugins = opts.globalPlugins || emptyArray;
417420
this.pluginProbeLocations = opts.pluginProbeLocations || emptyArray;
418421
this.allowLocalPluginLoads = !!opts.allowLocalPluginLoads;
@@ -1598,7 +1601,7 @@ namespace ts.server {
15981601
}
15991602

16001603
private sendConfigFileDiagEvent(project: ConfiguredProject, triggerFile: NormalizedPath) {
1601-
if (!this.eventHandler) {
1604+
if (!this.eventHandler || this.suppressDiagnosticEvents) {
16021605
return;
16031606
}
16041607

src/server/server.ts

+2
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ namespace ts.server {
512512
hrtime: process.hrtime,
513513
logger,
514514
canUseEvents: true,
515+
suppressDiagnosticEvents,
515516
globalPlugins,
516517
pluginProbeLocations,
517518
allowLocalPluginLoads,
@@ -927,6 +928,7 @@ namespace ts.server {
927928
const useSingleInferredProject = hasArgument("--useSingleInferredProject");
928929
const useInferredProjectPerProjectRoot = hasArgument("--useInferredProjectPerProjectRoot");
929930
const disableAutomaticTypingAcquisition = hasArgument("--disableAutomaticTypingAcquisition");
931+
const suppressDiagnosticEvents = hasArgument("--suppressDiagnosticEvents");
930932
const telemetryEnabled = hasArgument(Arguments.EnableTelemetry);
931933

932934
logger.info(`Starting TS Server`);

src/server/session.ts

+21-4
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ namespace ts.server {
295295
*/
296296
canUseEvents: boolean;
297297
eventHandler?: ProjectServiceEventHandler;
298+
/** Has no effect if eventHandler is also specified. */
299+
suppressDiagnosticEvents?: boolean;
298300
throttleWaitMilliseconds?: number;
299301

300302
globalPlugins?: ReadonlyArray<string>;
@@ -318,6 +320,7 @@ namespace ts.server {
318320
protected logger: Logger;
319321

320322
protected canUseEvents: boolean;
323+
private suppressDiagnosticEvents?: boolean;
321324
private eventHandler: ProjectServiceEventHandler;
322325

323326
constructor(opts: SessionOptions) {
@@ -328,6 +331,7 @@ namespace ts.server {
328331
this.hrtime = opts.hrtime;
329332
this.logger = opts.logger;
330333
this.canUseEvents = opts.canUseEvents;
334+
this.suppressDiagnosticEvents = opts.suppressDiagnosticEvents;
331335

332336
const { throttleWaitMilliseconds } = opts;
333337

@@ -352,6 +356,7 @@ namespace ts.server {
352356
typingsInstaller: this.typingsInstaller,
353357
throttleWaitMilliseconds,
354358
eventHandler: this.eventHandler,
359+
suppressDiagnosticEvents: this.suppressDiagnosticEvents,
355360
globalPlugins: opts.globalPlugins,
356361
pluginProbeLocations: opts.pluginProbeLocations,
357362
allowLocalPluginLoads: opts.allowLocalPluginLoads
@@ -401,11 +406,12 @@ namespace ts.server {
401406
private projectsUpdatedInBackgroundEvent(openFiles: string[]): void {
402407
this.projectService.logger.info(`got projects updated in background, updating diagnostics for ${openFiles}`);
403408
if (openFiles.length) {
404-
const checkList = this.createCheckList(openFiles);
405-
406-
// For now only queue error checking for open files. We can change this to include non open files as well
407-
this.errorCheck.startNew(next => this.updateErrorCheck(next, checkList, 100, /*requireOpen*/ true));
409+
if (!this.suppressDiagnosticEvents) {
410+
const checkList = this.createCheckList(openFiles);
408411

412+
// For now only queue error checking for open files. We can change this to include non open files as well
413+
this.errorCheck.startNew(next => this.updateErrorCheck(next, checkList, 100, /*requireOpen*/ true));
414+
}
409415

410416
// Send project changed event
411417
this.event<protocol.ProjectsUpdatedInBackgroundEventBody>({
@@ -489,7 +495,10 @@ namespace ts.server {
489495
}
490496
}
491497

498+
/** It is the caller's responsibility to verify that `!this.suppressDiagnosticEvents`. */
492499
private updateErrorCheck(next: NextStep, checkList: PendingErrorCheck[], ms: number, requireOpen = true) {
500+
Debug.assert(!this.suppressDiagnosticEvents); // Caller's responsibility
501+
493502
const seq = this.changeSeq;
494503
const followMs = Math.min(ms, 200);
495504

@@ -1379,6 +1388,10 @@ namespace ts.server {
13791388
}
13801389

13811390
private getDiagnostics(next: NextStep, delay: number, fileNames: string[]): void {
1391+
if (this.suppressDiagnosticEvents) {
1392+
return;
1393+
}
1394+
13821395
const checkList = this.createCheckList(fileNames);
13831396
if (checkList.length > 0) {
13841397
this.updateErrorCheck(next, checkList, delay);
@@ -1748,6 +1761,10 @@ namespace ts.server {
17481761
}
17491762

17501763
private getDiagnosticsForProject(next: NextStep, delay: number, fileName: string): void {
1764+
if (this.suppressDiagnosticEvents) {
1765+
return;
1766+
}
1767+
17511768
const { fileNames, languageServiceDisabled } = this.getProjectInfoWorker(fileName, /*projectFileName*/ undefined, /*needFileNameList*/ true, /*excludeConfigFiles*/ true);
17521769
if (languageServiceDisabled) {
17531770
return;

0 commit comments

Comments
 (0)