Skip to content

Test contributing multiple timeline providers with paging from extensions #93820

Closed

Description

@eamodio

Refs: #84297

Complexity: 4


Similar to #91330.

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 declaration:

//#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.
*/
label: string;
/**
* Optional id for the timeline item. It must be unique across all the timeline items provided by this source.
*
* If not provided, an id is generated using the timeline item's timestamp.
*/
id?: string;
/**
* The icon path or [ThemeIcon](#ThemeIcon) for the timeline item.
*/
iconPath?: Uri | { light: Uri; dark: Uri } | ThemeIcon;
/**
* A human readable string describing less prominent details of the timeline item.
*/
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. This can be used to contribute specific actions to the item.
* For example, a timeline item is given a context value as `commit`. When contributing actions to `timeline/item/context`
* using `menus` extension point, you can specify context value for key `timelineItem` in `when` expression like `timelineItem == commit`.
* ```
* "contributes": {
* "menus": {
* "timeline/item/context": [
* {
* "command": "extension.copyCommitId",
* "when": "timelineItem == commit"
* }
* ]
* }
* }
* ```
* This will show the `extension.copyCommitId` action only for items where `contextValue` is `commit`.
*/
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
*/
constructor(label: string, timestamp: number);
}
export interface TimelineChangeEvent {
/**
* The [uri](#Uri) of the resource for which the timeline changed.
* If the [uri](#Uri) is `undefined` that signals that the timeline source for all resources changed.
*/
uri?: Uri;
/**
* A flag which indicates whether the entire timeline should be reset.
*/
reset?: boolean;
}
export interface Timeline {
readonly paging?: {
/**
* A provider-defined cursor specifying the starting point of timeline items which are after the ones returned.
* Use `undefined` to signal that there are no more items to be returned.
*/
readonly cursor: string | undefined;
}
/**
* An array of [timeline items](#TimelineItem).
*/
readonly items: readonly TimelineItem[];
}
export interface TimelineOptions {
/**
* A provider-defined cursor specifying the starting point of the timeline items that should be returned.
*/
cursor?: string;
/**
* An optional maximum number timeline items or the all timeline items newer (inclusive) than the timestamp or id that should be returned.
* If `undefined` all timeline items should be returned.
*/
limit?: number | { timestamp: number; id?: string };
}
export interface TimelineProvider {
/**
* An optional event to signal that the timeline for a source has changed.
* To signal that the timeline for all resources (uris) has changed, do not pass any argument or pass `undefined`.
*/
onDidChange?: Event<TimelineChangeEvent>;
/**
* An identifier of the source of the timeline items. This can be used to filter sources.
*/
readonly id: string;
/**
* A human-readable string describing the source of the timeline items. This can be used as the display label when filtering sources.
*/
readonly label: string;
/**
* Provide [timeline items](#TimelineItem) for a [Uri](#Uri).
*
* @param uri The [uri](#Uri) of the file to provide the timeline for.
* @param options A set of options to determine how results should be returned.
* @param token A cancellation token.
* @return The [timeline result](#TimelineResult) 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, options: TimelineOptions, token: CancellationToken): ProviderResult<Timeline>;
}
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 scheme A scheme or schemes that defines which documents this provider is applicable to. Can be `*` to target all documents.
* @param provider A timeline provider.
* @return A [disposable](#Disposable) that unregisters this provider when being disposed.
*/
export function registerTimelineProvider(scheme: string | string[], provider: TimelineProvider): Disposable;
}
//#endregion

For implementing paging follow the basic scenario guidelines here on how the provider will be called: #84297 (comment)

  • Please test with multiple providers and ensure stable paging (via Load more) and display. Also test with excluding sources from display using the timeline.excludeSources setting (or ... menu includes on the Timeline view)
  • Implement paging in the provider
  • Make sure there is a command contributed to each timeline item for the on click action.
  • Contribute a command to the timeline/item/context for specific timeline items
  • Try updating provider data after initial load (using onDidChange) and ensure the view is updated
    • Try using a TimelineChangeEvent with reset on/off
  • Ensure that if you fire an onDidChange event while the Timeline view is hidden/collapsed, your provideTimeline method isn't called until the Timeline view is shown again

