timeline.ts 3.1 KB
Newer Older
1 2 3 4 5
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

6
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
7 8 9
import { Event } from 'vs/base/common/event';
import { IDisposable } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
10
import { Command } from 'vs/editor/common/modes';
11 12 13 14 15 16 17
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';

export function toKey(extension: ExtensionIdentifier | string, source: string) {
	return `${typeof extension === 'string' ? extension : ExtensionIdentifier.toKey(extension)}|${source}`;
}

18 19
export const TimelinePaneId = 'timeline';

20
export interface TimelineItem {
21 22 23
	handle: string;
	source: string;

24
	id?: string;
E
Eric Amodio 已提交
25
	timestamp: number;
26
	label: string;
27 28 29
	icon?: URI,
	iconDark?: URI,
	themeIcon?: { id: string },
30 31
	description?: string;
	detail?: string;
32 33
	command?: Command;
	contextValue?: string;
34 35
}

36
export interface TimelineChangeEvent {
37
	id?: string;
38
	uri?: URI;
39
	reset?: boolean
40 41
}

42 43
export interface TimelineOptions {
	cursor?: string;
E
Eric Amodio 已提交
44
	before?: boolean;
45
	limit?: number | { cursor: string };
E
Eric Amodio 已提交
46 47
}

48 49 50 51 52
export interface InternalTimelineOptions {
	cacheResults: boolean;
	resetCache: boolean;
}

E
Eric Amodio 已提交
53 54
export interface Timeline {
	source: string;
55
	items: TimelineItem[];
E
Eric Amodio 已提交
56

57 58 59 60 61 62 63
	paging?: {
		cursors: {
			before: string;
			after?: string
		};
		more?: boolean;
	}
E
Eric Amodio 已提交
64 65
}

66
export interface TimelineProvider extends TimelineProviderDescriptor, IDisposable {
67
	onDidChange?: Event<TimelineChangeEvent>;
68

69
	provideTimeline(uri: URI, options: TimelineOptions, token: CancellationToken, internalOptions?: InternalTimelineOptions): Promise<Timeline | undefined>;
70 71
}

E
Eric Amodio 已提交
72 73 74 75 76
export interface TimelineSource {
	id: string;
	label: string;
}

77
export interface TimelineProviderDescriptor {
78 79
	id: string;
	label: string;
80
	scheme: string | string[];
81 82
}

83 84 85 86 87 88
export interface TimelineProvidersChangeEvent {
	readonly added?: string[];
	readonly removed?: string[];
}

export interface TimelineRequest {
E
Eric Amodio 已提交
89
	readonly result: Promise<Timeline | undefined>;
90
	readonly options: TimelineOptions;
91 92 93 94 95
	readonly source: string;
	readonly tokenSource: CancellationTokenSource;
	readonly uri: URI;
}

96 97 98
export interface ITimelineService {
	readonly _serviceBrand: undefined;

99 100
	onDidChangeProviders: Event<TimelineProvidersChangeEvent>;
	onDidChangeTimeline: Event<TimelineChangeEvent>;
101
	onDidChangeUri: Event<URI>;
102

103
	registerTimelineProvider(provider: TimelineProvider): IDisposable;
104 105
	unregisterTimelineProvider(id: string): void;

E
Eric Amodio 已提交
106
	getSources(): TimelineSource[];
107

108
	getTimeline(id: string, uri: URI, options: TimelineOptions, tokenSource: CancellationTokenSource, internalOptions?: InternalTimelineOptions): TimelineRequest | undefined;
109

110
	setUri(uri: URI): void;
111 112 113 114
}

const TIMELINE_SERVICE_ID = 'timeline';
export const ITimelineService = createDecorator<ITimelineService>(TIMELINE_SERVICE_ID);