Use map for buffer sync support pending responses

This commit is contained in:
Matt Bierner
2017-06-14 17:06:49 -07:00
parent 3fb0d0256a
commit f37c1346b4

View File

@@ -106,7 +106,7 @@ export default class BufferSyncSupport {
private readonly disposables: Disposable[] = [];
private readonly syncedBuffers: Map<string, SyncedBuffer>;
private pendingDiagnostics: { [key: string]: number; };
private pendingDiagnostics = new Map<string, number>();
private readonly diagnosticDelayer: Delayer<any>;
private checkGlobalTSCVersion: boolean;
@@ -116,7 +116,6 @@ export default class BufferSyncSupport {
this.diagnostics = diagnostics;
this._validate = validate;
this.pendingDiagnostics = Object.create(null);
this.diagnosticDelayer = new Delayer<any>(300);
this.syncedBuffers = new Map<string, SyncedBuffer>();
@@ -211,7 +210,7 @@ export default class BufferSyncSupport {
return;
}
for (const filePath of this.syncedBuffers.keys()) {
this.pendingDiagnostics[filePath] = Date.now();
this.pendingDiagnostics.set(filePath, Date.now());
}
this.diagnosticDelayer.trigger(() => {
this.sendPendingDiagnostics();
@@ -223,7 +222,7 @@ export default class BufferSyncSupport {
return;
}
this.pendingDiagnostics[file] = Date.now();
this.pendingDiagnostics.set(file, Date.now());
const buffer = this.syncedBuffers.get(file);
let delay = 300;
if (buffer) {
@@ -239,10 +238,10 @@ export default class BufferSyncSupport {
if (!this._validate) {
return;
}
let files = Object.keys(this.pendingDiagnostics).map((key) => {
let files = Array.from(this.pendingDiagnostics.entries()).map(([key, value]) => {
return {
file: key,
time: this.pendingDiagnostics[key]
time: value
};
}).sort((a, b) => {
return a.time - b.time;
@@ -252,7 +251,7 @@ export default class BufferSyncSupport {
// Add all open TS buffers to the geterr request. They might be visible
for (const file of this.syncedBuffers.keys()) {
if (!this.pendingDiagnostics[file]) {
if (!this.pendingDiagnostics.get(file)) {
files.push(file);
}
}
@@ -264,7 +263,7 @@ export default class BufferSyncSupport {
};
this.client.execute('geterr', args, false);
}
this.pendingDiagnostics = Object.create(null);
this.pendingDiagnostics.clear();
}
private checkTSCVersion() {