Activity

  1. sandy081 commented on Apr 1, 2020

    @sandy081
    Member

    My sample User data history timeline is here - https://github.com/sandy081/userdata-timeline-sample

    I am half done on this.. pending (will continue tomorrow)

    • Testing multiple timeline providers
    • Contribute a command to the timeline/item/context for specific timeline items
    • Ensure that if you fire an onDidChange event while the Timeline view is hidden/collapsed, your provideTimeline method isn't called until the Timeline view is shown again

    Edit: Pending

    • Testing multiple timeline providers

    Edit: Done

  2. miguelsolorio commented on Apr 1, 2020

    @miguelsolorio
    Contributor

    I've a hard time getting setting up a timeline provider, below is as far as I could get from looking up various samples:

    import * as vscode from 'vscode';
    
    export class FirstTimelineProvider implements vscode.TimelineProvider {
    
    	onDidChange?: vscode.Event<vscode.TimelineChangeEvent> | undefined;
    	id = 'first-timeline';
    	label = 'First Timeline';
    
    	async provideTimeline(uri: vscode.Uri, options: vscode.TimelineOptions, token: vscode.CancellationToken): vscode.ProviderResult<vscode.Timeline> {
    		return Promise.resolve<vscode.Timeline>({
    			items: [
    				{
    					id: '1',
    					label: 'Fast Timeline1',
    					description: '',
    					timestamp: Date.now(),
    				},
    				{
    					id: '2',
    					label: 'Fast Timeline2',
    					description: '',
    					timestamp: Date.now() - 3000000000,
    				}
    			],
    			paging: {
    				cursor: 'next'
    			}
    		});
    	}
    }

    I'll likely defer this one to someone else.

  3. JacksonKearl commented on Apr 2, 2020

    @JacksonKearl
    Contributor

    My extension: https://github.com/JacksonKearl/vscode-solunar-timeline

    Please test with multiple providers and ensure stable paging (via Load more) and display. Also test with excluding sources from display using the timeline.excludeSources setting (or ... menu includes on the Timeline view)

    Paging seems to work fine, but the interface is a bit odd to work with. Proposal given in a separate issue.

    I did not implement the "fetch entire timeline" as for my extension that doesn't make any sense (infinite timeline). This didn't seem to have any effect on the runtime. As mentioned elsewhere, I think it would be good to separate out these different capabilities into individual methods that extensions can selectively choose to implement and core can detect what is available and work around that.

    Make sure there is a command contributed to each timeline item for the on click action.

    👍

    Contribute a command to the timeline/item/context for specific timeline items

    👍

    Try updating provider data after initial load (using onDidChange) and ensure the view is updated

    👍

    Try using a TimelineChangeEvent with reset on/off

    The purpose of reset isn't clear to me. In particular when you'd use reset: false (the default).

    Ensure that if you fire an onDidChange event while the Timeline view is hidden/collapsed, your provideTimeline method isn't called until the Timeline view is shown again

    👍

    Aside:

    I'd like to see future events better supported. Capping everything to the present seems artificially limiting. My extension is a bit esoteric sure, but I'd be inclined to make a real extension that, for instance, tells me how many days there are until code freeze/endgame. I think this could be simply implemented by mandating a fixed number of future events (no forward paging). Really the whole thing could remain as-is, just remove the cap on the rendered time.

  4. sandy081 commented on Apr 2, 2020

    @sandy081
    Member

    Done. Good job Eric Amodio (@eamodio) . Other than suggestions to the API Timeline view works flawlessly. 👏

  5. locked and limited conversation to collaborators on May 17, 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