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

Added tab related APIs - without functionality implemented yet #12031

Merged
merged 1 commit into from
Jan 4, 2023
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
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 @@ -1919,6 +1919,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 @@ -1952,7 +2074,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 @@ -1986,7 +2109,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
}
27 changes: 24 additions & 3 deletions packages/plugin-ext/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,15 @@ import {
ExtensionKind,
InlineCompletionItem,
InlineCompletionList,
InlineCompletionTriggerKind
InlineCompletionTriggerKind,
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 Down Expand Up @@ -218,6 +226,7 @@ import { WebviewViewsExtImpl } from './webview-views';
import { PluginPackage } from '../common';
import { Endpoint } from '@theia/core/lib/browser/endpoint';
import { FilePermission } from '@theia/filesystem/lib/common/files';
import { TabsExtImpl } from './tabs';

export function createAPIFactory(
rpc: RPCProtocol,
Expand Down Expand Up @@ -255,6 +264,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 @@ -496,7 +506,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[] | string): theia.Terminal {
return terminalExt.createTerminal(nameOrOptions, shellPath, shellArgs);
Expand Down Expand Up @@ -541,6 +551,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 @@ -1262,7 +1275,15 @@ export function createAPIFactory(
ExtensionKind,
InlineCompletionItem,
InlineCompletionList,
InlineCompletionTriggerKind
InlineCompletionTriggerKind,
TabInputText: TextTabInput,
TabInputTextDiff: TextDiffTabInput,
TabInputTextMerge: TextMergeTabInput,
TabInputCustom: CustomEditorTabInput,
TabInputNotebook: NotebookEditorTabInput,
TabInputNotebookDiff: NotebookDiffEditorTabInput,
TabInputWebview: WebviewEditorTabInput,
TabInputTerminal: TerminalEditorTabInput,
};
};
}
Expand Down
Loading