keep order more stable when sorting, add diagnostic message to inform about limit, #9826
This commit is contained in:
parent
df03c156b5
commit
fe8bb5b484
|
@ -4,13 +4,14 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import {localize} from 'vs/nls';
|
||||
import {IThreadService} from 'vs/workbench/services/thread/common/threadService';
|
||||
import {IMarkerData} from 'vs/platform/markers/common/markers';
|
||||
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';
|
||||
import {DiagnosticSeverity} from './extHostTypes';
|
||||
|
||||
export class DiagnosticCollection implements vscode.DiagnosticCollection {
|
||||
|
||||
|
@ -98,12 +99,28 @@ 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);
|
||||
marker = [];
|
||||
const sorted = diagnostics.slice(0).sort(Diagnostic.compare);
|
||||
for (let i = 0; i < DiagnosticCollection._maxDiagnosticsPerFile; i++) {
|
||||
marker.push(DiagnosticCollection._toMarkerData(sorted[i]));
|
||||
const order = [DiagnosticSeverity.Error, DiagnosticSeverity.Warning, DiagnosticSeverity.Information, DiagnosticSeverity.Hint];
|
||||
orderLoop: for (let i = 0; i < 4; i++) {
|
||||
for (const diagnostic of diagnostics) {
|
||||
if (diagnostic.severity === order[i]) {
|
||||
const len = marker.push(DiagnosticCollection._toMarkerData(diagnostic));
|
||||
if (len === DiagnosticCollection._maxDiagnosticsPerFile) {
|
||||
break orderLoop;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add 'signal' marker for showing omitted errors/warnings
|
||||
marker.push({
|
||||
severity: Severity.Error,
|
||||
message: localize('limitHit', "Not showing {0} further errors and warnings.", diagnostics.length - DiagnosticCollection._maxDiagnosticsPerFile),
|
||||
startLineNumber: marker[marker.length - 1].startLineNumber,
|
||||
startColumn: marker[marker.length - 1].startColumn,
|
||||
endLineNumber: marker[marker.length - 1].endLineNumber,
|
||||
endColumn: marker[marker.length - 1].endColumn
|
||||
});
|
||||
} else {
|
||||
marker = diagnostics.map(DiagnosticCollection._toMarkerData);
|
||||
}
|
||||
|
|
|
@ -552,17 +552,6 @@ 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 {
|
||||
|
|
|
@ -181,8 +181,9 @@ suite('ExtHostDiagnostics', () => {
|
|||
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].length, 251);
|
||||
assert.equal(lastEntries[0][1][0].severity, Severity.Error);
|
||||
assert.equal(lastEntries[0][1][200].severity, Severity.Warning);
|
||||
assert.equal(lastEntries[0][1][250].severity, Severity.Error);
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue