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

Fixes to run dart and flutter vscode extensions #6044

Merged
merged 10 commits into from
Sep 4, 2019
38 changes: 17 additions & 21 deletions packages/core/src/browser/shell/tab-bar-decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import debounce = require('lodash.debounce');
import { Title, Widget } from '@phosphor/widgets';
import { inject, injectable, named, postConstruct } from 'inversify';
import { Event, Emitter, Disposable, DisposableCollection, ContributionProvider } from '../../common';
import { Title, Widget } from '@phosphor/widgets';
import { WidgetDecoration } from '../widget-decoration';

export const TabBarDecorator = Symbol('TabBarDecorator');
Expand All @@ -34,11 +35,11 @@ export interface TabBarDecorator {
readonly onDidChangeDecorations: Event<void>;

/**
* Decorate tabs by the underlying URI.
* @param {Title<Widget>[]} titles An array of the titles of the tabs.
* @returns A map from the URI of the tab to its decoration data.
* Decorate title.
* @param {Title<Widget>} title the title
* @returns decoration data.
*/
decorate(titles: Title<Widget>[]): Map<string, WidgetDecoration.Data>;
decorate(title: Title<Widget>): WidgetDecoration.Data[];
}

@injectable()
Expand All @@ -57,33 +58,28 @@ export class TabBarDecoratorService implements Disposable {
protected init(): void {
const decorators = this.contributions.getContributions();
this.toDispose.pushAll(decorators.map(decorator =>
decorator.onDidChangeDecorations(data =>
this.onDidChangeDecorationsEmitter.fire(undefined)
))
);
decorator.onDidChangeDecorations(this.fireDidChangeDecorations)
));
}

dispose(): void {
this.toDispose.dispose();
}

protected fireDidChangeDecorations = debounce(() => this.onDidChangeDecorationsEmitter.fire(undefined), 150);

