Skip to content

Commit

Permalink
[debug] decouple debug model from UI + clean up
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
  • Loading branch information
akosyakov committed Oct 24, 2018
1 parent 5fde4ae commit 64b0b02
Show file tree
Hide file tree
Showing 125 changed files with 6,294 additions and 4,842 deletions.
3 changes: 2 additions & 1 deletion .theia/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
},
"sourceMaps": true,
"smartStep": true,
"outputCapture": "std"
"outputCapture": "std",
"internalConsoleOptions": "openOnSessionStart"
}
]
}
4 changes: 2 additions & 2 deletions packages/console/src/browser/ansi-console-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export class AnsiConsoleItem implements ConsoleItem {
});
}

get empty(): boolean {
return !this.htmlContent;
get visible(): boolean {
return !!this.htmlContent;
}

render(): React.ReactNode {
Expand Down
64 changes: 64 additions & 0 deletions packages/console/src/browser/console-content-widget.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/********************************************************************************
* Copyright (C) 2018 TypeFox and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { interfaces, Container, injectable } from 'inversify';
import { MenuPath, MessageType } from '@theia/core';
import { TreeProps } from '@theia/core/lib/browser/tree';
import { SourceTreeWidget, TreeElementNode } from '@theia/core/lib/browser/source-tree';
import { ConsoleItem } from './console-session';

@injectable()
export class ConsoleContentWidget extends SourceTreeWidget {

static CONTEXT_MENU: MenuPath = ['console-context-menu'];

static createContainer(parent: interfaces.Container, props?: Partial<TreeProps>): Container {
const child = SourceTreeWidget.createContainer(parent, {
contextMenuPath: ConsoleContentWidget.CONTEXT_MENU,
...props
});
child.unbind(SourceTreeWidget);
child.bind(ConsoleContentWidget).toSelf();
return child;
}

protected createTreeElementNodeClassNames(node: TreeElementNode): string[] {
const classNames = super.createTreeElementNodeClassNames(node);
if (node.element) {
const className = this.toClassName((node.element as ConsoleItem));
if (className) {
classNames.push(className);
}
}
return classNames;
}
protected toClassName(item: ConsoleItem): string | undefined {
if (item.severity === MessageType.Error) {
return ConsoleItem.errorClassName;
}
if (item.severity === MessageType.Warning) {
return ConsoleItem.warningClassName;
}
if (item.severity === MessageType.Info) {
return ConsoleItem.infoClassName;
}
if (item.severity === MessageType.Log) {
return ConsoleItem.logClassName;
}
return undefined;
}

}
6 changes: 3 additions & 3 deletions packages/console/src/browser/console-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { FrontendApplicationContribution, KeybindingContribution, KeybindingRegi
import { ConsoleManager } from './console-manager';
import { ConsoleKeybindingContexts } from './console-keybinding-contexts';
import { ConsoleWidget } from './console-widget';
import { CONSOLE_CONTEXT_MENU } from './content/console-content-container';
import { ConsoleContentWidget } from './console-content-widget';

export namespace ConsoleCommands {
export const SELECT_ALL: Command = {
Expand All @@ -44,8 +44,8 @@ export namespace ConsoleCommands {
}

export namespace ConsoleContextMenu {
export const CLIPBOARD = [...CONSOLE_CONTEXT_MENU, '1_clipboard'];
export const CLEAR = [...CONSOLE_CONTEXT_MENU, '2_clear'];
export const CLIPBOARD = [...ConsoleContentWidget.CONTEXT_MENU, '1_clipboard'];
export const CLEAR = [...ConsoleContentWidget.CONTEXT_MENU, '2_clear'];
}

@injectable()
Expand Down
49 changes: 10 additions & 39 deletions packages/console/src/browser/console-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,57 +14,28 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { ReactNode } from 'react';
import { Event } from '@theia/core/lib/common/event';
import { injectable } from 'inversify';
import { MaybePromise } from '@theia/core/lib/common/types';
import { MessageType } from '@theia/core/lib/common/message-service-protocol';
import { TreeSource, TreeElement, CompositeTreeElement } from '@theia/core/lib/browser/source-tree';

export interface ConsoleItem {
export interface ConsoleItem extends TreeElement {
readonly severity?: MessageType
readonly empty: boolean
render(): ReactNode
}
export namespace ConsoleItem {
export const errorClassName = 'theia-console-error';
export const warningClassName = 'theia-console-warning';
export const infoClassName = 'theia-console-info';
export const logClassName = 'theia-console-log';
export function toClassName(item: ConsoleItem): string | undefined {
if (item.severity === MessageType.Error) {
return errorClassName;
}
if (item.severity === MessageType.Warning) {
return warningClassName;
}
if (item.severity === MessageType.Info) {
return infoClassName;
}
if (item.severity === MessageType.Log) {
return logClassName;
}
return undefined;
}
}

export interface CompositeConsoleItem extends ConsoleItem {
readonly hasChildren: boolean;
resolve(): MaybePromise<ConsoleItem[]>;
}
export namespace CompositeConsoleItem {
// tslint:disable:no-any
export function is(item: CompositeConsoleItem | any): item is CompositeConsoleItem {
return !!item && 'resolve' in item;
}
export function hasChildren(item: CompositeConsoleItem | any): item is CompositeConsoleItem {
return is(item) && item.hasChildren;
}
export interface CompositeConsoleItem extends ConsoleItem, CompositeTreeElement {
getElements(): MaybePromise<IterableIterator<ConsoleItem>>
}

export interface ConsoleSession {
readonly id: string
readonly name: string
readonly items: ConsoleItem[]
readonly onDidChange: Event<void>
execute(value: string): MaybePromise<void>
clear(): MaybePromise<void>
@injectable()
export abstract class ConsoleSession extends TreeSource {
abstract getElements(): MaybePromise<IterableIterator<ConsoleItem>>;
abstract execute(value: string): MaybePromise<void>;
abstract clear(): MaybePromise<void>;
}
28 changes: 15 additions & 13 deletions packages/console/src/browser/console-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { injectable, inject, postConstruct } from 'inversify';
import { ElementExt } from '@phosphor/domutils';
import { injectable, inject, postConstruct, interfaces, Container } from 'inversify';
import { TreeSourceNode } from '@theia/core/lib/browser/source-tree';
import { BaseWidget, PanelLayout, Widget, Message, MessageLoop, StatefulWidget, CompositeTreeNode } from '@theia/core/lib/browser';
import { ConsoleSession } from './console-session';
import { DisposableCollection } from '@theia/core/lib/common';
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
import URI from '@theia/core/lib/common/uri';
import { MonacoEditorProvider } from '@theia/monaco/lib/browser/monaco-editor-provider';
import { ProtocolToMonacoConverter, MonacoToProtocolConverter } from 'monaco-languageclient/lib';
import { ElementExt } from '@phosphor/domutils';
import { ConsoleContentWidget } from './content/console-content-widget';
import { ConsoleSessionNode } from './content/console-content-tree';
import { ConsoleHistory } from './console-history';
import { ConsoleContentWidget } from './console-content-widget';
import { ConsoleSession } from './console-session';

export const ConsoleOptions = Symbol('ConsoleWidgetOptions');
export interface ConsoleOptions {
Expand All @@ -50,6 +49,14 @@ export class ConsoleWidget extends BaseWidget implements StatefulWidget {
input: 'theia-console-input',
};

static createContainer(parent: interfaces.Container, options: ConsoleOptions): Container {
const child = ConsoleContentWidget.createContainer(parent);
child.bind(ConsoleHistory).toSelf();
child.bind(ConsoleOptions).toConstantValue(options);
child.bind(ConsoleWidget).toSelf();
return child;
}

@inject(ConsoleOptions)
protected readonly options: ConsoleOptions;

Expand Down Expand Up @@ -116,17 +123,12 @@ export class ConsoleWidget extends BaseWidget implements StatefulWidget {
}

protected _session: ConsoleSession | undefined;
protected readonly toDisposeOnSession = new DisposableCollection();
set session(session: ConsoleSession | undefined) {
if (this._session === session) {
return;
}
this._session = session;
this.content.model.root = ConsoleSessionNode.to(session);
if (this._session) {
this.toDisposeOnSession.push(this._session.onDidChange(() => this.content.model.refresh()));
this.toDispose.push(this.toDisposeOnSession);
}
this.content.source = session;
}
get session(): ConsoleSession | undefined {
return this._session;
Expand Down Expand Up @@ -190,7 +192,7 @@ export class ConsoleWidget extends BaseWidget implements StatefulWidget {

protected revealLastOutput(): void {
const { root } = this.content.model;
if (ConsoleSessionNode.is(root)) {
if (TreeSourceNode.is(root)) {
this.content.model.selectNode(root.children[root.children.length - 1]);
}
}
Expand Down
43 changes: 0 additions & 43 deletions packages/console/src/browser/content/console-content-container.ts

This file was deleted.

Loading

0 comments on commit 64b0b02

Please sign in to comment.