mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
merge tuples of equal Uri, #6373
This commit is contained in:
parent
bc3837edef
commit
4458bdf5c0
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue