extensionManagement.ts 7.2 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5 6 7
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

'use strict';

8
import { localize } from 'vs/nls';
9
import { TPromise } from 'vs/base/common/winjs.base';
E
Erich Gamma 已提交
10
import Event from 'vs/base/common/event';
J
Joao Moreno 已提交
11
import { IPager } from 'vs/base/common/paging';
12
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
E
Erich Gamma 已提交
13

S
Sandeep Somavarapu 已提交
14
export const EXTENSION_IDENTIFIER_PATTERN = '^[a-z0-9A-Z][a-z0-9\-A-Z]*\\.[a-z0-9A-Z][a-z0-9\-A-Z]*$';
S
Sandeep Somavarapu 已提交
15
export const EXTENSION_IDENTIFIER_REGEX = new RegExp(EXTENSION_IDENTIFIER_PATTERN);
S
Sandeep Somavarapu 已提交
16

17 18 19 20 21 22 23 24 25
export interface ICommand {
	command: string;
	title: string;
	category?: string;
}

export interface IConfigurationProperty {
	description: string;
	type: string | string[];
J
Joao Moreno 已提交
26
	default?: any;
27 28 29 30 31 32 33
}

export interface IConfiguration {
	properties: { [key: string]: IConfigurationProperty; };
}

export interface IDebugger {
J
Joao Moreno 已提交
34 35
	label?: string;
	type: string;
36 37 38 39 40 41 42 43 44 45 46
	runtime: string;
}

export interface IGrammar {
	language: string;
}

export interface IJSONValidation {
	fileMatch: string;
}

47
export interface IKeyBinding {
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
	command: string;
	key: string;
	when?: string;
	mac?: string;
	linux?: string;
	win?: string;
}

export interface ILanguage {
	id: string;
	extensions: string[];
	aliases: string[];
}

export interface IMenu {
	command: string;
	alt?: string;
	when?: string;
	group?: string;
}

export interface ISnippet {
	language: string;
}

J
Joao Moreno 已提交
73 74 75 76
export interface ITheme {
	label: string;
}

77
export interface ITreeExplorer {
P
Pine Wu 已提交
78 79
	treeExplorerNodeProviderId: string;
	treeLabel: string;
80 81 82
	icon: string;
}

83 84 85 86 87 88
export interface IExtensionContributions {
	commands?: ICommand[];
	configuration?: IConfiguration;
	debuggers?: IDebugger[];
	grammars?: IGrammar[];
	jsonValidation?: IJSONValidation[];
89
	keybindings?: IKeyBinding[];
90 91 92
	languages?: ILanguage[];
	menus?: { [context: string]: IMenu[] };
	snippets?: ISnippet[];
J
Joao Moreno 已提交
93
	themes?: ITheme[];
94
	explorer?: ITreeExplorer;
95 96
}

E
Erich Gamma 已提交
97 98 99 100
export interface IExtensionManifest {
	name: string;
	publisher: string;
	version: string;
101
	engines: { vscode: string };
E
Erich Gamma 已提交
102 103
	displayName?: string;
	description?: string;
J
Joao Moreno 已提交
104
	main?: string;
J
Joao Moreno 已提交
105
	icon?: string;
106 107
	categories?: string[];
	activationEvents?: string[];
108
	extensionDependencies?: string[];
109
	contributes?: IExtensionContributions;
E
Erich Gamma 已提交
110 111
}

J
Joao Moreno 已提交
112 113 114 115 116
export interface IExtensionIdentity {
	name: string;
	publisher: string;
}

117 118
export interface IGalleryExtensionProperties {
	dependencies?: string[];
119
	engine?: string;
120 121
}

122 123 124
export interface IGalleryExtensionAssets {
	manifest: string;
	readme: string;
125
	changelog: string;
126 127
	download: string;
	icon: string;
128
	iconFallback: string;
129 130 131
	license: string;
}

J
Joao Moreno 已提交
132 133 134
export interface IGalleryExtension {
	id: string;
	name: string;
135 136
	version: string;
	date: string;
J
Joao Moreno 已提交
137
	displayName: string;
E
Erich Gamma 已提交
138
	publisherId: string;
J
Joao Moreno 已提交
139
	publisher: string;
E
Erich Gamma 已提交
140
	publisherDisplayName: string;
J
Joao Moreno 已提交
141
	description: string;
J
Joao Moreno 已提交
142
	installCount: number;
J
Joao Moreno 已提交
143 144
	rating: number;
	ratingCount: number;
145
	assets: IGalleryExtensionAssets;
146
	properties: IGalleryExtensionProperties;
E
Erich Gamma 已提交
147 148
}

J
Joao Moreno 已提交
149
export interface IGalleryMetadata {
150 151 152
	id: string;
	publisherId: string;
	publisherDisplayName: string;
J
Joao Moreno 已提交
153 154
}

J
Joao Moreno 已提交
155 156 157 158 159
export enum LocalExtensionType {
	System,
	User
}

J
Joao Moreno 已提交
160
export interface ILocalExtension {
J
Joao Moreno 已提交
161
	type: LocalExtensionType;
J
Joao Moreno 已提交
162
	id: string;
J
Joao Moreno 已提交
163
	manifest: IExtensionManifest;
J
Joao Moreno 已提交
164
	metadata: IGalleryMetadata;
J
Joao Moreno 已提交
165
	path: string;
J
Joao Moreno 已提交
166
	readmeUrl: string;
167
	changelogUrl: string;
J
Joao Moreno 已提交
168 169
}

