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

Apply vscode Timeline Plugin API #7997

Merged
merged 1 commit into from
Sep 8, 2020
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ cache:
- packages/search-in-workspace/node_modules
- packages/task/node_modules
- packages/terminal/node_modules
- packages/timeline/node_modules
- packages/typehierarchy/node_modules
- packages/userstorage/node_modules
- packages/variable-resolver/node_modules
Expand Down
3 changes: 3 additions & 0 deletions configs/root-compilation.tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
},
{
"path": "../packages/vsx-registry/compile.tsconfig.json"
},
{
"path": "../packages/timeline/compile.tsconfig.json"
}
]
}
1 change: 1 addition & 0 deletions examples/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@theia/search-in-workspace": "^1.5.0",
"@theia/task": "^1.5.0",
"@theia/terminal": "^1.5.0",
"@theia/timeline": "^1.5.0",
"@theia/typehierarchy": "^1.5.0",
"@theia/userstorage": "^1.5.0",
"@theia/variable-resolver": "^1.5.0",
Expand Down
3 changes: 3 additions & 0 deletions examples/electron/compile.tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@
},
{
"path": "../../packages/vsx-registry/compile.tsconfig.json"
},
{
"path": "../../packages/timeline/compile.tsconfig.json"
}
]
}
1 change: 1 addition & 0 deletions examples/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@theia/search-in-workspace": "^1.5.0",
"@theia/task": "^1.5.0",
"@theia/terminal": "^1.5.0",
"@theia/timeline": "^1.5.0",
"@theia/typehierarchy": "^1.5.0",
"@theia/userstorage": "^1.5.0",
"@theia/variable-resolver": "^1.5.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/plugin-ext/compile.tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
},
{
"path": "../callhierarchy/compile.tsconfig.json"
},
{
"path": "../timeline/compile.tsconfig.json"
}
]
}
1 change: 1 addition & 0 deletions packages/plugin-ext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@theia/search-in-workspace": "^1.5.0",
"@theia/task": "^1.5.0",
"@theia/terminal": "^1.5.0",
"@theia/timeline": "^1.5.0",
"@theia/workspace": "^1.5.0",
"@types/connect": "^3.4.32",
"@types/mime": "^2.0.1",
Expand Down
33 changes: 31 additions & 2 deletions packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ import { QuickTitleButton } from '@theia/core/lib/common/quick-open-model';
import * as files from '@theia/filesystem/lib/common/files';
import { BinaryBuffer } from '@theia/core/lib/common/buffer';
import { ResourceLabelFormatter } from '@theia/core/lib/common/label-protocol';
import type {
InternalTimelineOptions,
Timeline,
TimelineChangeEvent,
TimelineProviderDescriptor
} from '@theia/timeline/lib/common/timeline-model';

