sort by severity when limiting diagnostics list, #9826
This commit is contained in:
parent
db65d4aac9
commit
df03c156b5
|
@ -10,6 +10,7 @@ import URI from 'vs/base/common/uri';
|
|||
import Severity from 'vs/base/common/severity';
|
||||
import * as vscode from 'vscode';
|
||||
import {MainContext, MainThreadDiagnosticsShape, ExtHostDiagnosticsShape} from './extHost.protocol';
|
||||
import {Diagnostic} from './extHostTypes';
|
||||
|
||||
export class DiagnosticCollection implements vscode.DiagnosticCollection {
|
||||
|
||||
|
@ -98,9 +99,14 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection {
|
|||
// no more than 250 diagnostics per file
|
||||
if (diagnostics.length > DiagnosticCollection._maxDiagnosticsPerFile) {
|
||||
console.warn('diagnostics for %s will be capped to %d (actually is %d)', uri.toString(), DiagnosticCollection._maxDiagnosticsPerFile, diagnostics.length);
|
||||
diagnostics = diagnostics.slice(0, DiagnosticCollection._maxDiagnosticsPerFile);
|
||||
marker = [];
|
||||
const sorted = diagnostics.slice(0).sort(Diagnostic.compare);
|
||||
for (let i = 0; i < DiagnosticCollection._maxDiagnosticsPerFile; i++) {
|
||||
marker.push(DiagnosticCollection._toMarkerData(sorted[i]));
|
||||
}
|
||||
} else {
|
||||
marker = diagnostics.map(DiagnosticCollection._toMarkerData);
|
||||
}
|
||||
marker = diagnostics.map(DiagnosticCollection._toMarkerData);
|
||||
}
|
||||
|
||||
entries.push([<URI> uri, marker]);
|
||||
|
|
|
@ -552,6 +552,17 @@ export class Diagnostic {
|
|||
code: this.code,
|
||||
};
|
||||
}
|
||||
|
||||
static compare(a: vscode.Diagnostic, b: vscode.Diagnostic): number{
|
||||
let ret = a.severity - b.severity;
|
||||
if (ret === 0) {
|
||||
ret = a.range.start.compareTo(b.range.start);
|
||||
}
|
||||
if (ret === 0) {
|
||||
ret = a.message.localeCompare(b.message);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
export class Hover {
|
||||
|
|
|
@ -7,8 +7,9 @@
|
|||
|
||||
import * as assert from 'assert';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import Severity from 'vs/base/common/severity';
|
||||
import {DiagnosticCollection} from 'vs/workbench/api/node/extHostDiagnostics';
|
||||
import {Diagnostic, Range} from 'vs/workbench/api/node/extHostTypes';
|
||||
import {Diagnostic, DiagnosticSeverity, Range} from 'vs/workbench/api/node/extHostTypes';
|
||||
import {MainThreadDiagnosticsShape} from 'vs/workbench/api/node/extHost.protocol';
|
||||
import {TPromise} from 'vs/base/common/winjs.base';
|
||||
import {IMarkerData} from 'vs/platform/markers/common/markers';
|
||||
|
@ -170,9 +171,18 @@ suite('ExtHostDiagnostics', () => {
|
|||
});
|
||||
let uri = URI.parse('aa:bb');
|
||||
|
||||
collection.set(uri, new Array(500).map((value, i) => new Diagnostic(new Range(i, 0, i + 1, 0), `error#${i}`)));
|
||||
let diagnostics: Diagnostic[] = [];
|
||||
for (let i = 0; i < 500; i++) {
|
||||
diagnostics.push(new Diagnostic(new Range(i, 0, i + 1, 0), `error#${i}`, i < 300
|
||||
? DiagnosticSeverity.Warning
|
||||
: DiagnosticSeverity.Error));
|
||||
}
|
||||
|
||||
collection.set(uri, diagnostics);
|
||||
assert.equal(collection.get(uri).length, 500);
|
||||
assert.equal(lastEntries.length, 1);
|
||||
assert.equal(lastEntries[0][1].length, 250);
|
||||
assert.equal(lastEntries[0][1][0].severity, Severity.Error);
|
||||
assert.equal(lastEntries[0][1][200].severity, Severity.Warning);
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue