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 committed Jul 15, 2020
1 parent a1ea230 commit 0b58e8f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 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: 48 additions & 2 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 toDisposeOnCurrentWidgetChanged = 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 @@ -46,6 +59,39 @@ export class ProblemWidget extends TreeWidget {
this.addClipboardListener(this.node, 'copy', e => this.handleCopy(e));
}

@postConstruct()
protected init(): void {
super.init();
this.updateFollowActiveEditor();
this.toDispose.push(this.preferences.onPreferenceChanged(e => {
if (e.preferenceName === 'problems.autoReveal') {
this.updateFollowActiveEditor();
}
}));
}

protected updateFollowActiveEditor(): void {
this.toDisposeOnCurrentWidgetChanged.dispose();
if (this.preferences.get('problems.autoReveal')) {
this.followActiveEditor();
this.toDispose.push(this.toDisposeOnCurrentWidgetChanged);
}
}

protected followActiveEditor(): void {
this.toDisposeOnCurrentWidgetChanged.push(this.shell.onDidChangeCurrentWidget(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 0b58e8f

Please sign in to comment.