export interface PreferenceData {
[scope: number]: any;
Expand Down Expand Up @@ -539,6 +545,16 @@ export interface WorkspaceExt {
$onTextSearchResult(searchRequestId: number, done: boolean, result?: SearchInWorkspaceResult): void;
}

export interface TimelineExt {
$getTimeline(source: string, uri: UriComponents, options: theia.TimelineOptions, internalOptions?: InternalTimelineOptions): Promise<Timeline | undefined>;
}

export interface TimelineMain {
$registerTimelineProvider(provider: TimelineProviderDescriptor): Promise<void>;
$fireTimelineChanged(e: TimelineChangeEvent): Promise<void>;
$unregisterTimelineProvider(source: string): Promise<void>;
}

export interface DialogsMain {
$showOpenDialog(options: OpenDialogOptionsMain): Promise<string[] | undefined>;
$showSaveDialog(options: SaveDialogOptionsMain): Promise<string | undefined>;
Expand Down Expand Up @@ -657,6 +673,17 @@ export interface ScmExt {
$setSourceControlSelection(sourceControlHandle: number, selected: boolean): Promise<void>;
}

export namespace TimelineCommandArg {
export function is(arg: Object | undefined): arg is TimelineCommandArg {
return !!arg && typeof arg === 'object' && 'timelineHandle' in arg;
}
}
export interface TimelineCommandArg {
timelineHandle: string;
source: string;
uri: string;
}

export interface DecorationsExt {
registerDecorationProvider(provider: theia.DecorationProvider): theia.Disposable
$provideDecoration(id: number, uri: string): Promise<DecorationData | undefined>
Expand Down Expand Up @@ -1448,7 +1475,8 @@ export const PLUGIN_RPC_CONTEXT = {
DECORATIONS_MAIN: createProxyIdentifier<DecorationsMain>('DecorationsMain'),
WINDOW_MAIN: createProxyIdentifier<WindowMain>('WindowMain'),
CLIPBOARD_MAIN: <ProxyIdentifier<ClipboardMain>>createProxyIdentifier<ClipboardMain>('ClipboardMain'),
LABEL_SERVICE_MAIN: <ProxyIdentifier<LabelServiceMain>>createProxyIdentifier<LabelServiceMain>('LabelServiceMain')
LABEL_SERVICE_MAIN: <ProxyIdentifier<LabelServiceMain>>createProxyIdentifier<LabelServiceMain>('LabelServiceMain'),
TIMELINE_MAIN: <ProxyIdentifier<TimelineMain>>createProxyIdentifier<TimelineMain>('TimelineMain')
};

export const MAIN_RPC_CONTEXT = {
Expand All @@ -1475,7 +1503,8 @@ export const MAIN_RPC_CONTEXT = {
ExtHostFileSystemEventService: createProxyIdentifier<ExtHostFileSystemEventServiceShape>('ExtHostFileSystemEventService'),
SCM_EXT: createProxyIdentifier<ScmExt>('ScmExt'),
DECORATIONS_EXT: createProxyIdentifier<DecorationsExt>('DecorationsExt'),
LABEL_SERVICE_EXT: createProxyIdentifier<LabelServiceExt>('LabelServiceExt')
LABEL_SERVICE_EXT: createProxyIdentifier<LabelServiceExt>('LabelServiceExt'),
TIMELINE_EXT: createProxyIdentifier<TimelineExt>('TimeLineExt')
};

export interface TasksExt {
Expand Down
4 changes: 4 additions & 0 deletions packages/plugin-ext/src/main/browser/main-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { UntitledResourceResolver } from './editor/untitled-resource';
import { FileResourceResolver } from '@theia/filesystem/lib/browser';
import { MainFileSystemEventService } from './main-file-system-event-service';
import { LabelServiceMainImpl } from '../browser/label-service-main';
import { TimelineMainImpl } from './timeline-main';

export function setUpPluginApi(rpc: RPCProtocol, container: interfaces.Container): void {
const commandRegistryMain = new CommandRegistryMainImpl(rpc, container);
Expand Down Expand Up @@ -151,4 +152,7 @@ export function setUpPluginApi(rpc: RPCProtocol, container: interfaces.Container

const labelServiceMain = new LabelServiceMainImpl(container);
rpc.set(PLUGIN_RPC_CONTEXT.LABEL_SERVICE_MAIN, labelServiceMain);

const timelineMain = new TimelineMainImpl(rpc, container);
rpc.set(PLUGIN_RPC_CONTEXT.TIMELINE_MAIN, timelineMain);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { TabBarToolbarRegistry, TabBarToolbarItem } from '@theia/core/lib/browse
import { NAVIGATOR_CONTEXT_MENU } from '@theia/navigator/lib/browser/navigator-contribution';
import { QuickCommandService } from '@theia/core/lib/browser/quick-open/quick-command-service';
import { VIEW_ITEM_CONTEXT_MENU, TreeViewWidget, VIEW_ITEM_INLINE_MENU } from '../view/tree-view-widget';
import { DeployedPlugin, Menu, ScmCommandArg, TreeViewSelection } from '../../../common';
import { DeployedPlugin, Menu, ScmCommandArg, TimelineCommandArg, TreeViewSelection } from '../../../common';
import { DebugStackFramesWidget } from '@theia/debug/lib/browser/view/debug-stack-frames-widget';
import { DebugThreadsWidget } from '@theia/debug/lib/browser/view/debug-threads-widget';
import { TreeWidgetSelection } from '@theia/core/lib/browser/tree/tree-widget-selection';
Expand All @@ -41,6 +41,8 @@ import { ViewContextKeyService } from '../view/view-context-key-service';
import { WebviewWidget } from '../webview/webview';
import { Navigatable } from '@theia/core/lib/browser/navigatable';
import { ContextKeyService } from '@theia/core/lib/browser/context-key-service';
import { TIMELINE_ITEM_CONTEXT_MENU } from '@theia/timeline/lib/browser/timeline-tree-widget';
import { TimelineItem } from '@theia/timeline/lib/common/timeline-model';

type CodeEditorWidget = EditorWidget | WebviewWidget;
export namespace CodeEditorWidget {
Expand Down Expand Up @@ -147,6 +149,16 @@ export class MenusContributionPointHandler {
const menuPath = inline ? ScmTreeWidget.RESOURCE_INLINE_MENU : ScmTreeWidget.RESOURCE_CONTEXT_MENU;
toDispose.push(this.registerScmMenuAction(menuPath, menu));
}
} else if (location === 'timeline/item/context') {
for (const menu of allMenus[location]) {
toDispose.push(this.registerMenuAction(TIMELINE_ITEM_CONTEXT_MENU, menu,
command => ({
execute: (...args) => this.commands.executeCommand(command, ...this.toTimelineArgs(...args)),
isEnabled: (...args) => this.commands.isEnabled(command, ...this.toTimelineArgs(...args)),
isVisible: (...args) => this.commands.isVisible(command, ...this.toTimelineArgs(...args))
})
));
}
} else if (location === 'debug/callstack/context') {
for (const menu of allMenus[location]) {
for (const menuPath of [DebugStackFramesWidget.CONTEXT_MENU, DebugThreadsWidget.CONTEXT_MENU]) {
Expand Down Expand Up @@ -290,6 +302,22 @@ export class MenusContributionPointHandler {
}
}

protected toTimelineArgs(...args: any[]): any[] {
const timelineArgs: any[] = [];
const arg = args[0];
timelineArgs.push(this.toTimelineArg(arg));
timelineArgs.push(CodeUri.parse(arg.uri));
timelineArgs.push('source' in arg ? arg.source : '');
return timelineArgs;
}
protected toTimelineArg(arg: TimelineItem): TimelineCommandArg {
return {
timelineHandle: arg.handle,
source: arg.source,
uri: arg.uri
};
}

protected registerGlobalMenuAction(menuPath: MenuPath, menu: Menu): Disposable {
const selectedResource = () => {
const selection = this.selectionService.selection;
Expand Down
81 changes: 81 additions & 0 deletions packages/plugin-ext/src/main/browser/timeline-main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/********************************************************************************
* Copyright (C) 2018 Red Hat, Inc. 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 'inversify';
import { TimelineMain } from '../../common/plugin-api-rpc';
import { RPCProtocol } from '../../common/rpc-protocol';
import { TimelineService } from '@theia/timeline/lib/browser/timeline-service';
import { Emitter } from '@theia/core/lib/common';
import { URI } from 'vscode-uri';
import { MAIN_RPC_CONTEXT, TimelineExt } from '../../common/plugin-api-rpc';
import {
InternalTimelineOptions,
Timeline,
TimelineOptions,
TimelineProviderDescriptor,
TimelineChangeEvent
} from '@theia/timeline/lib/common/timeline-model';

/*---------------------------------------------------------------------------------------------
* 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/afacd2bdfe7060f09df9b9139521718915949757/src/vs/workbench/api/browser/mainThreadTimeline.ts

export class TimelineMainImpl implements TimelineMain {
private readonly proxy: TimelineExt;
private readonly timelineService: TimelineService;
private readonly providerEmitters = new Map<string, Emitter<TimelineChangeEvent>>();
constructor(rpc: RPCProtocol, container: interfaces.Container) {
this.proxy = rpc.getProxy(MAIN_RPC_CONTEXT.TIMELINE_EXT);
this.timelineService = container.get<TimelineService>(TimelineService);
}

async $registerTimelineProvider(provider: TimelineProviderDescriptor): Promise<void> {
const proxy = this.proxy;

const emitters = this.providerEmitters;
let onDidChange = emitters.get(provider.id);
if (onDidChange === undefined) {
onDidChange = new Emitter<TimelineChangeEvent>();
emitters.set(provider.id, onDidChange);
}

this.timelineService.registerTimelineProvider({
...provider,
onDidChange: onDidChange.event,
provideTimeline(uri: URI, options: TimelineOptions, internalOptions?: InternalTimelineOptions): Promise<Timeline | undefined> {
return proxy.$getTimeline(provider.id, uri, options, internalOptions);
},
dispose(): void {
emitters.delete(provider.id);
if (onDidChange) {
onDidChange.dispose();
}
}
});
}

async $unregisterTimelineProvider(id: string): Promise<void> {
this.timelineService.unregisterTimelineProvider(id);
}

async $fireTimelineChanged(e: TimelineChangeEvent): Promise<void> {
const emitter = this.providerEmitters.get(e.id);
if (emitter) {
emitter.fire(e);
}
}
}
11 changes: 9 additions & 2 deletions packages/plugin-ext/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ import {
CommentMode,
CallHierarchyItem,
CallHierarchyIncomingCall,
CallHierarchyOutgoingCall
CallHierarchyOutgoingCall,
TimelineItem
} from './types-impl';
import { SymbolKind } from '../common/plugin-api-rpc-model';
import { EditorsAndDocumentsExtImpl } from './editors-and-documents';
Expand Down Expand Up @@ -151,6 +152,7 @@ import { ClipboardExt } from './clipboard-ext';
import { WebviewsExtImpl } from './webviews';
import { ExtHostFileSystemEventService } from './file-system-event-service-ext-impl';
import { LabelServiceExtImpl } from '../plugin/label-service';
import { TimelineExtImpl } from './timeline';

export function createAPIFactory(
rpc: RPCProtocol,
Expand Down Expand Up @@ -184,6 +186,7 @@ export function createAPIFactory(
const scmExt = rpc.set(MAIN_RPC_CONTEXT.SCM_EXT, new ScmExtImpl(rpc, commandRegistry));
const decorationsExt = rpc.set(MAIN_RPC_CONTEXT.DECORATIONS_EXT, new DecorationsExtImpl(rpc));
const labelServiceExt = rpc.set(MAIN_RPC_CONTEXT.LABEL_SERVICE_EXT, new LabelServiceExtImpl(rpc));
const timelineExt = rpc.set(MAIN_RPC_CONTEXT.TIMELINE_EXT, new TimelineExtImpl(rpc, commandRegistry));
rpc.set(MAIN_RPC_CONTEXT.DEBUG_EXT, debugExt);

return function (plugin: InternalPlugin): typeof theia {
Expand Down Expand Up @@ -496,6 +499,9 @@ export function createAPIFactory(
},
registerResourceLabelFormatter(formatter: ResourceLabelFormatter): theia.Disposable {
return labelServiceExt.$registerResourceLabelFormatter(formatter);
},
registerTimelineProvider(scheme: string | string[], provider: theia.TimelineProvider): theia.Disposable {
return timelineExt.registerTimelineProvider(plugin, scheme, provider);
}
};

Expand Down Expand Up @@ -873,7 +879,8 @@ export function createAPIFactory(
CommentMode,
CallHierarchyItem,
CallHierarchyIncomingCall,
CallHierarchyOutgoingCall
CallHierarchyOutgoingCall,
TimelineItem
};
};
}
Expand Down
Loading