diff --git a/src/vs/workbench/api/node/extHostDiagnostics.ts b/src/vs/workbench/api/node/extHostDiagnostics.ts index dab90f9e538..d73f73a8dea 100644 --- a/src/vs/workbench/api/node/extHostDiagnostics.ts +++ b/src/vs/workbench/api/node/extHostDiagnostics.ts @@ -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, marker]); diff --git a/src/vs/workbench/api/node/extHostTypes.ts b/src/vs/workbench/api/node/extHostTypes.ts index c0058a88efd..6a96eff46ce 100644 --- a/src/vs/workbench/api/node/extHostTypes.ts +++ b/src/vs/workbench/api/node/extHostTypes.ts @@ -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 { diff --git a/src/vs/workbench/test/node/api/extHostDiagnostics.test.ts b/src/vs/workbench/test/node/api/extHostDiagnostics.test.ts index ab1dd37b041..2f4e21e89ea 100644 --- a/src/vs/workbench/test/node/api/extHostDiagnostics.test.ts +++ b/src/vs/workbench/test/node/api/extHostDiagnostics.test.ts @@ -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); }); }); \ No newline at end of file