Skip to content

Commit

Permalink
Added types to theia.d.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
jbicker committed Dec 29, 2022
1 parent 7e753f4 commit 1d3a31c
Show file tree
Hide file tree
Showing 9 changed files with 1,030 additions and 6 deletions.
37 changes: 37 additions & 0 deletions packages/plugin-ext/src/common/collections.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// *****************************************************************************
// Copyright (C) 2022 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
// *****************************************************************************

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
// some code copied and modified from https://github.com/microsoft/vscode/blob/1.71.2/src/vs/base/common/collections.ts

export function diffSets<T>(before: Set<T>, after: Set<T>): { removed: T[]; added: T[] } {
const removed: T[] = [];
const added: T[] = [];
for (const element of before) {
if (!after.has(element)) {
removed.push(element);
}
}
for (const element of after) {
if (!before.has(element)) {
added.push(element);
}
}
return { removed, added };
}
128 changes: 126 additions & 2 deletions packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1902,6 +1902,128 @@ export interface CommentsMain {
$onDidCommentThreadsChange(handle: number, event: CommentThreadChangedEvent): void;
}

// #region

export const enum TabInputKind {
UnknownInput,
TextInput,
TextDiffInput,
TextMergeInput,
NotebookInput,
NotebookDiffInput,
CustomEditorInput,
WebviewEditorInput,
TerminalEditorInput,
InteractiveEditorInput,
}

export interface UnknownInputDto {
kind: TabInputKind.UnknownInput;
}

export interface TextInputDto {
kind: TabInputKind.TextInput;
uri: UriComponents;
}

export interface TextDiffInputDto {
kind: TabInputKind.TextDiffInput;
original: UriComponents;
modified: UriComponents;
}

export interface TextMergeInputDto {
kind: TabInputKind.TextMergeInput;
base: UriComponents;
input1: UriComponents;
input2: UriComponents;
result: UriComponents;
}

export interface NotebookInputDto {
kind: TabInputKind.NotebookInput;
notebookType: string;
uri: UriComponents;
}

export interface NotebookDiffInputDto {
kind: TabInputKind.NotebookDiffInput;
notebookType: string;
original: UriComponents;
modified: UriComponents;
}

export interface CustomInputDto {
kind: TabInputKind.CustomEditorInput;
viewType: string;
uri: UriComponents;
}

export interface WebviewInputDto {
kind: TabInputKind.WebviewEditorInput;
viewType: string;
}

export interface InteractiveEditorInputDto {
kind: TabInputKind.InteractiveEditorInput;
uri: UriComponents;
inputBoxUri: UriComponents;
}

export interface TabInputDto {
kind: TabInputKind.TerminalEditorInput;
}

export type EditorGroupColumn = number;
export type AnyInputDto = UnknownInputDto | TextInputDto | TextDiffInputDto | TextMergeInputDto | NotebookInputDto | NotebookDiffInputDto | CustomInputDto | WebviewInputDto | InteractiveEditorInputDto | TabInputDto;

export interface TabGroupDto {
isActive: boolean;
viewColumn: EditorGroupColumn;
tabs: TabDto[];
groupId: number;
}

export const enum TabModelOperationKind {
TAB_OPEN,
TAB_CLOSE,
TAB_UPDATE,
TAB_MOVE
}

export interface TabOperation {
readonly kind: TabModelOperationKind.TAB_OPEN | TabModelOperationKind.TAB_CLOSE | TabModelOperationKind.TAB_UPDATE | TabModelOperationKind.TAB_MOVE;
readonly index: number;
readonly tabDto: TabDto;
readonly groupId: number;
readonly oldIndex?: number;
}

export interface TabDto {
id: string;
label: string;
input: any;
editorId?: string;
isActive: boolean;
isPinned: boolean;
isPreview: boolean;
isDirty: boolean;
}

export interface TabsExt {
$acceptEditorTabModel(tabGroups: TabGroupDto[]): void;
$acceptTabGroupUpdate(groupDto: TabGroupDto): void;
$acceptTabOperation(operation: TabOperation): void;
}

