diff --git a/packages/markers/src/browser/problem/problem-preferences.ts b/packages/markers/src/browser/problem/problem-preferences.ts index 7f3b18f1ea0f4..b6e0da94d1ae8 100644 --- a/packages/markers/src/browser/problem/problem-preferences.ts +++ b/packages/markers/src/browser/problem/problem-preferences.ts @@ -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'); diff --git a/packages/markers/src/browser/problem/problem-widget.tsx b/packages/markers/src/browser/problem/problem-widget.tsx index bf10b96c515f9..f0f3a3d9ae0bc 100644 --- a/packages/markers/src/browser/problem/problem-widget.tsx +++ b/packages/markers/src/browser/problem/problem-widget.tsx @@ -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, @@ -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 {};