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