export interface TabsMain {
$moveTab(tabId: string, index: number, viewColumn: EditorGroupColumn, preserveFocus?: boolean): void;
$closeTab(tabIds: string[], preserveFocus?: boolean): Promise<boolean>;
$closeGroup(groupIds: number[], preservceFocus?: boolean): Promise<boolean>;
}

// endregion

export const PLUGIN_RPC_CONTEXT = {
AUTHENTICATION_MAIN: <ProxyIdentifier<AuthenticationMain>>createProxyIdentifier<AuthenticationMain>('AuthenticationMain'),
COMMAND_REGISTRY_MAIN: <ProxyIdentifier<CommandRegistryMain>>createProxyIdentifier<CommandRegistryMain>('CommandRegistryMain'),
Expand Down Expand Up @@ -1936,7 +2058,8 @@ export const PLUGIN_RPC_CONTEXT = {
LABEL_SERVICE_MAIN: <ProxyIdentifier<LabelServiceMain>>createProxyIdentifier<LabelServiceMain>('LabelServiceMain'),
TIMELINE_MAIN: <ProxyIdentifier<TimelineMain>>createProxyIdentifier<TimelineMain>('TimelineMain'),
THEMING_MAIN: <ProxyIdentifier<ThemingMain>>createProxyIdentifier<ThemingMain>('ThemingMain'),
COMMENTS_MAIN: <ProxyIdentifier<CommentsMain>>createProxyIdentifier<CommentsMain>('CommentsMain')
COMMENTS_MAIN: <ProxyIdentifier<CommentsMain>>createProxyIdentifier<CommentsMain>('CommentsMain'),
TABS_MAIN: <ProxyIdentifier<TabsMain>>createProxyIdentifier<TabsMain>('TabsMain')
};

export const MAIN_RPC_CONTEXT = {
Expand Down Expand Up @@ -1971,7 +2094,8 @@ export const MAIN_RPC_CONTEXT = {
LABEL_SERVICE_EXT: createProxyIdentifier<LabelServiceExt>('LabelServiceExt'),
TIMELINE_EXT: createProxyIdentifier<TimelineExt>('TimeLineExt'),
THEMING_EXT: createProxyIdentifier<ThemingExt>('ThemingExt'),
COMMENTS_EXT: createProxyIdentifier<CommentsExt>('CommentsExt')
COMMENTS_EXT: createProxyIdentifier<CommentsExt>('CommentsExt'),
TABS_EXT: createProxyIdentifier<TabsExt>('TabsExt')
};

export interface TasksExt {
Expand Down
11 changes: 11 additions & 0 deletions packages/plugin-ext/src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,14 @@ export function isUndefined(obj: any): obj is undefined {
export function isUndefinedOrNull(obj: any): obj is undefined | null {
return isUndefined(obj) || obj === null; // eslint-disable-line no-null/no-null
}

/**
* Asserts that the argument passed in is neither undefined nor null.
*/
export function assertIsDefined<T>(arg: T | null | undefined): T {
if (isUndefinedOrNull(arg)) {
throw new Error('Assertion Failed: argument is undefined or null');
}

return arg;
}
42 changes: 42 additions & 0 deletions packages/plugin-ext/src/main/browser/tabs/tabs-main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// *****************************************************************************
// Copyright (C) 2022 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 } from '@theia/core/shared/inversify';

import { TabsMain } from '../../../common/plugin-api-rpc';
import { RPCProtocol } from '../../../common/rpc-protocol';

export class TabsMainImp implements TabsMain {

constructor(
rpc: RPCProtocol,
container: interfaces.Container
) {}

// #region Messages received from Ext Host
$moveTab(tabId: string, index: number, viewColumn: number, preserveFocus?: boolean): void {
return;
}

async $closeTab(tabIds: string[], preserveFocus?: boolean): Promise<boolean> {
return false;
}

async $closeGroup(groupIds: number[], preserveFocus?: boolean): Promise<boolean> {
return false;
}
// #endregion
}
34 changes: 30 additions & 4 deletions packages/plugin-ext/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,15 @@ import {
TestRunProfileKind,
TestTag,
TestRunRequest,
TestMessage
TestMessage,
TextTabInput,
CustomEditorTabInput,
NotebookDiffEditorTabInput,
NotebookEditorTabInput,
TerminalEditorTabInput,
TextDiffTabInput,
TextMergeTabInput,
WebviewEditorTabInput
} from './types-impl';
import { AuthenticationExtImpl } from './authentication-ext';
import { SymbolKind } from '../common/plugin-api-rpc-model';
Expand All @@ -180,7 +188,12 @@ import { ConnectionImpl } from '../common/connection';
import { TasksExtImpl } from './tasks/tasks';
import { DebugExtImpl } from './debug/debug-ext';
import { FileSystemExtImpl } from './file-system-ext-impl';
import { QuickPick, QuickPickItem, ResourceLabelFormatter, LineChange } from '@theia/plugin';
import {
QuickPick,
QuickPickItem,
ResourceLabelFormatter,
LineChange
} from '@theia/plugin';
import { ScmExtImpl } from './scm';
import { DecorationsExtImpl } from './decorations';
import { TextEditorExt } from './text-editor';
Expand All @@ -201,6 +214,7 @@ import { CustomEditorsExtImpl } from './custom-editors';
import { WebviewViewsExtImpl } from './webview-views';
import { PluginPackage } from '../common';
import { Endpoint } from '@theia/core/lib/browser/endpoint';
import { TabsExtImpl } from './tabs';

export function createAPIFactory(
rpc: RPCProtocol,
Expand Down Expand Up @@ -238,6 +252,7 @@ export function createAPIFactory(
const timelineExt = rpc.set(MAIN_RPC_CONTEXT.TIMELINE_EXT, new TimelineExtImpl(rpc, commandRegistry));
const themingExt = rpc.set(MAIN_RPC_CONTEXT.THEMING_EXT, new ThemingExtImpl(rpc));
const commentsExt = rpc.set(MAIN_RPC_CONTEXT.COMMENTS_EXT, new CommentsExtImpl(rpc, commandRegistry, documents));
const tabsExt = rpc.set(MAIN_RPC_CONTEXT.TABS_EXT, new TabsExtImpl(rpc));
const customEditorExt = rpc.set(MAIN_RPC_CONTEXT.CUSTOM_EDITORS_EXT, new CustomEditorsExtImpl(rpc, documents, webviewExt, workspaceExt));
const webviewViewsExt = rpc.set(MAIN_RPC_CONTEXT.WEBVIEW_VIEWS_EXT, new WebviewViewsExtImpl(rpc, webviewExt));
rpc.set(MAIN_RPC_CONTEXT.DEBUG_EXT, debugExt);
Expand Down Expand Up @@ -459,7 +474,7 @@ export function createAPIFactory(
onDidChangeWindowState(listener, thisArg?, disposables?): theia.Disposable {
return windowStateExt.onDidChangeWindowState(listener, thisArg, disposables);
},
createTerminal(nameOrOptions: theia.TerminalOptions | theia.PseudoTerminalOptions | theia.ExtensionTerminalOptions | (string | undefined),
createTerminal(nameOrOptions: theia.TerminalOptions | theia.ExtensionTerminalOptions | theia.ExtensionTerminalOptions | (string | undefined),
shellPath?: string,
shellArgs?: string[]): theia.Terminal {
return terminalExt.createTerminal(nameOrOptions, shellPath, shellArgs);
Expand Down Expand Up @@ -500,6 +515,9 @@ export function createAPIFactory(
},
onDidChangeActiveColorTheme(listener, thisArg?, disposables?) {
return themingExt.onDidChangeActiveColorTheme(listener, thisArg, disposables);
},
get tabGroups(): theia.TabGroups {
return tabsExt.tabGroups;
}
};

Expand Down Expand Up @@ -1100,7 +1118,15 @@ export function createAPIFactory(
TestRunProfileKind,
TestTag,
TestRunRequest,
TestMessage
TestMessage,
TabInputText: TextTabInput,
TabInputTextDiff: TextDiffTabInput,
TabInputTextMerge: TextMergeTabInput,
TabInputCustom: CustomEditorTabInput,
TabInputNotebook: NotebookEditorTabInput,
TabInputNotebookDiff: NotebookDiffEditorTabInput,
TabInputWebview: WebviewEditorTabInput,
TabInputTerminal: TerminalEditorTabInput,
};
};
}
Expand Down
Loading

0 comments on commit 1d3a31c

Please sign in to comment.