Skip to content

Commit

Permalink
[markers] Sync problem markers with active editor
Browse files Browse the repository at this point in the history
Fixes: #7436

Reveals and expands the markers for the active editor.
Added a preference `problems.autoReveal` to control this behavior.

Signed-off-by: Muhammad Anas Shahid <muhammad.shahid@ericsson.com>
  • Loading branch information
Anas Shahid authored and vince-fugnitto committed Jul 15, 2020
1 parent a1ea230 commit 733063d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
8 changes: 7 additions & 1 deletion packages/markers/src/browser/problem/problem-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@ export const ProblemConfigSchema: PreferenceSchema = {
'type': 'boolean',
'description': 'Show problem decorators (diagnostic markers) in the tab bars.',
'default': true
},
'problems.autoReveal': {
'type': 'boolean',
'description': 'Controls whether Problems view should reveal markers when file is opened.',
'default': true
}
}
};

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

export const ProblemPreferences = Symbol('ProblemPreferences');
Expand Down
50 changes: 47 additions & 3 deletions packages/markers/src/browser/problem/problem-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,33 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { injectable, inject } from 'inversify';
import { injectable, inject, postConstruct } from 'inversify';
import { ProblemManager } from './problem-manager';
import { ProblemMarker } from '../../common/problem-marker';
import { ProblemTreeModel } from './problem-tree-model';
import { MarkerInfoNode, MarkerNode, MarkerRootNode } from '../marker-tree';
import { TreeWidget, TreeProps, ContextMenuRenderer, TreeNode, NodeProps, TreeModel } from '@theia/core/lib/browser';
import {
TreeWidget, TreeProps, ContextMenuRenderer, TreeNode, NodeProps, TreeModel,
ApplicationShell, Navigatable, ExpandableTreeNode, SelectableTreeNode
} from '@theia/core/lib/browser';
import { DiagnosticSeverity } from 'vscode-languageserver-types';
import * as React from 'react';
import { ProblemPreferences } from './problem-preferences';
import { DisposableCollection } from '@theia/core/lib/common/disposable';

export const PROBLEMS_WIDGET_ID = 'problems';

@injectable()
export class ProblemWidget extends TreeWidget {

protected readonly toDisposeOnActiveWidgetChanged = new DisposableCollection();

@inject(ProblemPreferences)
protected readonly preferences: ProblemPreferences;

@inject(ApplicationShell)
protected readonly shell: ApplicationShell;

constructor(
@inject(ProblemManager) protected readonly problemManager: ProblemManager,
@inject(TreeProps) readonly treeProps: TreeProps,
Expand All @@ -42,10 +55,41 @@ export class ProblemWidget extends TreeWidget {
this.title.iconClass = 'fa problem-tab-icon';
this.title.closable = true;
this.addClass('theia-marker-container');

this.addClipboardListener(this.node, 'copy', e => this.handleCopy(e));
}

@postConstruct()
protected init(): void {
super.init();
if (this.preferences.get('problems.autoReveal')) {
this.focusActiveEditorMarkers();
}
this.preferences.onPreferenceChanged(e => {
if (e.preferenceName === 'problems.autoReveal') {
if (e.newValue === true) {
this.focusActiveEditorMarkers();
} else {
this.toDisposeOnActiveWidgetChanged.dispose();
}
}
});
}

protected focusActiveEditorMarkers(): void {
this.toDisposeOnActiveWidgetChanged.dispose();
this.toDisposeOnActiveWidgetChanged.push(this.shell.onDidChangeActiveWidget(e => {
const widget = e.newValue;
if (widget && Navigatable.is(widget)) {
const uri = widget.getResourceUri();
const node = uri && this.model.getNode(uri.toString());
if (ExpandableTreeNode.is(node) && SelectableTreeNode.is(node)) {
this.model.expandNode(node);
this.model.selectNode(node);
}
}
}));
}

storeState(): object {
// no-op
return {};
Expand Down

0 comments on commit 733063d

Please sign in to comment.