Repository navigation
Closed
Labels
Milestone
Description
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:
vscode/src/vs/vscode.proposed.d.ts
Lines 1788 to 1941 in 21293c4
| //#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.excludeSourcessetting (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/contextfor specific timeline items - Try updating provider data after initial load (using
onDidChange) and ensure the view is updated- Try using a
TimelineChangeEventwithreseton/off
- Try using a
- Ensure that if you fire an
onDidChangeevent while the Timeline view is hidden/collapsed, yourprovideTimelinemethod isn't called until the Timeline view is shown again
Activity
sandy081 commentedon Apr 1, 2020
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)
Contribute a command to the timeline/item/context for specific timeline itemsEnsure 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 againEdit: Pending
Testing multiple timeline providersEdit: Done
miguelsolorio commentedon Apr 1, 2020
I've a hard time getting setting up a timeline provider, below is as far as I could get from looking up various samples:
I'll likely defer this one to someone else.
JacksonKearl commentedon Apr 2, 2020
My extension: https://github.com/JacksonKearl/vscode-solunar-timeline
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.
👍
👍
👍
The purpose of reset isn't clear to me. In particular when you'd use
reset: false(the default).👍
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.
sandy081 commentedon Apr 2, 2020
Done. Good job Eric Amodio (@eamodio) . Other than suggestions to the API Timeline view works flawlessly. 👏