Skip to content

Commit

Permalink
fix eclipse-theia#6084: optimize problem status rendering
Browse files Browse the repository at this point in the history
- debounce status update
- travers all markers only once, not for each Uri and then for each severity

Signed-off-by: Anton Kosyakov <[email protected]>
  • Loading branch information
akosyakov committed Sep 4, 2019
1 parent 5b366f6 commit 6bb0a25
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
8 changes: 4 additions & 4 deletions packages/markers/src/browser/problem/problem-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import debounce = require('lodash.debounce');
import { injectable, inject } from 'inversify';
import { FrontendApplication, FrontendApplicationContribution, CompositeTreeNode, SelectableTreeNode, Widget } from '@theia/core/lib/browser';
import { StatusBar, StatusBarAlignment } from '@theia/core/lib/browser/status-bar/status-bar';
Expand Down Expand Up @@ -70,16 +71,15 @@ export class ProblemContribution extends AbstractViewContribution<ProblemWidget>
}

onStart(app: FrontendApplication): void {
this.setStatusBarElement(this.problemManager.getProblemStat());
this.problemManager.onDidChangeMarkers(() => {
this.setStatusBarElement(this.problemManager.getProblemStat());
});
this.updateStatusBarElement();
this.problemManager.onDidChangeMarkers(this.updateStatusBarElement);
}

async initializeLayout(app: FrontendApplication): Promise<void> {
await this.openView();
}

protected updateStatusBarElement = debounce(() => this.setStatusBarElement(this.problemManager.getProblemStat()), 10);
protected setStatusBarElement(problemStat: ProblemStat): void {
this.statusBar.setElement('problem-marker-status', {
text: problemStat.infos <= 0
Expand Down
21 changes: 11 additions & 10 deletions packages/markers/src/browser/problem/problem-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import { injectable } from 'inversify';
import { MarkerManager } from '../marker-manager';
import { PROBLEM_KIND } from '../../common/problem-marker';
import { Marker } from '../../common/marker';
import URI from '@theia/core/lib/common/uri';
import { Diagnostic } from 'vscode-languageserver-types';

export interface ProblemStat {
Expand All @@ -35,15 +33,18 @@ export class ProblemManager extends MarkerManager<Diagnostic> {
}

getProblemStat(): ProblemStat {
const allMarkers: Marker<Diagnostic>[] = [];
for (const uri of this.getUris()) {
allMarkers.push(...this.findMarkers({ uri: new URI(uri) }));
let errors = 0;
let warnings = 0;
let infos = 0;
for (const marker of this.findMarkers()) {
if (marker.data.severity === 1) {
errors++;
} else if (marker.data.severity === 2) {
warnings++;
} else if (marker.data.severity === 3) {
infos++;
}
}

const errors = allMarkers.filter(m => m.data.severity === 1).length;
const warnings = allMarkers.filter(m => m.data.severity === 2).length;
const infos = allMarkers.filter(m => m.data.severity === 3).length;

return { errors, warnings, infos };
}

Expand Down

0 comments on commit 6bb0a25

Please sign in to comment.