merge tuples of equal Uri, #6373

This commit is contained in:
Johannes Rieken 2016-05-17 11:22:28 +02:00
parent bc3837edef
commit 4458bdf5c0
2 changed files with 61 additions and 1 deletions

View file

@ -79,6 +79,55 @@ suite('languages namespace tests', () => {
collection.dispose();
});
test('diagnostics collection, set with dupliclated tuples', function () {
let collection = languages.createDiagnosticCollection('test');
let uri = Uri.parse('sc:hightower');
collection.set([
[uri, [new Diagnostic(new Range(0, 0, 0, 1), 'message-1')]],
[Uri.parse('some:thing'), [new Diagnostic(new Range(0, 0, 1, 1), 'something')]],
[uri, [new Diagnostic(new Range(0, 0, 0, 1), 'message-2')]],
]);
let array = collection.get(uri);
assert.equal(array.length, 2);
let [first, second] = array;
assert.equal(first.message, 'message-1');
assert.equal(second.message, 'message-2');
// clear
collection.delete(uri);
assert.ok(!collection.has(uri));
// bad tuple clears 1/2
collection.set([
[uri, [new Diagnostic(new Range(0, 0, 0, 1), 'message-1')]],
[Uri.parse('some:thing'), [new Diagnostic(new Range(0, 0, 1, 1), 'something')]],
[uri, undefined]
]);
assert.ok(!collection.has(uri));
// clear
collection.delete(uri);
assert.ok(!collection.has(uri));
// bad tuple clears 2/2
collection.set([
[uri, [new Diagnostic(new Range(0, 0, 0, 1), 'message-1')]],
[Uri.parse('some:thing'), [new Diagnostic(new Range(0, 0, 1, 1), 'something')]],
[uri, undefined],
[uri, [new Diagnostic(new Range(0, 0, 0, 1), 'message-2')]],
[uri, [new Diagnostic(new Range(0, 0, 0, 1), 'message-3')]],
]);
array = collection.get(uri);
assert.equal(array.length, 2);
[first, second] = array;
assert.equal(first.message, 'message-2');
assert.equal(second.message, 'message-3');
collection.dispose();
});
test('diagnostics & CodeActionProvider', function (done) {
class D2 extends Diagnostic {

View file

@ -72,8 +72,19 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection {
toSync = [];
for (let entry of first) {
let [uri, diagnostics] = entry;
this._data[uri.toString()] = diagnostics;
toSync.push(uri);
if (!diagnostics) {
// [Uri, undefined] means clear this
delete this._data[uri.toString()];
} else {
// set or merge diagnostics
let existing = this._data[uri.toString()];
if (existing) {
existing.push(...diagnostics);
} else {
this._data[uri.toString()] = diagnostics;
}
}
}
}