Skip to content

Test contributing timeline providers from extensions #89385

Closed

Description

@eamodio

Refs: #84297

Complexity: 4


Testing

Extensions can now contribute timeline providers to show time-series information in a new Timeline view in the Explorer sidebar.

Develop an extension that can contribute a TimelineProvider to provide time-series information given a Uri. Here is an example provider.

Here is the current API declarations:

//#region eamodio - timeline: https://github.com/microsoft/vscode/issues/84297
export class TimelineItem {
/**
* A timestamp (in milliseconds since 1 January 1970 00:00:00) for when the timeline item occurred
*/
timestamp: number;
/**
* A human-readable string describing the timeline item. When `falsy`, it is derived from [resourceUri](#TreeItem.resourceUri).
*/
label: string;
/**
* Optional id for the timeline item. See [TreeItem.id](#TreeItem.id) for more details.
*/
id?: string;
/**
* The icon path or [ThemeIcon](#ThemeIcon) for the timeline item. See [TreeItem.iconPath](#TreeItem.iconPath) for more details.
*/
iconPath?: Uri | { light: Uri; dark: Uri } | ThemeIcon;
/**
* A human readable string describing less prominent details of the timeline item. See [TreeItem.description](#TreeItem.description) for more details.
*/
description?: string;
/**
* The tooltip text when you hover over the timeline item.
*/
detail?: string;
/**
* The [command](#Command) that should be executed when the timeline item is selected.
*/
command?: Command;
/**
* Context value of the timeline item. See [TreeItem.contextValue](#TreeItem.contextValue) for more details.
*/
contextValue?: string;
/**
* @param label A human-readable string describing the timeline item
* @param timestamp A timestamp (in milliseconds since 1 January 1970 00:00:00) for when the timeline item occurred
* @param source A human-readable string describing the source of the timeline item
*/
constructor(label: string, timestamp: number, source: string);
}
export interface TimelineProvider {
onDidChange?: Event<Uri | undefined>;
/**
* An identifier of the source of the timeline items. This can be used for filtering and/or overriding existing sources.
*/
source: string;
/**
* A human-readable string describing the source of the timeline items. This can be as the display label when filtering by sources.
*/
sourceDescription: string;
replaceable?: boolean;
/**
* Provide [timeline items](#TimelineItem) for a [Uri](#Uri).
*
* @param uri The uri of the file to provide the timeline for.
* @param token A cancellation token.
* @return An array of timeline items or a thenable that resolves to such. The lack of a result
* can be signaled by returning `undefined`, `null`, or an empty array.
*/
provideTimeline(uri: Uri, token: CancellationToken): ProviderResult<TimelineItem[]>;
}
export namespace workspace {
/**
* Register a timeline provider.
*
* Multiple providers can be registered. In that case, providers are asked in
* parallel and the results are merged. A failing provider (rejected promise or exception) will
* not cause a failure of the whole operation.
*
* @param selector A selector that defines the documents this provider is applicable to.
* @param provider A timeline provider.
* @return A [disposable](#Disposable) that unregisters this provider when being disposed.
*/
export function registerTimelineProvider(selector: DocumentSelector, provider: TimelineProvider): Disposable;
}
//#endregion
)

  • Make sure there is a command contributed to each timeline item for the on click action.
  • Try making a provider take a while and make sure the view shows an indication of progress/loading
  • Try updating provider data after initial load (using onDidChange) and ensure the view is updated
  • For extra points, try setting replaceable to true and then register a replacement provider using the same source -- it should replace the existing one. Also try the same thing without setting replaceable (or set to false) and the second registration should error out.

Notes

  • The DocumentSelector as part of the registerTimelineProvider call isn't yet honored
  • You cannot (yet) attach context menus to timeline items

Activity

  1. Tyriar commented on Jan 28, 2020

    @Tyriar
    Contributor

    I can't get the API to work. With the following ext code:

    import * as vscode from 'vscode';
    
    const backups: { [uri: string]: string[] } = {};
    
    export function activate(context: vscode.ExtensionContext) {
    	console.log('activate');
    	context.subscriptions.push(vscode.workspace.onDidSaveTextDocument(d => {
    		const uri = d.uri.toString();
    		if (backups[uri] === undefined) {
    			backups[uri] = [];
    		}
    		backups[uri].push(d.getText());
    		console.log('backed up');
    	}));
    	const changeEmitter = new vscode.EventEmitter<vscode.Uri | undefined>();
    	context.subscriptions.push(vscode.workspace.registerTimelineProvider('*', {
    		source: 'my-magical-timeline-provider',
    		sourceDescription: 'My magical timeline provider',
    		provideTimeline: (uri: vscode.Uri, token: vscode.CancellationToken) => {
    			console.log('provide');
    			const result: vscode.TimelineItem[] = [
    				new (vscode.TimelineItem as any)('rawr', Date.now())
    			];
    			return result;
    		},
    		onDidChange: changeEmitter.event
    	}));
    }

    backed up gets logged but not provide:

    image

  2. Tyriar commented on Jan 29, 2020

    @Tyriar
    Contributor

    Tried again and still having problems, closing off as I'm blocked. Hopefully the root cause of the problem will surface before the API is stabilized.

  3. removed their assignment
    on Jan 29, 2020
  4. locked and limited conversation to collaborators on Mar 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions