Skip to content

Commit

Permalink
Add a preference to control tree problem decorators
Browse files Browse the repository at this point in the history
Fixes #6019

- added a new preference to control whether to enable/disable
problem decorators (diagnostic markers) in tree widgets.
- updated the `problems.decorations.tabbar.enabled` preference name.

Signed-off-by: Vincent Fugnitto <vincent.fugnitto@ericsson.com>
  • Loading branch information
vince-fugnitto committed Aug 26, 2019
1 parent 530eb75 commit da3c2eb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
22 changes: 20 additions & 2 deletions packages/markers/src/browser/problem/problem-decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { inject, injectable } from 'inversify';
import { inject, injectable, postConstruct } from 'inversify';
import { Diagnostic, DiagnosticSeverity } from 'vscode-languageserver-types';
import URI from '@theia/core/lib/common/uri';
import { notEmpty } from '@theia/core/lib/common/objects';
Expand All @@ -25,10 +25,15 @@ import { TreeDecorator, TreeDecoration } from '@theia/core/lib/browser/tree/tree
import { FileStatNode } from '@theia/filesystem/lib/browser';
import { Marker } from '../../common/marker';
import { ProblemManager } from './problem-manager';
import { ProblemPreferences, ProblemConfiguration } from './problem-preferences';
import { PreferenceChangeEvent } from '@theia/core/lib/browser';

@injectable()
export class ProblemDecorator implements TreeDecorator {

@inject(ProblemPreferences)
protected problemPreferences: ProblemPreferences;

readonly id = 'theia-problem-decorator';

protected readonly emitter: Emitter<(tree: Tree) => Map<string, TreeDecoration.Data>>;
Expand All @@ -38,6 +43,16 @@ export class ProblemDecorator implements TreeDecorator {
this.problemManager.onDidChangeMarkers(() => this.fireDidChangeDecorations((tree: Tree) => this.collectDecorators(tree)));
}

@postConstruct()
protected init(): void {
this.problemPreferences.onPreferenceChanged((event: PreferenceChangeEvent<ProblemConfiguration>) => {
const { preferenceName } = event;
if (preferenceName === 'problems.decorations.enabled') {
this.fireDidChangeDecorations((tree: Tree) => this.collectDecorators(tree));
}
});
}

async decorations(tree: Tree): Promise<Map<string, TreeDecoration.Data>> {
return this.collectDecorators(tree);
}
Expand All @@ -51,8 +66,11 @@ export class ProblemDecorator implements TreeDecorator {
}

protected collectDecorators(tree: Tree): Map<string, TreeDecoration.Data> {

const result = new Map();
if (tree.root === undefined) {

// If the tree root is undefined or the preference for the decorations is disabled, return an empty result map.
if (tree.root === undefined || !this.problemPreferences['problems.decorations.enabled']) {
return result;
}
const markers = this.appendContainerMarkers(tree, this.collectMarkers(tree));
Expand Down
10 changes: 8 additions & 2 deletions packages/markers/src/browser/problem/problem-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ import { createPreferenceProxy, PreferenceProxy, PreferenceService, PreferenceCo
export const ProblemConfigSchema: PreferenceSchema = {
'type': 'object',
'properties': {
'problem.decorations.tabbar.enabled': {
'problems.decorations.enabled': {
'type': 'boolean',
'description': 'Show problem decorators (diagnostic markers) in tree widgets.',
'default': true,
},
'problems.decorations.tabbar.enabled': {
'type': 'boolean',
'description': 'Show problem decorators (diagnostic markers) in the tab bars.',
'default': true
Expand All @@ -29,7 +34,8 @@ export const ProblemConfigSchema: PreferenceSchema = {
};

export interface ProblemConfiguration {
'problem.decorations.tabbar.enabled': boolean
'problems.decorations.enabled': boolean,
'problems.decorations.tabbar.enabled': boolean
}

export const ProblemPreferences = Symbol('ProblemPreferences');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class ProblemTabBarDecorator implements TabBarDecorator {
*/
protected async handlePreferenceChange(event: PreferenceChangeEvent<ProblemConfiguration>): Promise<void> {
const { preferenceName } = event;
if (preferenceName === 'problem.decorations.tabbar.enabled') {
if (preferenceName === 'problems.decorations.tabbar.enabled') {
this.fireDidChangeDecorations();
}
}
Expand All @@ -79,7 +79,7 @@ export class ProblemTabBarDecorator implements TabBarDecorator {
*/
protected collectDecorators(titles: Title<Widget>[]): Map<string, WidgetDecoration.Data> {
const result: Map<string, Marker<Diagnostic>> = new Map();
if (this.preferences['problem.decorations.tabbar.enabled']) {
if (this.preferences['problems.decorations.tabbar.enabled']) {
const markers = this.groupMarkersByURI(this.collectMarkers());
for (const title of titles) {
// Ensure `title.caption` does not contain illegal characters for URI.
Expand Down

0 comments on commit da3c2eb

Please sign in to comment.