Skip to content

Commit

Permalink
Fix false positive problem tabbar decorators
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
vince-fugnitto committed Sep 9, 2019
1 parent c5757df commit 6fba326
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions packages/markers/src/browser/problem/problem-tabbar-decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<Diagnostic>[] = 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<Diagnostic> | 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 [];
Expand Down

0 comments on commit 6fba326

Please sign in to comment.