Skip to content

Commit

Permalink
eclipse-che/che#9434 implement all editor objects (#28)
Browse files Browse the repository at this point in the history
Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>
  • Loading branch information
evidolob authored and benoitf committed Jun 20, 2018
1 parent 0e4badb commit 6375deb
Show file tree
Hide file tree
Showing 30 changed files with 5,539 additions and 27 deletions.
4 changes: 3 additions & 1 deletion packages/plugin-ext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
"@theia/filesystem": "^0.3.10",
"@theia/workspace": "^0.3.10",
"@theia/plugin": "^0.3.10",
"@theia/monaco": "^0.3.10",
"decompress": "^4.2.0",
"ps-tree": "1.1.0"
"ps-tree": "1.1.0",
"vscode-uri": "^1.0.1"
},
"publishConfig": {
"access": "public"
Expand Down
293 changes: 286 additions & 7 deletions packages/plugin-ext/src/api/plugin-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import { createProxyIdentifier, ProxyIdentifier } from './rpc-protocol';
import * as theia from '@theia/plugin';
import { PluginLifecycle, PluginModel, PluginMetadata } from '../common/plugin-protocol';
import { TextEditorCursorStyle } from '../common/editor-options';
import { TextEditorLineNumbersStyle, EndOfLine, OverviewRulerLane } from '../plugin/types-impl';
import { UriComponents } from '../common/uri-components';

export interface HostedPluginManagerExt {
$initialize(contextPath: string, pluginMedata: PluginMetadata): void;
Expand Down Expand Up @@ -71,11 +74,11 @@ export interface MessageRegistryMain {

export interface StatusBarMessageRegistryMain {
$setMessage(text: string,
priority: number,
alignment: theia.StatusBarAlignment,
color: string | undefined,
tooltip: string | undefined,
command: string | undefined): PromiseLike<string>;
priority: number,
alignment: theia.StatusBarAlignment,
color: string | undefined,
tooltip: string | undefined,
command: string | undefined): PromiseLike<string>;
$dispose(id: string): void;
}

Expand All @@ -95,16 +98,292 @@ export interface WindowStateExt {
$onWindowStateChanged(focus: boolean): void;
}

export enum EditorPosition {
ONE = 0,
TWO = 1,
THREE = 2
}

export interface Position {
readonly lineNumber: number;
readonly column: number;
}

export interface Range {
/**
* Line number on which the range starts (starts at 1).
*/
readonly startLineNumber: number;
/**
* Column on which the range starts in line `startLineNumber` (starts at 1).
*/
readonly startColumn: number;
/**
* Line number on which the range ends.
*/
readonly endLineNumber: number;
/**
* Column on which the range ends in line `endLineNumber`.
*/
readonly endColumn: number;
}

export interface Selection {
/**
* The line number on which the selection has started.
*/
readonly selectionStartLineNumber: number;
/**
* The column on `selectionStartLineNumber` where the selection has started.
*/
readonly selectionStartColumn: number;
/**
* The line number on which the selection has ended.
*/
readonly positionLineNumber: number;
/**
* The column on `positionLineNumber` where the selection has ended.
*/
readonly positionColumn: number;
}

export interface TextEditorConfiguration {
tabSize: number;
insertSpaces: boolean;
cursorStyle: TextEditorCursorStyle;
lineNumbers: TextEditorLineNumbersStyle;
}

export interface TextEditorConfigurationUpdate {
tabSize?: number | 'auto';
insertSpaces?: boolean | 'auto';
cursorStyle?: TextEditorCursorStyle;
lineNumbers?: TextEditorLineNumbersStyle;
}

export enum TextEditorRevealType {
Default = 0,
InCenter = 1,
InCenterIfOutsideViewport = 2,
AtTop = 3
}

export interface SelectionChangeEvent {
selections: Selection[];
source?: string;
}

export interface EditorChangedPropertiesData {
options?: TextEditorConfiguration;
selections?: SelectionChangeEvent;
visibleRanges?: Range[];
}

export interface TextEditorPositionData {
[id: string]: EditorPosition;
}

export interface TextEditorsExt {
$acceptEditorPropertiesChanged(id: string, props: EditorChangedPropertiesData): void;
$acceptEditorPositionData(data: TextEditorPositionData): void;
}

export interface SingleEditOperation {
range: Range;
text?: string;
forceMoveMarkers?: boolean;
}

export interface UndoStopOptions {
undoStopBefore: boolean;
undoStopAfter: boolean;
}

export interface ApplyEditsOptions extends UndoStopOptions {
setEndOfLine: EndOfLine;
}

export interface ThemeColor {
id: string;
}

/**
* Describes the behavior of decorations when typing/editing near their edges.
*/
export enum TrackedRangeStickiness {
AlwaysGrowsWhenTypingAtEdges = 0,
NeverGrowsWhenTypingAtEdges = 1,
GrowsOnlyWhenTypingBefore = 2,
GrowsOnlyWhenTypingAfter = 3,
}
export interface ContentDecorationRenderOptions {
contentText?: string;
contentIconPath?: string | UriComponents;

border?: string;
borderColor?: string | ThemeColor;
fontStyle?: string;
fontWeight?: string;
textDecoration?: string;
color?: string | ThemeColor;
backgroundColor?: string | ThemeColor;

margin?: string;
width?: string;
height?: string;
}

export interface ThemeDecorationRenderOptions {
backgroundColor?: string | ThemeColor;

outline?: string;
outlineColor?: string | ThemeColor;
outlineStyle?: string;
outlineWidth?: string;

border?: string;
borderColor?: string | ThemeColor;
borderRadius?: string;
borderSpacing?: string;
borderStyle?: string;
borderWidth?: string;

fontStyle?: string;
fontWeight?: string;
textDecoration?: string;
cursor?: string;
color?: string | ThemeColor;
opacity?: number;
letterSpacing?: string;

gutterIconPath?: string | UriComponents;
gutterIconSize?: string;

overviewRulerColor?: string | ThemeColor;

before?: ContentDecorationRenderOptions;
after?: ContentDecorationRenderOptions;
}

export interface DecorationRenderOptions extends ThemeDecorationRenderOptions {
isWholeLine?: boolean;
rangeBehavior?: TrackedRangeStickiness;
overviewRulerLane?: OverviewRulerLane;

light?: ThemeDecorationRenderOptions;
dark?: ThemeDecorationRenderOptions;
}

export interface ThemeDecorationInstanceRenderOptions {
before?: ContentDecorationRenderOptions;
after?: ContentDecorationRenderOptions;
}

export interface DecorationInstanceRenderOptions extends ThemeDecorationInstanceRenderOptions {
light?: ThemeDecorationInstanceRenderOptions;
dark?: ThemeDecorationInstanceRenderOptions;
}

export interface MarkdownString {
value: string;
isTrusted?: boolean;
}

export interface DecorationOptions {
range: Range;
hoverMessage?: MarkdownString | MarkdownString[];
renderOptions?: DecorationInstanceRenderOptions;
}

export interface TextEditorsMain {
// $tryShowTextDocument(resource: UriComponents, options: TextDocumentShowOptions): Promise<string>;
$registerTextEditorDecorationType(key: string, options: DecorationRenderOptions): void;
$removeTextEditorDecorationType(key: string): void;
// $tryShowEditor(id: string, position: EditorPosition): Promise<void>;
// $tryHideEditor(id: string): Promise<void>;
$trySetOptions(id: string, options: TextEditorConfigurationUpdate): Promise<void>;
$trySetDecorations(id: string, key: string, ranges: DecorationOptions[]): Promise<void>;
$trySetDecorationsFast(id: string, key: string, ranges: number[]): Promise<void>;
$tryRevealRange(id: string, range: Range, revealType: TextEditorRevealType): Promise<void>;
$trySetSelections(id: string, selections: Selection[]): Promise<void>;
$tryApplyEdits(id: string, modelVersionId: number, edits: SingleEditOperation[], opts: ApplyEditsOptions): Promise<boolean>;
// $tryApplyWorkspaceEdit(workspaceEditDto: WorkspaceEditDto): Promise<boolean>;
$tryInsertSnippet(id: string, template: string, selections: Range[], opts: UndoStopOptions): Promise<boolean>;
// $getDiffInformation(id: string): Promise<editorCommon.ILineChange[]>;
}

export interface ModelAddedData {
uri: UriComponents;
versionId: number;
lines: string[];
EOL: string;
modeId: string;
isDirty: boolean;
}

export interface TextEditorAddData {
id: string;
documentUri: UriComponents;
options: TextEditorConfiguration;
selections: Selection[];
visibleRanges: Range[];
editorPosition?: EditorPosition;
}

export interface EditorsAndDocumentsDelta {
removedDocuments?: UriComponents[];
addedDocuments?: ModelAddedData[];
removedEditors?: string[];
addedEditors?: TextEditorAddData[];
newActiveEditor?: string;
}

export interface EditorsAndDocumentsExt {
$acceptEditorsAndDocumentsDelta(delta: EditorsAndDocumentsDelta): void;
}

export interface ModelContentChange {
readonly range: Range;
readonly rangeOffset: number;
readonly rangeLength: number;
readonly text: string;
}
export interface ModelChangedEvent {
readonly changes: ModelContentChange[];

readonly eol: string;

readonly versionId: number;
}

export interface DocumentsExt {
$acceptModelModeChanged(startUrl: UriComponents, oldModeId: string, newModeId: string): void;
$acceptModelSaved(strUrl: UriComponents): void;
$acceptDirtyStateChanged(strUrl: UriComponents, isDirty: boolean): void;
$acceptModelChanged(strUrl: UriComponents, e: ModelChangedEvent, isDirty: boolean): void;
}

export interface DocumentsMain {
$tryCreateDocument(options?: { language?: string; content?: string; }): Promise<UriComponents>;
$tryOpenDocument(uri: UriComponents): Promise<void>;
$trySaveDocument(uri: UriComponents): Promise<boolean>;
}

export const PLUGIN_RPC_CONTEXT = {
COMMAND_REGISTRY_MAIN: <ProxyIdentifier<CommandRegistryMain>>createProxyIdentifier<CommandRegistryMain>('CommandRegistryMain'),
QUICK_OPEN_MAIN: createProxyIdentifier<QuickOpenMain>('QuickOpenMain'),
MESSAGE_REGISTRY_MAIN: <ProxyIdentifier<MessageRegistryMain>>createProxyIdentifier<MessageRegistryMain>('MessageRegistryMain'),
STATUS_BAR_MESSAGE_REGISTRY_MAIN: <ProxyIdentifier<StatusBarMessageRegistryMain>>createProxyIdentifier<StatusBarMessageRegistryMain>('StatusBarMessageRegistryMain')
TEXT_EDITORS_MAIN: createProxyIdentifier<TextEditorsMain>('TextEditorsMain'),
DOCUMENTS_MAIN: createProxyIdentifier<DocumentsMain>('DocumentsMain'),
STATUS_BAR_MESSAGE_REGISTRY_MAIN: <ProxyIdentifier<StatusBarMessageRegistryMain>>createProxyIdentifier<StatusBarMessageRegistryMain>('StatusBarMessageRegistryMain'),
};

export const MAIN_RPC_CONTEXT = {
HOSTED_PLUGIN_MANAGER_EXT: createProxyIdentifier<HostedPluginManagerExt>('HostedPluginManagerExt'),
COMMAND_REGISTRY_EXT: createProxyIdentifier<CommandRegistryExt>('CommandRegistryExt'),
QUICK_OPEN_EXT: createProxyIdentifier<QuickOpenExt>('QuickOpenExt'),
WINDOW_STATE_EXT: createProxyIdentifier<WindowStateExt>('WindowStateExt')
TEXT_EDITORS_EXT: createProxyIdentifier<TextEditorsExt>('TextEditorsExt'),
EDITORS_AND_DOCUMENTS_EXT: createProxyIdentifier<EditorsAndDocumentsExt>('EditorsAndDocumentsExt'),
DOCUMENTS_EXT: createProxyIdentifier<DocumentsExt>('DocumentsExt'),
WINDOW_STATE_EXT: createProxyIdentifier<WindowStateExt>('WindowStateExt'),
};
14 changes: 14 additions & 0 deletions packages/plugin-ext/src/common/assert.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

/*
* Copyright (C) 2018 Red Hat, Inc. and others.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/

// tslint:disable-next-line:no-any
export function ok(val?: any, message?: string) {
if (!val || val === null) {
throw new Error(message ? `Assertion failed (${message})` : 'Assertion failed');
}
}
30 changes: 30 additions & 0 deletions packages/plugin-ext/src/common/disposable-util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2018 Red Hat, Inc. and others.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/

export interface Disposable {
dispose(): void;
}

export function dispose<T extends Disposable>(disposable: T): T | undefined;
export function dispose<T extends Disposable>(...disposables: T[]): T[] | undefined;
export function dispose<T extends Disposable>(disposables: T[]): T[] | undefined;
export function dispose<T extends Disposable>(first: T | T[], ...rest: T[]): T | T[] | undefined {
if (Array.isArray(first)) {
first.forEach(d => d && d.dispose());
return [];
} else if (rest.length === 0) {
if (first) {
first.dispose();
return first;
}
return undefined;
} else {
dispose(first);
dispose(rest);
return [];
}
}
Loading

0 comments on commit 6375deb

Please sign in to comment.