Skip to content

Commit dbbadcd

Browse files
committed
don't merge diagnostics with old data, fixes microsoft#11547
1 parent 63880d3 commit dbbadcd

2 files changed

Lines changed: 48 additions & 11 deletions

File tree

src/vs/workbench/api/node/extHostDiagnostics.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {localize} from 'vs/nls';
88
import {IThreadService} from 'vs/workbench/services/thread/common/threadService';
99
import {IMarkerData} from 'vs/platform/markers/common/markers';
1010
import URI from 'vs/base/common/uri';
11+
import {compare} from 'vs/base/common/strings';
1112
import Severity from 'vs/base/common/severity';
1213
import * as vscode from 'vscode';
1314
import {MainContext, MainThreadDiagnosticsShape, ExtHostDiagnosticsShape} from './extHost.protocol';
@@ -72,20 +73,23 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection {
7273
} else if (Array.isArray(first)) {
7374
// update many rows
7475
toSync = [];
75-
for (let entry of first) {
76-
let [uri, diagnostics] = entry;
77-
toSync.push(uri);
76+
let lastUri: vscode.Uri;
77+
for (const entry of first.slice(0).sort(DiagnosticCollection._compareTuplesByUri)) {
78+
const [uri, diagnostics] = entry;
79+
if (!lastUri || uri.toString() !== lastUri.toString()) {
80+
if (lastUri && this._data[lastUri.toString()].length === 0) {
81+
delete this._data[lastUri.toString()];
82+
}
83+
lastUri = uri;
84+
toSync.push(uri);
85+
this._data[uri.toString()] = [];
86+
}
87+
7888
if (!diagnostics) {
7989
// [Uri, undefined] means clear this
80-
delete this._data[uri.toString()];
90+
this._data[uri.toString()].length = 0;
8191
} else {
82-
// set or merge diagnostics
83-
let existing = this._data[uri.toString()];
84-
if (existing) {
85-
existing.push(...diagnostics);
86-
} else {
87-
this._data[uri.toString()] = diagnostics;
88-
}
92+
this._data[uri.toString()].push(...diagnostics);
8993
}
9094
}
9195
}
@@ -196,6 +200,10 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection {
196200
default: return Severity.Error;
197201
}
198202
}
203+
204+
private static _compareTuplesByUri(a: [vscode.Uri, vscode.Diagnostic[]], b: [vscode.Uri, vscode.Diagnostic[]]): number {
205+
return compare(a[0].toString(), b[0].toString());
206+
}
199207
}
200208

201209
export class ExtHostDiagnostics extends ExtHostDiagnosticsShape {

src/vs/workbench/test/node/api/extHostDiagnostics.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,35 @@ suite('ExtHostDiagnostics', () => {
159159
collection.dispose();
160160
});
161161

162+
test('diagnostics collection, set tuple overrides, #11547', function () {
163+
164+
let lastEntries: [URI, IMarkerData[]][];
165+
let collection = new DiagnosticCollection('test', new class extends DiagnosticsShape {
166+
$changeMany(owner: string, entries: [URI, IMarkerData[]][]): TPromise<any> {
167+
lastEntries = entries;
168+
return super.$changeMany(owner, entries);
169+
}
170+
});
171+
let uri = URI.parse('sc:hightower');
172+
173+
collection.set([[uri, [new Diagnostic(new Range(0, 0, 1, 1), 'error')]]]);
174+
assert.equal(collection.get(uri).length, 1);
175+
assert.equal(collection.get(uri)[0].message, 'error');
176+
assert.equal(lastEntries.length, 1);
177+
let [[, data1]] = lastEntries;
178+
assert.equal(data1.length, 1);
179+
assert.equal(data1[0].message, 'error');
180+
lastEntries = undefined;
181+
182+
collection.set([[uri, [new Diagnostic(new Range(0, 0, 1, 1), 'warning')]]]);
183+
assert.equal(collection.get(uri).length, 1);
184+
assert.equal(collection.get(uri)[0].message, 'warning');
185+
assert.equal(lastEntries.length, 1);
186+
let [[, data2]] = lastEntries;
187+
assert.equal(data2.length, 1);
188+
assert.equal(data2[0].message, 'warning');
189+
lastEntries = undefined;
190+
});
162191

163192
test('diagnostic capping', function () {
164193

0 commit comments

Comments
 (0)