From c2472024239a7d23bae91f8d6abb85c49910b4c0 Mon Sep 17 00:00:00 2001 From: Vincent Fugnitto Date: Fri, 6 Sep 2019 11:20:57 -0400 Subject: [PATCH] Fix false positive problem tabbar decorators Fixes #6109 - fixes an issue where problem tabbar decorators wrongly display false positives - with the change, only `error` and `warning` decorators are displayed in the tabbar which is consistent with the problem decorators present in the explorer - with the change, only one decorator (max severity) is ever decorated (no need for unnecessary rendering) Signed-off-by: Vincent Fugnitto --- .../problem/problem-tabbar-decorator.ts | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/packages/markers/src/browser/problem/problem-tabbar-decorator.ts b/packages/markers/src/browser/problem/problem-tabbar-decorator.ts index 56a13347fb36d..33de77b77790c 100644 --- a/packages/markers/src/browser/problem/problem-tabbar-decorator.ts +++ b/packages/markers/src/browser/problem/problem-tabbar-decorator.ts @@ -15,7 +15,7 @@ ********************************************************************************/ import { inject, injectable, postConstruct } from 'inversify'; -import { Diagnostic } from 'vscode-languageserver-types'; +import { Diagnostic, DiagnosticSeverity } from 'vscode-languageserver-types'; import { Event, Emitter } from '@theia/core/lib/common/event'; import { Title, Widget } from '@phosphor/widgets'; import { WidgetDecoration } from '@theia/core/lib/browser/widget-decoration'; @@ -49,9 +49,27 @@ export class ProblemTabBarDecorator implements TabBarDecorator { if (Navigatable.is(widget)) { const resourceUri = widget.getResourceUri(); if (resourceUri) { - return this.problemManager.findMarkers({ - uri: resourceUri - }).map(marker => this.toDecorator(marker)); + // Get the list of problem markers for the given resource URI. + const markers: Marker[] = this.problemManager.findMarkers({ uri: resourceUri }); + // If no markers are available, return early. + if (markers.length === 0) { + return []; + } + // Store the marker with the highest severity. + let maxSeverity: Marker | undefined; + // Iterate over available markers to determine that which has the highest severity. + // Only display a decoration if an error or warning marker is available. + for (const marker of markers) { + // Break early if an error marker is present, since it represents the highest severity. + if (marker.data.severity === DiagnosticSeverity.Error) { + maxSeverity = marker; + break; + } else if (marker.data.severity === DiagnosticSeverity.Warning) { + maxSeverity = marker; + } + } + // Decorate the tabbar with the highest marker severity if available. + return maxSeverity ? [this.toDecorator(maxSeverity)] : []; } } return [];