mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-23 01:58:53 +01:00
Adds timeline view & api providers (wip) — #84297
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as nls from 'vs/nls';
|
||||
import { CancellationTokenSource } from 'vs/base/common/cancellation';
|
||||
import { CancellationTokenSource, CancellationToken } from 'vs/base/common/cancellation';
|
||||
import * as errors from 'vs/base/common/errors';
|
||||
import { Emitter, Event } from 'vs/base/common/event';
|
||||
import * as path from 'vs/base/common/path';
|
||||
@@ -71,6 +71,7 @@ import { ExtHostTheming } from 'vs/workbench/api/common/extHostTheming';
|
||||
import { IExtHostTunnelService } from 'vs/workbench/api/common/extHostTunnelService';
|
||||
import { IExtHostApiDeprecationService } from 'vs/workbench/api/common/extHostApiDeprecationService';
|
||||
import { ExtHostAuthentication } from 'vs/workbench/api/common/extHostAuthentication';
|
||||
import { ExtHostTimeline } from 'vs/workbench/api/common/extHostTimeline';
|
||||
|
||||
export interface IExtensionApiFactory {
|
||||
(extension: IExtensionDescription, registry: ExtensionDescriptionRegistry, configProvider: ExtHostConfigProvider): typeof vscode;
|
||||
@@ -132,6 +133,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
||||
const extHostLabelService = rpcProtocol.set(ExtHostContext.ExtHostLabelService, new ExtHostLabelService(rpcProtocol));
|
||||
const extHostTheming = rpcProtocol.set(ExtHostContext.ExtHostTheming, new ExtHostTheming(rpcProtocol));
|
||||
const extHostAuthentication = rpcProtocol.set(ExtHostContext.ExtHostAuthentication, new ExtHostAuthentication(rpcProtocol));
|
||||
const extHostTimelineService = rpcProtocol.set(ExtHostContext.ExtHostTimeline, new ExtHostTimeline(rpcProtocol));
|
||||
|
||||
// Check that no named customers are missing
|
||||
const expected: ProxyIdentifier<any>[] = values(ExtHostContext);
|
||||
@@ -761,6 +763,17 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
||||
onDidTunnelsChange: (listener, thisArg?, disposables?) => {
|
||||
checkProposedApiEnabled(extension);
|
||||
return extHostTunnelService.onDidTunnelsChange(listener, thisArg, disposables);
|
||||
|
||||
},
|
||||
registerTimelineProvider: (scheme: string, provider: vscode.TimelineProvider) => {
|
||||
checkProposedApiEnabled(extension);
|
||||
return extHostTimelineService.registerTimelineProvider(extension.identifier, {
|
||||
id: provider.id,
|
||||
async provideTimeline(uri: URI, since: number, token: CancellationToken) {
|
||||
const results = await provider.provideTimeline(uri, since, token);
|
||||
return results ?? [];
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -984,7 +997,8 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
||||
Decoration: extHostTypes.Decoration,
|
||||
WebviewContentState: extHostTypes.WebviewContentState,
|
||||
UIKind: UIKind,
|
||||
ColorThemeKind: extHostTypes.ColorThemeKind
|
||||
ColorThemeKind: extHostTypes.ColorThemeKind,
|
||||
TimelineItem: extHostTypes.TimelineItem
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ import { SaveReason } from 'vs/workbench/common/editor';
|
||||
import { ExtensionActivationReason } from 'vs/workbench/api/common/extHostExtensionActivator';
|
||||
import { TunnelDto } from 'vs/workbench/api/common/extHostTunnelService';
|
||||
import { TunnelOptions } from 'vs/platform/remote/common/tunnel';
|
||||
import { TimelineItem } from 'vs/workbench/contrib/timeline/common/timeline';
|
||||
|
||||
export interface IEnvironment {
|
||||
isExtensionDevelopmentDebug: boolean;
|
||||
@@ -797,6 +798,13 @@ export interface MainThreadTunnelServiceShape extends IDisposable {
|
||||
$setCandidateFilter(): Promise<void>;
|
||||
}
|
||||
|
||||
export interface MainThreadTimelineShape extends IDisposable {
|
||||
$registerTimelineProvider(key: string, id: string): void;
|
||||
$unregisterTimelineProvider(key: string): void;
|
||||
|
||||
$getTimeline(resource: UriComponents, since: number, token: CancellationToken): Promise<TimelineItem[]>;
|
||||
}
|
||||
|
||||
// -- extension host
|
||||
|
||||
export interface ExtHostCommandsShape {
|
||||
@@ -1441,6 +1449,12 @@ export interface ExtHostTunnelServiceShape {
|
||||
$onDidTunnelsChange(): Promise<void>;
|
||||
}
|
||||
|
||||
export interface ExtHostTimelineShape {
|
||||
// $registerTimelineProvider(handle: number, provider: TimelineProvider): void;
|
||||
|
||||
$getTimeline(key: string, uri: UriComponents, since: number, token: CancellationToken): Promise<TimelineItem[]>;
|
||||
}
|
||||
|
||||
// --- proxy identifiers
|
||||
|
||||
export const MainContext = {
|
||||
@@ -1484,7 +1498,8 @@ export const MainContext = {
|
||||
MainThreadWindow: createMainId<MainThreadWindowShape>('MainThreadWindow'),
|
||||
MainThreadLabelService: createMainId<MainThreadLabelServiceShape>('MainThreadLabelService'),
|
||||
MainThreadTheming: createMainId<MainThreadThemingShape>('MainThreadTheming'),
|
||||
MainThreadTunnelService: createMainId<MainThreadTunnelServiceShape>('MainThreadTunnelService')
|
||||
MainThreadTunnelService: createMainId<MainThreadTunnelServiceShape>('MainThreadTunnelService'),
|
||||
MainThreadTimeline: createMainId<MainThreadTimelineShape>('MainThreadTimeline')
|
||||
};
|
||||
|
||||
export const ExtHostContext = {
|
||||
@@ -1521,5 +1536,6 @@ export const ExtHostContext = {
|
||||
ExtHostLabelService: createMainId<ExtHostLabelServiceShape>('ExtHostLabelService'),
|
||||
ExtHostTheming: createMainId<ExtHostThemingShape>('ExtHostTheming'),
|
||||
ExtHostTunnelService: createMainId<ExtHostTunnelServiceShape>('ExtHostTunnelService'),
|
||||
ExtHostAuthentication: createMainId<ExtHostAuthenticationShape>('ExtHostAuthentication')
|
||||
ExtHostAuthentication: createMainId<ExtHostAuthenticationShape>('ExtHostAuthentication'),
|
||||
ExtHostTimeline: createMainId<ExtHostTimelineShape>('ExtHostTimeline')
|
||||
};
|
||||
|
||||
80
src/vs/workbench/api/common/extHostTimeline.ts
Normal file
80
src/vs/workbench/api/common/extHostTimeline.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import { UriComponents, URI } from 'vs/base/common/uri';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { ExtHostTimelineShape, MainThreadTimelineShape, IMainContext, MainContext } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { TimelineItem, TimelineProvider, toKey } from 'vs/workbench/contrib/timeline/common/timeline';
|
||||
import { IDisposable, toDisposable } from 'vs/base/common/lifecycle';
|
||||
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
|
||||
|
||||
export interface IExtHostTimeline extends ExtHostTimelineShape {
|
||||
readonly _serviceBrand: undefined;
|
||||
$getTimeline(key: string, uri: UriComponents, since: number, token: vscode.CancellationToken): Promise<TimelineItem[]>;
|
||||
}
|
||||
|
||||
export const IExtHostTimeline = createDecorator<IExtHostTimeline>('IExtHostTimeline');
|
||||
|
||||
export class ExtHostTimeline implements IExtHostTimeline {
|
||||
_serviceBrand: undefined;
|
||||
|
||||
private _proxy: MainThreadTimelineShape;
|
||||
|
||||
private _providers = new Map<string, TimelineProvider>();
|
||||
|
||||
constructor(
|
||||
mainContext: IMainContext,
|
||||
|
||||
) {
|
||||
this._proxy = mainContext.getProxy(MainContext.MainThreadTimeline);
|
||||
|
||||
this.registerTimelineProvider('bar', {
|
||||
id: 'baz',
|
||||
async provideTimeline(uri: URI, since: number, token: vscode.CancellationToken) {
|
||||
return [
|
||||
{
|
||||
id: '1',
|
||||
label: 'Bar Timeline1',
|
||||
description: uri.toString(true),
|
||||
detail: new Date().toString(),
|
||||
date: Date.now(),
|
||||
source: 'log'
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
label: 'Bar Timeline2',
|
||||
description: uri.toString(true),
|
||||
detail: new Date(Date.now() - 100).toString(),
|
||||
date: Date.now() - 100,
|
||||
source: 'log'
|
||||
}
|
||||
];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async $getTimeline(key: string, uri: UriComponents, since: number, token: vscode.CancellationToken): Promise<TimelineItem[]> {
|
||||
const provider = this._providers.get(key);
|
||||
return provider?.provideTimeline(URI.revive(uri), since, token) ?? [];
|
||||
}
|
||||
|
||||
registerTimelineProvider(extension: ExtensionIdentifier | string, provider: TimelineProvider): IDisposable {
|
||||
console.log(`ExtHostTimeline#registerTimelineProvider: extension=${extension.toString()}, provider=${provider.id}`);
|
||||
|
||||
const key = toKey(extension, provider.id);
|
||||
if (this._providers.has(key)) {
|
||||
throw new Error(`Timeline Provider ${key} already exists.`);
|
||||
}
|
||||
|
||||
this._proxy.$registerTimelineProvider(key, provider.id);
|
||||
this._providers.set(key, provider);
|
||||
|
||||
return toDisposable(() => {
|
||||
this._providers.delete(key);
|
||||
this._proxy.$unregisterTimelineProvider(key);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -2544,3 +2544,12 @@ export enum ColorThemeKind {
|
||||
}
|
||||
|
||||
//#endregion Theming
|
||||
|
||||
//#region Timeline
|
||||
|
||||
@es5ClassCompat
|
||||
export class TimelineItem implements vscode.TimelineItem {
|
||||
constructor(public label: string, public date: number, public source: string) { }
|
||||
}
|
||||
|
||||
//#endregion Timeline
|
||||
|
||||
Reference in New Issue
Block a user