Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[markers] Sync problem markers with active editor #8172

Merged
merged 1 commit into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
53 changes: 51 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,42 @@ 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();
this.toDispose.push(this.toDisposeOnCurrentWidgetChanged);
if (this.preferences.get('problems.autoReveal')) {
this.followActiveEditor();
}
}

protected followActiveEditor(): void {
this.autoRevealFromActiveEditor();
this.toDisposeOnCurrentWidgetChanged.push(this.shell.onDidChangeCurrentWidget(() => this.autoRevealFromActiveEditor()));
}

protected autoRevealFromActiveEditor(): void {
const widget = this.shell.currentWidget;
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