J
Joao Moreno 已提交
170 171
export const IExtensionManagementService = createDecorator<IExtensionManagementService>('extensionManagementService');
export const IExtensionGalleryService = createDecorator<IExtensionGalleryService>('extensionGalleryService');
E
Erich Gamma 已提交
172

J
Joao Moreno 已提交
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
export enum SortBy {
	NoneOrRelevance = 0,
	LastUpdatedDate = 1,
	Title = 2,
	PublisherName = 3,
	InstallCount = 4,
	PublishedDate = 5,
	AverageRating = 6
}

export enum SortOrder {
	Default = 0,
	Ascending = 1,
	Descending = 2
}

J
Joao Moreno 已提交
189 190
export interface IQueryOptions {
	text?: string;
J
Joao Moreno 已提交
191
	ids?: string[];
192
	names?: string[];
J
Joao Moreno 已提交
193
	pageSize?: number;
J
Joao Moreno 已提交
194 195
	sortBy?: SortBy;
	sortOrder?: SortOrder;
J
Joao Moreno 已提交
196 197
}

J
Joao Moreno 已提交
198
export interface IExtensionGalleryService {
199
	_serviceBrand: any;
E
Erich Gamma 已提交
200
	isEnabled(): boolean;
J
Joao Moreno 已提交
201
	getRequestHeaders(): TPromise<{ [key: string]: string; }>;
J
Joao Moreno 已提交
202
	query(options?: IQueryOptions): TPromise<IPager<IGalleryExtension>>;
203
	download(extension: IGalleryExtension): TPromise<string>;
204 205
	getReadme(extension: IGalleryExtension): TPromise<string>;
	getManifest(extension: IGalleryExtension): TPromise<IExtensionManifest>;
206 207
	loadCompatibleVersion(extension: IGalleryExtension): TPromise<IGalleryExtension>;
	getAllDependencies(extension: IGalleryExtension): TPromise<IGalleryExtension[]>;
E
Erich Gamma 已提交
208 209
}

210 211 212 213 214 215 216 217 218 219 220 221 222
export interface InstallExtensionEvent {
	id: string;
	zipPath?: string;
	gallery?: IGalleryExtension;
}

export interface DidInstallExtensionEvent {
	id: string;
	zipPath?: string;
	gallery?: IGalleryExtension;
	local?: ILocalExtension;
	error?: Error;
}
J
Joao Moreno 已提交
223

S
Sandeep Somavarapu 已提交
224 225 226 227 228
export interface DidUninstallExtensionEvent {
	id: string;
	error?: Error;
}

J
Joao Moreno 已提交
229
export interface IExtensionManagementService {
230
	_serviceBrand: any;
E
Erich Gamma 已提交
231

J
Joao Moreno 已提交
232
	onInstallExtension: Event<InstallExtensionEvent>;
J
Joao Moreno 已提交
233 234
	onDidInstallExtension: Event<DidInstallExtensionEvent>;
	onUninstallExtension: Event<string>;
S
Sandeep Somavarapu 已提交
235
	onDidUninstallExtension: Event<DidUninstallExtensionEvent>;
J
Joao Moreno 已提交
236 237

	install(zipPath: string): TPromise<void>;
S
Sandeep Somavarapu 已提交
238
	installFromGallery(extension: IGalleryExtension, promptToInstallDependencies?: boolean): TPromise<void>;
J
Joao Moreno 已提交
239
	uninstall(extension: ILocalExtension): TPromise<void>;
J
Joao Moreno 已提交
240
	getInstalled(type?: LocalExtensionType): TPromise<ILocalExtension[]>;
E
Erich Gamma 已提交
241
}
242

243 244 245 246 247 248 249 250 251
export const IExtensionEnablementService = createDecorator<IExtensionEnablementService>('extensionEnablementService');

// TODO: @sandy: Merge this into IExtensionManagementService when we have a storage service available in Shared process
export interface IExtensionEnablementService {
	_serviceBrand: any;

	/**
	 * Event to listen on for extension enablement changes
	 */
252
	onEnablementChanged: Event<string>;
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282

	/**
	 * Returns all globally disabled extension identifiers.
	 * Returns an empty array if none exist.
	 */
	getGloballyDisabledExtensions(): string[];

	/**
	 * Returns all workspace disabled extension identifiers.
	 * Returns an empty array if none exist or workspace does not exist.
	 */
	getWorkspaceDisabledExtensions(): string[];

	/**
	 * Returns `true` if given extension can be enabled by calling `setEnablement`, otherwise false`.
	 */
	canEnable(identifier: string): boolean;

	/**
	 * Enable or disable the given extension.
	 * if `workspace` is `true` then enablement is done for workspace, otherwise globally.
	 *
	 * Returns a promise that resolves to boolean value.
	 * if resolves to `true` then requires restart for the change to take effect.
	 *
	 * Throws error if enablement is requested for workspace and there is no workspace
	 */
	setEnablement(identifier: string, enable: boolean, workspace?: boolean): TPromise<boolean>;
}

J
Joao Moreno 已提交
283
export const IExtensionTipsService = createDecorator<IExtensionTipsService>('extensionTipsService');
284 285

export interface IExtensionTipsService {
286
	_serviceBrand: any;
287
	getRecommendations(): string[];
288
	getWorkspaceRecommendations(): TPromise<string[]>;
289 290
}

291
export const ExtensionsLabel = localize('extensions', "Extensions");
292
export const ExtensionsChannelId = 'extensions';