forked from github/codespaces-host-images
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbufferSyncSupport.ts
More file actions
763 lines (635 loc) · 21.7 KB
/
Copy pathbufferSyncSupport.ts
File metadata and controls
763 lines (635 loc) · 21.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import { officeScript, vscodeNotebookCell } from '../configuration/fileSchemes';
import * as languageModeIds from '../configuration/languageIds';
import * as typeConverters from '../typeConverters';
import { ClientCapability, ITypeScriptServiceClient } from '../typescriptService';
import { inMemoryResourcePrefix } from '../typescriptServiceClient';
import { coalesce } from '../utils/arrays';
import { Delayer, setImmediate } from '../utils/async';
import { nulToken } from '../utils/cancellation';
import { Disposable } from '../utils/dispose';
import { ResourceMap } from '../utils/resourceMap';
import { API } from './api';
import type * as Proto from './protocol/protocol';
type ScriptKind = 'TS' | 'TSX' | 'JS' | 'JSX';
function mode2ScriptKind(mode: string): ScriptKind | undefined {
switch (mode) {
case languageModeIds.typescript: return 'TS';
case languageModeIds.typescriptreact: return 'TSX';
case languageModeIds.javascript: return 'JS';
case languageModeIds.javascriptreact: return 'JSX';
}
return undefined;
}
const enum BufferState { Initial, Open, Closed }
const enum BufferOperationType { Close, Open, Change }
class CloseOperation {
readonly type = BufferOperationType.Close;
constructor(
public readonly args: string,
public readonly scriptKind: ScriptKind | undefined,
) { }
}
class OpenOperation {
readonly type = BufferOperationType.Open;
constructor(
public readonly args: Proto.OpenRequestArgs,
public readonly scriptKind: ScriptKind | undefined,
) { }
}
class ChangeOperation {
readonly type = BufferOperationType.Change;
constructor(
public readonly args: Proto.FileCodeEdits
) { }
}
type BufferOperation = CloseOperation | OpenOperation | ChangeOperation;
/**
* Manages synchronization of buffers with the TS server.
*
* If supported, batches together file changes. This allows the TS server to more efficiently process changes.
*/
class BufferSynchronizer {
private readonly _pending: ResourceMap<BufferOperation>;
constructor(
private readonly client: ITypeScriptServiceClient,
pathNormalizer: (path: vscode.Uri) => string | undefined,
onCaseInsensitiveFileSystem: boolean
) {
this._pending = new ResourceMap<BufferOperation>(pathNormalizer, {
onCaseInsensitiveFileSystem
});
}
public open(resource: vscode.Uri, args: Proto.OpenRequestArgs) {
if (this.supportsBatching) {
this.updatePending(resource, new OpenOperation(args, args.scriptKindName));
} else {
this.client.executeWithoutWaitingForResponse('open', args);
}
}
/**
* @return Was the buffer open?
*/
public close(resource: vscode.Uri, filepath: string, scriptKind: ScriptKind | undefined): boolean {
if (this.supportsBatching) {
return this.updatePending(resource, new CloseOperation(filepath, scriptKind));
} else {
const args: Proto.FileRequestArgs = { file: filepath };
this.client.executeWithoutWaitingForResponse('close', args);
return true;
}
}
public change(resource: vscode.Uri, filepath: string, events: readonly vscode.TextDocumentContentChangeEvent[]) {
if (!events.length) {
return;
}
if (this.supportsBatching) {
this.updatePending(resource, new ChangeOperation({
fileName: filepath,
textChanges: events.map((change): Proto.CodeEdit => ({
newText: change.text,
start: typeConverters.Position.toLocation(change.range.start),
end: typeConverters.Position.toLocation(change.range.end),
})).reverse(), // Send the edits end-of-document to start-of-document order
}));
} else {
for (const { range, text } of events) {
const args: Proto.ChangeRequestArgs = {
insertString: text,
...typeConverters.Range.toFormattingRequestArgs(filepath, range)
};
this.client.executeWithoutWaitingForResponse('change', args);
}
}
}
public reset(): void {
this._pending.clear();
}
public beforeCommand(command: string): void {
if (command === 'updateOpen') {
return;
}
this.flush();
}
private flush() {
if (!this.supportsBatching) {
// We've already eagerly synchronized
this._pending.clear();
return;
}
if (this._pending.size > 0) {
const closedFiles: string[] = [];
const openFiles: Proto.OpenRequestArgs[] = [];
const changedFiles: Proto.FileCodeEdits[] = [];
for (const change of this._pending.values()) {
switch (change.type) {
case BufferOperationType.Change: changedFiles.push(change.args); break;
case BufferOperationType.Open: openFiles.push(change.args); break;
case BufferOperationType.Close: closedFiles.push(change.args); break;
}
}
this.client.execute('updateOpen', { changedFiles, closedFiles, openFiles }, nulToken, { nonRecoverable: true });
this._pending.clear();
}
}
private get supportsBatching(): boolean {
return this.client.apiVersion.gte(API.v340);
}
private updatePending(resource: vscode.Uri, op: BufferOperation): boolean {
switch (op.type) {
case BufferOperationType.Close: {
const existing = this._pending.get(resource);
switch (existing?.type) {
case BufferOperationType.Open:
if (existing.scriptKind === op.scriptKind) {
this._pending.delete(resource);
return false; // Open then close. No need to do anything
}
}
break;
}
}
if (this._pending.has(resource)) {
// we saw this file before, make sure we flush before working with it again
this.flush();
}
this._pending.set(resource, op);
return true;
}
}
class SyncedBuffer {
private state = BufferState.Initial;
constructor(
private readonly document: vscode.TextDocument,
public readonly filepath: string,
private readonly client: ITypeScriptServiceClient,
private readonly synchronizer: BufferSynchronizer,
) { }
public open(): void {
const args: Proto.OpenRequestArgs = {
file: this.filepath,
fileContent: this.document.getText(),
projectRootPath: this.getProjectRootPath(this.document.uri),
};
const scriptKind = mode2ScriptKind(this.document.languageId);
if (scriptKind) {
args.scriptKindName = scriptKind;
}
const tsPluginsForDocument = this.client.pluginManager.plugins
.filter(x => x.languages.indexOf(this.document.languageId) >= 0);
if (tsPluginsForDocument.length) {
(args as any).plugins = tsPluginsForDocument.map(plugin => plugin.name);
}
this.synchronizer.open(this.resource, args);
this.state = BufferState.Open;
}
private getProjectRootPath(resource: vscode.Uri): string | undefined {
const workspaceRoot = this.client.getWorkspaceRootForResource(resource);
if (workspaceRoot) {
const tsRoot = this.client.toTsFilePath(workspaceRoot);
return tsRoot?.startsWith(inMemoryResourcePrefix) ? undefined : tsRoot;
}
return resource.scheme === officeScript ? '/' : undefined;
}
public get resource(): vscode.Uri {
return this.document.uri;
}
public get lineCount(): number {
return this.document.lineCount;
}
public get languageId(): string {
return this.document.languageId;
}
/**
* @return Was the buffer open?
*/
public close(): boolean {
if (this.state !== BufferState.Open) {
this.state = BufferState.Closed;
return false;
}
this.state = BufferState.Closed;
return this.synchronizer.close(this.resource, this.filepath, mode2ScriptKind(this.document.languageId));
}
public onContentChanged(events: readonly vscode.TextDocumentContentChangeEvent[]): void {
if (this.state !== BufferState.Open) {
console.error(`Unexpected buffer state: ${this.state}`);
}
this.synchronizer.change(this.resource, this.filepath, events);
}
}
class SyncedBufferMap extends ResourceMap<SyncedBuffer> {
public getForPath(filePath: string): SyncedBuffer | undefined {
return this.get(vscode.Uri.file(filePath));
}
public get allBuffers(): Iterable<SyncedBuffer> {
return this.values();
}
}
class PendingDiagnostics extends ResourceMap<number> {
public getOrderedFileSet(): ResourceMap<void> {
const orderedResources = Array.from(this.entries())
.sort((a, b) => a.value - b.value)
.map(entry => entry.resource);
const map = new ResourceMap<void>(this._normalizePath, this.config);
for (const resource of orderedResources) {
map.set(resource, undefined);
}
return map;
}
}
class GetErrRequest {
public static executeGetErrRequest(
client: ITypeScriptServiceClient,
files: ResourceMap<void>,
onDone: () => void
) {
return new GetErrRequest(client, files, onDone);
}
private _done: boolean = false;
private readonly _token: vscode.CancellationTokenSource = new vscode.CancellationTokenSource();
private constructor(
private readonly client: ITypeScriptServiceClient,
public readonly files: ResourceMap<void>,
onDone: () => void
) {
if (!this.isErrorReportingEnabled()) {
this._done = true;
setImmediate(onDone);
return;
}
const supportsSyntaxGetErr = this.client.apiVersion.gte(API.v440);
const allFiles = coalesce(Array.from(files.entries())
.filter(entry => supportsSyntaxGetErr || client.hasCapabilityForResource(entry.resource, ClientCapability.Semantic))
.map(entry => client.toTsFilePath(entry.resource)));
if (!allFiles.length) {
this._done = true;
setImmediate(onDone);
} else {
const request = this.areProjectDiagnosticsEnabled()
// Note that geterrForProject is almost certainly not the api we want here as it ends up computing far
// too many diagnostics
? client.executeAsync('geterrForProject', { delay: 0, file: allFiles[0] }, this._token.token)
: client.executeAsync('geterr', { delay: 0, files: allFiles }, this._token.token);
request.finally(() => {
if (this._done) {
return;
}
this._done = true;
onDone();
});
}
}
private isErrorReportingEnabled() {
if (this.client.apiVersion.gte(API.v440)) {
return true;
} else {
// Older TS versions only support `getErr` on semantic server
return this.client.capabilities.has(ClientCapability.Semantic);
}
}
private areProjectDiagnosticsEnabled() {
return this.client.configuration.enableProjectDiagnostics && this.client.capabilities.has(ClientCapability.Semantic);
}
public cancel(): any {
if (!this._done) {
this._token.cancel();
}
this._token.dispose();
}
}
class TabResourceTracker extends Disposable {
private readonly _onDidChange = this._register(new vscode.EventEmitter<{
readonly closed: Iterable<vscode.Uri>;
readonly opened: Iterable<vscode.Uri>;
}>());
public readonly onDidChange = this._onDidChange.event;
private readonly _tabResources: ResourceMap<{ readonly tabs: Set<vscode.Tab> }>;
constructor(
normalizePath: (resource: vscode.Uri) => string | undefined,
config: {
readonly onCaseInsensitiveFileSystem: boolean;
},
) {
super();
this._tabResources = new ResourceMap<{ readonly tabs: Set<vscode.Tab> }>(normalizePath, config);
for (const tabGroup of vscode.window.tabGroups.all) {
for (const tab of tabGroup.tabs) {
this.add(tab);
}
}
this._register(vscode.window.tabGroups.onDidChangeTabs(e => {
const closed = e.closed.flatMap(tab => this.delete(tab));
const opened = e.opened.flatMap(tab => this.add(tab));
if (closed.length || opened.length) {
this._onDidChange.fire({ closed, opened });
}
}));
}
public has(resource: vscode.Uri): boolean {
if (resource.scheme === vscodeNotebookCell) {
const notebook = vscode.workspace.notebookDocuments.find(doc =>
doc.getCells().some(cell => cell.document.uri.toString() === resource.toString()));
return !!notebook && this.has(notebook.uri);
}
const entry = this._tabResources.get(resource);
return !!entry && entry.tabs.size > 0;
}
private add(tab: vscode.Tab): vscode.Uri[] {
const addedResources: vscode.Uri[] = [];
for (const uri of this.getResourcesForTab(tab)) {
const entry = this._tabResources.get(uri);
if (entry) {
entry.tabs.add(tab);
} else {
this._tabResources.set(uri, { tabs: new Set([tab]) });
addedResources.push(uri);
}
}
return addedResources;
}
private delete(tab: vscode.Tab): vscode.Uri[] {
const closedResources: vscode.Uri[] = [];
for (const uri of this.getResourcesForTab(tab)) {
const entry = this._tabResources.get(uri);
if (!entry) {
continue;
}
entry.tabs.delete(tab);
if (entry.tabs.size === 0) {
this._tabResources.delete(uri);
closedResources.push(uri);
}
}
return closedResources;
}
private getResourcesForTab(tab: vscode.Tab): vscode.Uri[] {
if (tab.input instanceof vscode.TabInputText) {
return [tab.input.uri];
} else if (tab.input instanceof vscode.TabInputTextDiff) {
return [tab.input.original, tab.input.modified];
} else if (tab.input instanceof vscode.TabInputNotebook) {
return [tab.input.uri];
} else {
return [];
}
}
}
export default class BufferSyncSupport extends Disposable {
private readonly client: ITypeScriptServiceClient;
private _validateJavaScript = true;
private _validateTypeScript = true;
private readonly modeIds: Set<string>;
private readonly syncedBuffers: SyncedBufferMap;
private readonly pendingDiagnostics: PendingDiagnostics;
private readonly diagnosticDelayer: Delayer<any>;
private pendingGetErr: GetErrRequest | undefined;
private listening: boolean = false;
private readonly synchronizer: BufferSynchronizer;
private readonly _tabResources: TabResourceTracker;
constructor(
client: ITypeScriptServiceClient,
modeIds: readonly string[],
onCaseInsensitiveFileSystem: boolean
) {
super();
this.client = client;
this.modeIds = new Set<string>(modeIds);
this.diagnosticDelayer = new Delayer<any>(300);
const pathNormalizer = (path: vscode.Uri) => this.client.toTsFilePath(path);
this.syncedBuffers = new SyncedBufferMap(pathNormalizer, { onCaseInsensitiveFileSystem });
this.pendingDiagnostics = new PendingDiagnostics(pathNormalizer, { onCaseInsensitiveFileSystem });
this.synchronizer = new BufferSynchronizer(client, pathNormalizer, onCaseInsensitiveFileSystem);
this._tabResources = this._register(new TabResourceTracker(pathNormalizer, { onCaseInsensitiveFileSystem }));
this._register(this._tabResources.onDidChange(e => {
if (this.client.configuration.enableProjectDiagnostics) {
return;
}
for (const closed of e.closed) {
const syncedBuffer = this.syncedBuffers.get(closed);
if (syncedBuffer) {
this.pendingDiagnostics.delete(closed);
this.pendingGetErr?.files.delete(closed);
}
}
for (const opened of e.opened) {
const syncedBuffer = this.syncedBuffers.get(opened);
if (syncedBuffer) {
this.requestDiagnostic(syncedBuffer);
}
}
}));
this.updateConfiguration();
vscode.workspace.onDidChangeConfiguration(this.updateConfiguration, this, this._disposables);
}
private readonly _onDelete = this._register(new vscode.EventEmitter<vscode.Uri>());
public readonly onDelete = this._onDelete.event;
private readonly _onWillChange = this._register(new vscode.EventEmitter<vscode.Uri>());
public readonly onWillChange = this._onWillChange.event;
public listen(): void {
if (this.listening) {
return;
}
this.listening = true;
vscode.workspace.onDidOpenTextDocument(this.openTextDocument, this, this._disposables);
vscode.workspace.onDidCloseTextDocument(this.onDidCloseTextDocument, this, this._disposables);
vscode.workspace.onDidChangeTextDocument(this.onDidChangeTextDocument, this, this._disposables);
vscode.window.onDidChangeVisibleTextEditors(e => {
for (const { document } of e) {
const syncedBuffer = this.syncedBuffers.get(document.uri);
if (syncedBuffer) {
this.requestDiagnostic(syncedBuffer);
}
}
}, this, this._disposables);
vscode.workspace.textDocuments.forEach(this.openTextDocument, this);
}
public handles(resource: vscode.Uri): boolean {
return this.syncedBuffers.has(resource);
}
public ensureHasBuffer(resource: vscode.Uri): boolean {
if (this.syncedBuffers.has(resource)) {
return true;
}
const existingDocument = vscode.workspace.textDocuments.find(doc => doc.uri.toString() === resource.toString());
if (existingDocument) {
return this.openTextDocument(existingDocument);
}
return false;
}
public toVsCodeResource(resource: vscode.Uri): vscode.Uri {
const filepath = this.client.toTsFilePath(resource);
for (const buffer of this.syncedBuffers.allBuffers) {
if (buffer.filepath === filepath) {
return buffer.resource;
}
}
return resource;
}
public toResource(filePath: string): vscode.Uri {
const buffer = this.syncedBuffers.getForPath(filePath);
if (buffer) {
return buffer.resource;
}
return vscode.Uri.file(filePath);
}
public reset(): void {
this.pendingGetErr?.cancel();
this.pendingDiagnostics.clear();
this.synchronizer.reset();
}
public reinitialize(): void {
this.reset();
for (const buffer of this.syncedBuffers.allBuffers) {
buffer.open();
}
}
public openTextDocument(document: vscode.TextDocument): boolean {
if (!this.modeIds.has(document.languageId)) {
return false;
}
const resource = document.uri;
const filepath = this.client.toTsFilePath(resource);
if (!filepath) {
return false;
}
if (this.syncedBuffers.has(resource)) {
return true;
}
const syncedBuffer = new SyncedBuffer(document, filepath, this.client, this.synchronizer);
this.syncedBuffers.set(resource, syncedBuffer);
syncedBuffer.open();
this.requestDiagnostic(syncedBuffer);
return true;
}
public closeResource(resource: vscode.Uri): void {
const syncedBuffer = this.syncedBuffers.get(resource);
if (!syncedBuffer) {
return;
}
this.pendingDiagnostics.delete(resource);
this.pendingGetErr?.files.delete(resource);
this.syncedBuffers.delete(resource);
const wasBufferOpen = syncedBuffer.close();
this._onDelete.fire(resource);
if (wasBufferOpen) {
this.requestAllDiagnostics();
}
}
public interruptGetErr<R>(f: () => R): R {
if (!this.pendingGetErr
|| this.client.configuration.enableProjectDiagnostics // `geterr` happens on separate server so no need to cancel it.
) {
return f();
}
this.pendingGetErr.cancel();
this.pendingGetErr = undefined;
const result = f();
this.triggerDiagnostics();
return result;
}
public beforeCommand(command: string): void {
this.synchronizer.beforeCommand(command);
}
private onDidCloseTextDocument(document: vscode.TextDocument): void {
this.closeResource(document.uri);
}
private onDidChangeTextDocument(e: vscode.TextDocumentChangeEvent): void {
const syncedBuffer = this.syncedBuffers.get(e.document.uri);
if (!syncedBuffer) {
return;
}
this._onWillChange.fire(syncedBuffer.resource);
syncedBuffer.onContentChanged(e.contentChanges);
const didTrigger = this.requestDiagnostic(syncedBuffer);
if (!didTrigger && this.pendingGetErr) {
// In this case we always want to re-trigger all diagnostics
this.pendingGetErr.cancel();
this.pendingGetErr = undefined;
this.triggerDiagnostics();
}
}
public requestAllDiagnostics() {
for (const buffer of this.syncedBuffers.allBuffers) {
if (this.shouldValidate(buffer)) {
this.pendingDiagnostics.set(buffer.resource, Date.now());
}
}
this.triggerDiagnostics();
}
public getErr(resources: readonly vscode.Uri[]): any {
const handledResources = resources.filter(resource => this.handles(resource));
if (!handledResources.length) {
return;
}
for (const resource of handledResources) {
this.pendingDiagnostics.set(resource, Date.now());
}
this.triggerDiagnostics();
}
private triggerDiagnostics(delay: number = 200) {
this.diagnosticDelayer.trigger(() => {
this.sendPendingDiagnostics();
}, delay);
}
private requestDiagnostic(buffer: SyncedBuffer): boolean {
if (!this.shouldValidate(buffer)) {
return false;
}
this.pendingDiagnostics.set(buffer.resource, Date.now());
const delay = Math.min(Math.max(Math.ceil(buffer.lineCount / 20), 300), 800);
this.triggerDiagnostics(delay);
return true;
}
public hasPendingDiagnostics(resource: vscode.Uri): boolean {
return this.pendingDiagnostics.has(resource);
}
private sendPendingDiagnostics(): void {
const orderedFileSet = this.pendingDiagnostics.getOrderedFileSet();
if (this.pendingGetErr) {
this.pendingGetErr.cancel();
for (const { resource } of this.pendingGetErr.files.entries()) {
if (this.syncedBuffers.get(resource)) {
orderedFileSet.set(resource, undefined);
}
}
this.pendingGetErr = undefined;
}
// Add all open TS buffers to the geterr request. They might be visible
for (const buffer of this.syncedBuffers.values()) {
orderedFileSet.set(buffer.resource, undefined);
}
if (orderedFileSet.size) {
const getErr = this.pendingGetErr = GetErrRequest.executeGetErrRequest(this.client, orderedFileSet, () => {
if (this.pendingGetErr === getErr) {
this.pendingGetErr = undefined;
}
});
}
this.pendingDiagnostics.clear();
}
private updateConfiguration() {
const jsConfig = vscode.workspace.getConfiguration('javascript', null);
const tsConfig = vscode.workspace.getConfiguration('typescript', null);
this._validateJavaScript = jsConfig.get<boolean>('validate.enable', true);
this._validateTypeScript = tsConfig.get<boolean>('validate.enable', true);
}
private shouldValidate(buffer: SyncedBuffer): boolean {
if (!this.client.configuration.enableProjectDiagnostics && !this._tabResources.has(buffer.resource)) { // Only validate resources that are showing to the user
return false;
}
switch (buffer.languageId) {
case languageModeIds.javascript:
case languageModeIds.javascriptreact:
return this._validateJavaScript;
case languageModeIds.typescript:
case languageModeIds.typescriptreact:
default:
return this._validateTypeScript;
}
}
}