/**
* Assign tabs the decorators provided by all the contributions.
* @param {Title<Widget>[]} titles An array of the titles of the tabs.
* @returns A map from the URI of the tab to an array of its decoration data.
* @param {Title<Widget>} title the title
* @returns an array of its decoration data.
*/
getDecorations(titles: Title<Widget>[]): Map<string, WidgetDecoration.Data[]> {
getDecorations(title: Title<Widget>): WidgetDecoration.Data[] {
const decorators = this.contributions.getContributions();
const changes: Map<string, WidgetDecoration.Data[]> = new Map();
let all: WidgetDecoration.Data[] = [];
for (const decorator of decorators) {
for (const [id, data] of (decorator.decorate(titles)).entries()) {
if (changes.has(id)) {
changes.get(id)!.push(data);
} else {
changes.set(id, [data]);
}
}
const decorations = decorator.decorate(title);
all = all.concat(decorations);
}
return changes;
return all;
}
}
71 changes: 51 additions & 20 deletions packages/core/src/browser/shell/tab-bars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import PerfectScrollbar from 'perfect-scrollbar';
import { TabBar, Title, Widget } from '@phosphor/widgets';
import { VirtualElement, h, VirtualDOM, ElementInlineStyle } from '@phosphor/virtualdom';
import { DisposableCollection, MenuPath, notEmpty } from '../../common';
import { Disposable, DisposableCollection, MenuPath, notEmpty } from '../../common';
import { ContextMenuRenderer } from '../context-menu-renderer';
import { Signal } from '@phosphor/signaling';
import { Signal, Slot } from '@phosphor/signaling';
import { Message } from '@phosphor/messaging';
import { ArrayExt } from '@phosphor/algorithm';
import { ElementExt } from '@phosphor/domutils';
Expand Down Expand Up @@ -63,11 +63,6 @@ export interface SideBarRenderData extends TabBar.IRenderData<Widget> {
*/
export class TabBarRenderer extends TabBar.Renderer {

/**
* A reference to the tab bar is required in order to activate it when a context menu
* is requested.
*/
tabBar?: TabBar<Widget>;
/**
* The menu path used to render the context menu.
*/
Expand All @@ -84,9 +79,34 @@ export class TabBarRenderer extends TabBar.Renderer {
) {
super();
if (this.decoratorService) {
this.toDispose.push(Disposable.create(() => this.resetDecorations()));
this.toDispose.push(this.decoratorService);
this.toDispose.push(this.decoratorService.onDidChangeDecorations(() => this.tabBar && this.tabBar.update()));
this.toDispose.push(this.decoratorService.onDidChangeDecorations(() => this.resetDecorations()));
}
}

protected _tabBar?: TabBar<Widget>;
protected readonly toDisposeOnTabBar = new DisposableCollection();
/**
* A reference to the tab bar is required in order to activate it when a context menu
* is requested.
*/
set tabBar(tabBar: TabBar<Widget> | undefined) {
if (this._tabBar === tabBar) {
return;
}
this.toDisposeOnTabBar.dispose();
this.toDispose.push(this.toDisposeOnTabBar);
this._tabBar = tabBar;
if (tabBar) {
const listener: Slot<Widget, TabBar.ITabCloseRequestedArgs<Widget>> = (_, { title }) => this.resetDecorations(title);
tabBar.tabCloseRequested.connect(listener);
this.toDisposeOnTabBar.push(Disposable.create(() => tabBar.tabCloseRequested.disconnect(listener)));
}
this.resetDecorations();
}
get tabBar(): TabBar<Widget> | undefined {
return this._tabBar;
}

/**
Expand Down Expand Up @@ -183,28 +203,39 @@ export class TabBarRenderer extends TabBar.Renderer {
return h.div({ className: 'p-TabBar-tabLabel', style }, data.title.label);
}

protected readonly decorations = new Map<Title<Widget>, WidgetDecoration.Data[]>();

protected resetDecorations(title?: Title<Widget>): void {
if (title) {
this.decorations.delete(title);
} else {
this.decorations.clear();
}
if (this.tabBar) {
this.tabBar.update();
}
}

/**
* Get all available decorations of a given tab.
* @param {string} tab The URI of the tab.
* @param {string} title The widget title.
*/
protected getDecorations(tab: string): WidgetDecoration.Data[] {
const tabDecorations = [];
protected getDecorations(title: Title<Widget>): WidgetDecoration.Data[] {
if (this.tabBar && this.decoratorService) {
const allDecorations = this.decoratorService.getDecorations([...this.tabBar.titles]);
if (allDecorations.has(tab)) {
tabDecorations.push(...allDecorations.get(tab));
}
const decorations = this.decorations.get(title) || this.decoratorService.getDecorations(title);
this.decorations.set(title, decorations);
return decorations;
}
return tabDecorations;
return [];
}

/**
* Get the decoration data given the tab URI and the decoration data type.
* @param {string} tab The URI of the tab.
* @param {string} title The title.
* @param {K} key The type of the decoration data.
*/
protected getDecorationData<K extends keyof WidgetDecoration.Data>(tab: string, key: K): WidgetDecoration.Data[K][] {
return this.getDecorations(tab).filter(data => data[key] !== undefined).map(data => data[key]);
protected getDecorationData<K extends keyof WidgetDecoration.Data>(title: Title<Widget>, key: K): WidgetDecoration.Data[K][] {
return this.getDecorations(title).filter(data => data[key] !== undefined).map(data => data[key]);

}

Expand Down Expand Up @@ -318,7 +349,7 @@ export class TabBarRenderer extends TabBar.Renderer {
const baseClassName = this.createIconClass(data);

const overlayIcons: VirtualElement[] = [];
const decorationData = this.getDecorationData(data.title.caption, 'iconOverlay');
const decorationData = this.getDecorationData(data.title, 'iconOverlay');

// Check if the tab has decoration markers to be rendered on top.
if (decorationData.length > 0) {
Expand Down
7 changes: 6 additions & 1 deletion packages/debug/src/browser/debug-session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,12 @@ export class DebugSession implements CompositeTreeElement {
sourceModified,
breakpoints: enabled.map(({ origin }) => origin.raw)
});
response.body.breakpoints.map((raw, index) => enabled[index].update({ raw }));
response.body.breakpoints.map((raw, index) => {
// node debug adapter returns more breakpoints sometimes
if (enabled[index]) {
enabled[index].update({ raw });
}
});
} catch (error) {
// could be error or promise rejection of DebugProtocol.SetBreakpointsResponse
if (error instanceof Error) {
Expand Down
8 changes: 4 additions & 4 deletions packages/markers/src/browser/problem/problem-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import debounce = require('lodash.debounce');
import { injectable, inject } from 'inversify';
import { FrontendApplication, FrontendApplicationContribution, CompositeTreeNode, SelectableTreeNode, Widget } from '@theia/core/lib/browser';
import { StatusBar, StatusBarAlignment } from '@theia/core/lib/browser/status-bar/status-bar';
Expand Down Expand Up @@ -70,16 +71,15 @@ export class ProblemContribution extends AbstractViewContribution<ProblemWidget>
}

onStart(app: FrontendApplication): void {
this.setStatusBarElement(this.problemManager.getProblemStat());
this.problemManager.onDidChangeMarkers(() => {
this.setStatusBarElement(this.problemManager.getProblemStat());
});
this.updateStatusBarElement();
this.problemManager.onDidChangeMarkers(this.updateStatusBarElement);
}

async initializeLayout(app: FrontendApplication): Promise<void> {
await this.openView();
}

protected updateStatusBarElement = debounce(() => this.setStatusBarElement(this.problemManager.getProblemStat()), 10);
protected setStatusBarElement(problemStat: ProblemStat): void {
this.statusBar.setElement('problem-marker-status', {
text: problemStat.infos <= 0
Expand Down
21 changes: 11 additions & 10 deletions packages/markers/src/browser/problem/problem-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import { injectable } from 'inversify';
import { MarkerManager } from '../marker-manager';
import { PROBLEM_KIND } from '../../common/problem-marker';
import { Marker } from '../../common/marker';
import URI from '@theia/core/lib/common/uri';
import { Diagnostic } from 'vscode-languageserver-types';

export interface ProblemStat {
Expand All @@ -35,15 +33,18 @@ export class ProblemManager extends MarkerManager<Diagnostic> {
}

getProblemStat(): ProblemStat {
const allMarkers: Marker<Diagnostic>[] = [];
for (const uri of this.getUris()) {
allMarkers.push(...this.findMarkers({ uri: new URI(uri) }));
let errors = 0;
let warnings = 0;
let infos = 0;
for (const marker of this.findMarkers()) {
if (marker.data.severity === 1) {
errors++;
} else if (marker.data.severity === 2) {
warnings++;
} else if (marker.data.severity === 3) {
infos++;
}
}

const errors = allMarkers.filter(m => m.data.severity === 1).length;
const warnings = allMarkers.filter(m => m.data.severity === 2).length;
const infos = allMarkers.filter(m => m.data.severity === 3).length;

return { errors, warnings, infos };
}

Expand Down
Loading