extensionsActions.ts 150.3 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 'vs/css!./media/extensionActions';
7
import { localize } from 'vs/nls';
8
import { IAction, Action, Separator, SubmenuAction } from 'vs/base/common/actions';
9
import { Delayer } from 'vs/base/common/async';
10
import * as DOM from 'vs/base/browser/dom';
11
import { Event } from 'vs/base/common/event';
12
import * as json from 'vs/base/common/json';
13
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
M
Matt Bierner 已提交
14
import { dispose, Disposable } from 'vs/base/common/lifecycle';
S
Sandeep Somavarapu 已提交
15
import { IExtension, ExtensionState, IExtensionsWorkbenchService, VIEWLET_ID, IExtensionsViewPaneContainer, AutoUpdateConfigurationKey, IExtensionContainer, EXTENSIONS_CONFIG, TOGGLE_IGNORE_EXTENSION_ACTION_ID } from 'vs/workbench/contrib/extensions/common/extensions';
16
import { ExtensionsConfigurationInitialContent } from 'vs/workbench/contrib/extensions/common/extensionsFileTemplate';
17
import { IGalleryExtension, IExtensionGalleryService, INSTALL_ERROR_MALICIOUS, INSTALL_ERROR_INCOMPATIBLE, IGalleryExtensionVersion, ILocalExtension, INSTALL_ERROR_NOT_SUPPORTED } from 'vs/platform/extensionManagement/common/extensionManagement';
18
import { IWorkbenchExtensionEnablementService, EnablementState, IExtensionManagementServerService, IExtensionRecommendationsService, IExtensionsConfigContent, IExtensionManagementServer } from 'vs/workbench/services/extensionManagement/common/extensionManagement';
19
import { areSameExtensions } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
20
import { ExtensionType, ExtensionIdentifier, IExtensionDescription, IExtensionManifest, isLanguagePackExtension } from 'vs/platform/extensions/common/extensions';
21
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
B
Benjamin Pasero 已提交
22
import { ShowViewletAction } from 'vs/workbench/browser/viewlet';
B
Benjamin Pasero 已提交
23
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
24
import { Query } from 'vs/workbench/contrib/extensions/common/extensionQuery';
B
Benjamin Pasero 已提交
25
import { IFileService, IFileContent } from 'vs/platform/files/common/files';
S
Sandeep Somavarapu 已提交
26
import { IWorkspaceContextService, WorkbenchState, IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
27
import { IHostService } from 'vs/workbench/services/host/browser/host';
28
import { IExtensionService, toExtension } from 'vs/workbench/services/extensions/common/extensions';
29
import { URI } from 'vs/base/common/uri';
S
Sandeep Somavarapu 已提交
30
import { CommandsRegistry, ICommandService } from 'vs/platform/commands/common/commands';
31
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
M
Martin Aeschlimann 已提交
32
import { registerThemingParticipant, IColorTheme, ICssStyleCollector } from 'vs/platform/theme/common/themeService';
33 34
import { buttonBackground, buttonForeground, buttonHoverBackground, contrastBorder, registerColor, foreground } from 'vs/platform/theme/common/colorRegistry';
import { Color } from 'vs/base/common/color';
35 36 37
import { IJSONEditingService } from 'vs/workbench/services/configuration/common/jsonEditing';
import { ITextEditorSelection } from 'vs/platform/editor/common/editor';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
38
import { PagedModel } from 'vs/base/common/paging';
S
Sandeep Somavarapu 已提交
39 40
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
41
import { MenuRegistry, MenuId, IMenuService } from 'vs/platform/actions/common/actions';
I
isidor 已提交
42
import { PICK_WORKSPACE_FOLDER_COMMAND_ID } from 'vs/workbench/browser/actions/workspaceCommands';
J
Joao Moreno 已提交
43 44 45
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { mnemonicButtonLabel } from 'vs/base/common/labels';
46
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
47
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
48
import { ExtensionsInput } from 'vs/workbench/contrib/extensions/common/extensionsInput';
49
import { IQuickPickItem, IQuickInputService, IQuickPickSeparator } from 'vs/platform/quickinput/common/quickInput';
50
import { CancellationToken } from 'vs/base/common/cancellation';
51
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
52
import { alert } from 'vs/base/browser/ui/aria/aria';
M
Matt Bierner 已提交
53
import { coalesce } from 'vs/base/common/arrays';
54
import { IWorkbenchThemeService, IWorkbenchTheme, IWorkbenchColorTheme, IWorkbenchFileIconTheme, IWorkbenchProductIconTheme } from 'vs/workbench/services/themes/common/workbenchThemeService';
55
import { ILabelService } from 'vs/platform/label/common/label';
S
Sandeep Somavarapu 已提交
56
import { prefersExecuteOnUI, prefersExecuteOnWorkspace, canExecuteOnUI, canExecuteOnWorkspace } from 'vs/workbench/services/extensions/common/extensionsUtil';
57
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
58
import { IProductService } from 'vs/platform/product/common/productService';
S
Sandeep Somavarapu 已提交
59
import { IFileDialogService, IDialogService } from 'vs/platform/dialogs/common/dialogs';
60
import { IProgressService, ProgressLocation } from 'vs/platform/progress/common/progress';
61
import { Codicon } from 'vs/base/common/codicons';
S
Sandeep Somavarapu 已提交
62
import { IViewsService } from 'vs/workbench/common/views';
63
import { IActionViewItemOptions, ActionViewItem } from 'vs/base/browser/ui/actionbar/actionViewItems';
J
Joao Moreno 已提交
64

S
Sandeep Somavarapu 已提交
65
export function toExtensionDescription(local: ILocalExtension): IExtensionDescription {
S
Sandeep Somavarapu 已提交
66 67 68 69 70
	return {
		identifier: new ExtensionIdentifier(local.identifier.id),
		isBuiltin: local.type === ExtensionType.System,
		isUnderDevelopment: false,
		extensionLocation: local.location,
S
Sandeep Somavarapu 已提交
71 72
		...local.manifest,
		uuid: local.identifier.uuid
S
Sandeep Somavarapu 已提交
73 74 75
	};
}

76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
const promptDownloadManually = (extension: IGalleryExtension | undefined, message: string, error: Error, instantiationService: IInstantiationService): Promise<any> => {
	return instantiationService.invokeFunction(accessor => {
		const productService = accessor.get(IProductService);
		const openerService = accessor.get(IOpenerService);
		const notificationService = accessor.get(INotificationService);
		const dialogService = accessor.get(IDialogService);
		const erorrsToShows = [INSTALL_ERROR_INCOMPATIBLE, INSTALL_ERROR_MALICIOUS, INSTALL_ERROR_NOT_SUPPORTED];
		if (!extension || erorrsToShows.indexOf(error.name) !== -1 || !productService.extensionsGallery) {
			return dialogService.show(Severity.Error, error.message, []);
		} else {
			const downloadUrl = `${productService.extensionsGallery.serviceUrl}/publishers/${extension.publisher}/vsextensions/${extension.name}/${extension.version}/vspackage`;
			notificationService.prompt(Severity.Error, message, [{
				label: localize('download', "Download Manually"),
				run: () => openerService.open(URI.parse(downloadUrl)).then(() => {
					notificationService.prompt(
						Severity.Info,
						localize('install vsix', 'Once downloaded, please manually install the downloaded VSIX of \'{0}\'.', extension.identifier.id),
						[{
							label: InstallVSIXAction.LABEL,
							run: () => {
								const action = instantiationService.createInstance(InstallVSIXAction, InstallVSIXAction.ID, InstallVSIXAction.LABEL);
								action.run();
								action.dispose();
							}
						}]
					);
				})
			}]);
			return Promise.resolve();
		}
	});
107
};
108

109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
function getRelativeDateLabel(date: Date): string {
	const delta = new Date().getTime() - date.getTime();

	const year = 365 * 24 * 60 * 60 * 1000;
	if (delta > year) {
		const noOfYears = Math.floor(delta / year);
		return noOfYears > 1 ? localize('noOfYearsAgo', "{0} years ago", noOfYears) : localize('one year ago', "1 year ago");
	}

	const month = 30 * 24 * 60 * 60 * 1000;
	if (delta > month) {
		const noOfMonths = Math.floor(delta / month);
		return noOfMonths > 1 ? localize('noOfMonthsAgo', "{0} months ago", noOfMonths) : localize('one month ago', "1 month ago");
	}

	const day = 24 * 60 * 60 * 1000;
	if (delta > day) {
		const noOfDays = Math.floor(delta / day);
		return noOfDays > 1 ? localize('noOfDaysAgo', "{0} days ago", noOfDays) : localize('one day ago', "1 day ago");
	}

	const hour = 60 * 60 * 1000;
	if (delta > hour) {
		const noOfHours = Math.floor(delta / day);
		return noOfHours > 1 ? localize('noOfHoursAgo', "{0} hours ago", noOfHours) : localize('one hour ago', "1 hour ago");
	}

	if (delta > 0) {
		return localize('just now', "Just now");
	}

	return '';
}

S
Sandeep Somavarapu 已提交
143
export abstract class ExtensionAction extends Action implements IExtensionContainer {
S
Sandeep Somavarapu 已提交
144 145 146 147
	static readonly EXTENSION_ACTION_CLASS = 'extension-action';
	static readonly TEXT_ACTION_CLASS = `${ExtensionAction.EXTENSION_ACTION_CLASS} text`;
	static readonly LABEL_ACTION_CLASS = `${ExtensionAction.EXTENSION_ACTION_CLASS} label`;
	static readonly ICON_ACTION_CLASS = `${ExtensionAction.EXTENSION_ACTION_CLASS} icon`;
S
Sandeep Somavarapu 已提交
148 149 150
	private _extension: IExtension | null = null;
	get extension(): IExtension | null { return this._extension; }
	set extension(extension: IExtension | null) { this._extension = extension; this.update(); }
S
Sandeep Somavarapu 已提交
151
	abstract update(): void;
152
}
153

S
Sandeep Somavarapu 已提交
154
export class InstallAction extends ExtensionAction {
155

156 157
	private static readonly INSTALL_LABEL = localize('install', "Install");
	private static readonly INSTALLING_LABEL = localize('installing', "Installing");
158

S
Sandeep Somavarapu 已提交
159 160
	private static readonly Class = `${ExtensionAction.LABEL_ACTION_CLASS} prominent install`;
	private static readonly InstallingClass = `${ExtensionAction.LABEL_ACTION_CLASS} install installing`;
161

S
Sandeep Somavarapu 已提交
162
	private _manifest: IExtensionManifest | null = null;
163 164 165 166 167
	set manifest(manifest: IExtensionManifest) {
		this._manifest = manifest;
		this.updateLabel();
	}

168
	constructor(
169 170 171
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
		@IInstantiationService private readonly instantiationService: IInstantiationService,
		@INotificationService private readonly notificationService: INotificationService,
S
Sandeep Somavarapu 已提交
172
		@IExtensionService private readonly runtimeExtensionService: IExtensionService,
173 174
		@IWorkbenchThemeService private readonly workbenchThemeService: IWorkbenchThemeService,
		@IConfigurationService private readonly configurationService: IConfigurationService,
A
Alex Dima 已提交
175
		@IProductService private readonly productService: IProductService,
176 177
		@ILabelService private readonly labelService: ILabelService,
		@IExtensionManagementServerService private readonly extensionManagementServerService: IExtensionManagementServerService
178
	) {
179
		super(`extensions.install`, InstallAction.INSTALL_LABEL, InstallAction.Class, false);
180
		this.update();
M
Matt Bierner 已提交
181
		this._register(this.labelService.onDidChangeFormatters(() => this.updateLabel(), this));
182 183
	}

S
Sandeep Somavarapu 已提交
184
	update(): void {
S
Sandeep Somavarapu 已提交
185
		this.enabled = false;
S
Sandeep Somavarapu 已提交
186 187 188 189 190 191 192 193 194 195 196 197 198 199
		this.class = InstallAction.Class;
		this.label = InstallAction.INSTALL_LABEL;
		if (this.extension && this.extension.type === ExtensionType.User) {
			if (this.extension.state === ExtensionState.Uninstalled && this.extensionsWorkbenchService.canInstall(this.extension)) {
				this.enabled = true;
				this.updateLabel();
				return;
			}
			if (this.extension.state === ExtensionState.Installing) {
				this.enabled = false;
				this.updateLabel();
				this.class = this.extension.state === ExtensionState.Installing ? InstallAction.InstallingClass : InstallAction.Class;
				return;
			}
200
		}
201
	}
202

203
	private updateLabel(): void {
S
Sandeep Somavarapu 已提交
204 205 206
		if (!this.extension) {
			return;
		}
207
		if (this.extension.state === ExtensionState.Installing) {
208 209
			this.label = InstallAction.INSTALLING_LABEL;
			this.tooltip = InstallAction.INSTALLING_LABEL;
210
		} else {
211
			if (this._manifest && this.extensionManagementServerService.localExtensionManagementServer && this.extensionManagementServerService.remoteExtensionManagementServer) {
212
				if (prefersExecuteOnUI(this._manifest, this.productService, this.configurationService)) {
S
Sandeep Somavarapu 已提交
213 214
					this.label = `${InstallAction.INSTALL_LABEL} ${localize('locally', "Locally")}`;
					this.tooltip = `${InstallAction.INSTALL_LABEL} ${localize('locally', "Locally")}`;
215
				} else {
216
					const host = this.extensionManagementServerService.remoteExtensionManagementServer.label;
S
Sandeep Somavarapu 已提交
217 218
					this.label = `${InstallAction.INSTALL_LABEL} on ${host}`;
					this.tooltip = `${InstallAction.INSTALL_LABEL} on ${host}`;
219 220 221 222 223
				}
			} else {
				this.label = InstallAction.INSTALL_LABEL;
				this.tooltip = InstallAction.INSTALL_LABEL;
			}
224 225 226
		}
	}

S
Sandeep Somavarapu 已提交
227
	async run(): Promise<any> {
S
Sandeep Somavarapu 已提交
228 229 230
		if (!this.extension) {
			return;
		}
231
		this.extensionsWorkbenchService.open(this.extension);
J
Joao Moreno 已提交
232

233 234
		alert(localize('installExtensionStart', "Installing extension {0} started. An editor is now open with more details on this extension", this.extension.displayName));

S
Sandeep Somavarapu 已提交
235 236
		const extension = await this.install(this.extension);

237
		alert(localize('installExtensionComplete', "Installing extension {0} is completed.", this.extension.displayName));
238

239
		if (extension && extension.local) {
S
Sandeep Somavarapu 已提交
240 241
			const runningExtension = await this.getRunningExtension(extension.local);
			if (runningExtension) {
242 243 244 245 246 247 248 249 250
				let action = await SetColorThemeAction.create(this.workbenchThemeService, this.instantiationService, extension)
					|| await SetFileIconThemeAction.create(this.workbenchThemeService, this.instantiationService, extension)
					|| await SetProductIconThemeAction.create(this.workbenchThemeService, this.instantiationService, extension);
				if (action) {
					try {
						return action.run({ showCurrentTheme: true, ignoreFocusLost: true });
					} finally {
						action.dispose();
					}
S
Sandeep Somavarapu 已提交
251 252
				}
			}
S
Sandeep Somavarapu 已提交
253 254
		}

J
Joao Moreno 已提交
255 256
	}

257
	private install(extension: IExtension): Promise<IExtension | void> {
S
Sandeep Somavarapu 已提交
258 259 260 261 262 263 264 265
		return this.extensionsWorkbenchService.install(extension)
			.then(null, err => {
				if (!extension.gallery) {
					return this.notificationService.error(err);
				}

				console.error(err);

266
				return promptDownloadManually(extension.gallery, localize('failedToInstall', "Failed to install \'{0}\'.", extension.identifier.id), err, this.instantiationService);
S
Sandeep Somavarapu 已提交
267 268
			});
	}
J
Joao Moreno 已提交
269

S
Sandeep Somavarapu 已提交
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
	private async getRunningExtension(extension: ILocalExtension): Promise<IExtensionDescription | null> {
		const runningExtension = await this.runtimeExtensionService.getExtension(extension.identifier.id);
		if (runningExtension) {
			return runningExtension;
		}
		if (this.runtimeExtensionService.canAddExtension(toExtensionDescription(extension))) {
			return new Promise<IExtensionDescription | null>((c, e) => {
				const disposable = this.runtimeExtensionService.onDidChangeExtensions(async () => {
					const runningExtension = await this.runtimeExtensionService.getExtension(extension.identifier.id);
					if (runningExtension) {
						disposable.dispose();
						c(runningExtension);
					}
				});
			});
		}
		return null;
287 288 289
	}
}

S
Sandeep Somavarapu 已提交
290
export abstract class InstallInOtherServerAction extends ExtensionAction {
291

292 293
	protected static readonly INSTALL_LABEL = localize('install', "Install");
	protected static readonly INSTALLING_LABEL = localize('installing', "Installing");
294

S
Sandeep Somavarapu 已提交
295 296
	private static readonly Class = `${ExtensionAction.LABEL_ACTION_CLASS} prominent install`;
	private static readonly InstallingClass = `${ExtensionAction.LABEL_ACTION_CLASS} install installing`;
297

298
	updateWhenCounterExtensionChanges: boolean = true;
299 300

	constructor(
S
Sandeep Somavarapu 已提交
301 302
		id: string,
		private readonly server: IExtensionManagementServer | null,
S
Sandeep Somavarapu 已提交
303
		private readonly canInstallAnyWhere: boolean,
304
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
Sandeep Somavarapu 已提交
305 306 307
		@IExtensionManagementServerService protected readonly extensionManagementServerService: IExtensionManagementServerService,
		@IProductService private readonly productService: IProductService,
		@IConfigurationService private readonly configurationService: IConfigurationService,
308
	) {
S
Sandeep Somavarapu 已提交
309
		super(id, InstallInOtherServerAction.INSTALL_LABEL, InstallInOtherServerAction.Class, false);
310 311 312
		this.update();
	}

313
	update(): void {
314
		this.enabled = false;
S
Sandeep Somavarapu 已提交
315 316
		this.class = InstallInOtherServerAction.Class;

S
Sandeep Somavarapu 已提交
317
		if (this.canInstall()) {
S
Sandeep Somavarapu 已提交
318
			const extensionInOtherServer = this.extensionsWorkbenchService.installed.filter(e => areSameExtensions(e.identifier, this.extension!.identifier) && e.server === this.server)[0];
S
Sandeep Somavarapu 已提交
319 320 321 322 323 324 325 326 327 328 329 330
			if (extensionInOtherServer) {
				// Getting installed in other server
				if (extensionInOtherServer.state === ExtensionState.Installing && !extensionInOtherServer.local) {
					this.enabled = true;
					this.label = InstallInOtherServerAction.INSTALLING_LABEL;
					this.class = InstallInOtherServerAction.InstallingClass;
				}
			} else {
				// Not installed in other server
				this.enabled = true;
				this.label = this.getInstallLabel();
			}
331 332 333
		}
	}

S
Sandeep Somavarapu 已提交
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
	private canInstall(): boolean {
		// Disable if extension is not installed or not an user extension
		if (
			!this.extension
			|| !this.server
			|| !this.extension.local
			|| this.extension.state !== ExtensionState.Installed
			|| this.extension.type !== ExtensionType.User
			|| this.extension.enablementState === EnablementState.DisabledByEnvironemt
		) {
			return false;
		}

		if (isLanguagePackExtension(this.extension.local.manifest)) {
			return true;
		}

		// Prefers to run on UI
		if (this.server === this.extensionManagementServerService.localExtensionManagementServer && prefersExecuteOnUI(this.extension.local.manifest, this.productService, this.configurationService)) {
			return true;
		}

		// Prefers to run on Workspace
		if (this.server === this.extensionManagementServerService.remoteExtensionManagementServer && prefersExecuteOnWorkspace(this.extension.local.manifest, this.productService, this.configurationService)) {
			return true;
		}

		if (this.canInstallAnyWhere) {
			// Can run on UI
			if (this.server === this.extensionManagementServerService.localExtensionManagementServer && canExecuteOnUI(this.extension.local.manifest, this.productService, this.configurationService)) {
				return true;
			}

			// Can run on Workspace
			if (this.server === this.extensionManagementServerService.remoteExtensionManagementServer && canExecuteOnWorkspace(this.extension.local.manifest, this.productService, this.configurationService)) {
				return true;
			}
		}

		return false;
	}

376
	async run(): Promise<void> {
S
Sandeep Somavarapu 已提交
377 378 379
		if (!this.extension) {
			return;
		}
S
Sandeep Somavarapu 已提交
380
		if (this.server) {
381 382
			this.extensionsWorkbenchService.open(this.extension);
			alert(localize('installExtensionStart', "Installing extension {0} started. An editor is now open with more details on this extension", this.extension.displayName));
S
Sandeep Somavarapu 已提交
383 384 385 386 387
			if (this.extension.gallery) {
				await this.server.extensionManagementService.installFromGallery(this.extension.gallery);
			} else {
				const vsix = await this.extension.server!.extensionManagementService.zip(this.extension.local!);
				await this.server.extensionManagementService.install(vsix);
388 389 390
			}
		}
	}
S
Sandeep Somavarapu 已提交
391 392

	protected abstract getInstallLabel(): string;
393 394
}

S
Sandeep Somavarapu 已提交
395
export class RemoteInstallAction extends InstallInOtherServerAction {
396

S
Sandeep Somavarapu 已提交
397
	constructor(
S
Sandeep Somavarapu 已提交
398
		canInstallAnyWhere: boolean,
S
Sandeep Somavarapu 已提交
399
		@IExtensionsWorkbenchService extensionsWorkbenchService: IExtensionsWorkbenchService,
S
Sandeep Somavarapu 已提交
400 401 402
		@IExtensionManagementServerService extensionManagementServerService: IExtensionManagementServerService,
		@IProductService productService: IProductService,
		@IConfigurationService configurationService: IConfigurationService,
S
Sandeep Somavarapu 已提交
403
	) {
S
Sandeep Somavarapu 已提交
404
		super(`extensions.remoteinstall`, extensionManagementServerService.remoteExtensionManagementServer, canInstallAnyWhere, extensionsWorkbenchService, extensionManagementServerService, productService, configurationService);
S
Sandeep Somavarapu 已提交
405
	}
406

S
Sandeep Somavarapu 已提交
407
	protected getInstallLabel(): string {
408
		return this.extensionManagementServerService.remoteExtensionManagementServer ? localize('Install on Server', "Install in {0}", this.extensionManagementServerService.remoteExtensionManagementServer.label) : InstallInOtherServerAction.INSTALL_LABEL;
S
Sandeep Somavarapu 已提交
409 410
	}

S
Sandeep Somavarapu 已提交
411
}
412

S
Sandeep Somavarapu 已提交
413
export class LocalInstallAction extends InstallInOtherServerAction {
414 415

	constructor(
S
Sandeep Somavarapu 已提交
416
		@IExtensionsWorkbenchService extensionsWorkbenchService: IExtensionsWorkbenchService,
S
Sandeep Somavarapu 已提交
417 418 419
		@IExtensionManagementServerService extensionManagementServerService: IExtensionManagementServerService,
		@IProductService productService: IProductService,
		@IConfigurationService configurationService: IConfigurationService,
420
	) {
S
Sandeep Somavarapu 已提交
421
		super(`extensions.localinstall`, extensionManagementServerService.localExtensionManagementServer, false, extensionsWorkbenchService, extensionManagementServerService, productService, configurationService);
422 423
	}

S
Sandeep Somavarapu 已提交
424 425
	protected getInstallLabel(): string {
		return localize('install locally', "Install Locally");
426 427 428 429
	}

}

S
Sandeep Somavarapu 已提交
430
export class UninstallAction extends ExtensionAction {
431

432 433
	private static readonly UninstallLabel = localize('uninstallAction', "Uninstall");
	private static readonly UninstallingLabel = localize('Uninstalling', "Uninstalling");
434

S
Sandeep Somavarapu 已提交
435 436
	private static readonly UninstallClass = `${ExtensionAction.LABEL_ACTION_CLASS} uninstall`;
	private static readonly UnInstallingClass = `${ExtensionAction.LABEL_ACTION_CLASS} uninstall uninstalling`;
S
Sandeep Somavarapu 已提交
437

438
	constructor(
S
Sandeep Somavarapu 已提交
439
		@IExtensionsWorkbenchService private extensionsWorkbenchService: IExtensionsWorkbenchService
440
	) {
S
Sandeep Somavarapu 已提交
441
		super('extensions.uninstall', UninstallAction.UninstallLabel, UninstallAction.UninstallClass, false);
442 443 444
		this.update();
	}

S
Sandeep Somavarapu 已提交
445
	update(): void {
446 447 448 449 450 451 452 453 454
		if (!this.extension) {
			this.enabled = false;
			return;
		}

		const state = this.extension.state;

		if (state === ExtensionState.Uninstalling) {
			this.label = UninstallAction.UninstallingLabel;
S
Sandeep Somavarapu 已提交
455
			this.class = UninstallAction.UnInstallingClass;
456 457 458 459 460
			this.enabled = false;
			return;
		}

		this.label = UninstallAction.UninstallLabel;
S
Sandeep Somavarapu 已提交
461
		this.class = UninstallAction.UninstallClass;
S
Sandeep Somavarapu 已提交
462
		this.tooltip = UninstallAction.UninstallLabel;
463

S
Sandeep Somavarapu 已提交
464 465 466 467 468
		if (state !== ExtensionState.Installed) {
			this.enabled = false;
			return;
		}

S
cleanup  
Sandeep Somavarapu 已提交
469
		if (this.extension.type !== ExtensionType.User) {
470 471 472 473 474 475 476
			this.enabled = false;
			return;
		}

		this.enabled = true;
	}

S
Sandeep Somavarapu 已提交
477 478 479 480
	async run(): Promise<any> {
		if (!this.extension) {
			return;
		}
481 482 483
		alert(localize('uninstallExtensionStart', "Uninstalling extension {0} started.", this.extension.displayName));

		return this.extensionsWorkbenchService.uninstall(this.extension).then(() => {
S
Sandeep Somavarapu 已提交
484
			alert(localize('uninstallExtensionComplete', "Please reload Visual Studio Code to complete the uninstallation of the extension {0}.", this.extension!.displayName));
485
		});
486 487 488
	}
}

S
Sandeep Somavarapu 已提交
489
export class CombinedInstallAction extends ExtensionAction {
490

S
Sandeep Somavarapu 已提交
491
	private static readonly NoExtensionClass = `${ExtensionAction.LABEL_ACTION_CLASS} prominent install no-extension`;
492 493
	private installAction: InstallAction;
	private uninstallAction: UninstallAction;
494 495

	constructor(
496
		@IInstantiationService instantiationService: IInstantiationService
497 498 499
	) {
		super('extensions.combinedInstall', '', '', false);

M
Matt Bierner 已提交
500 501
		this.installAction = this._register(instantiationService.createInstance(InstallAction));
		this.uninstallAction = this._register(instantiationService.createInstance(UninstallAction));
502 503 504 505

		this.update();
	}

506 507
	set manifest(manifiest: IExtensionManifest) { this.installAction.manifest = manifiest; this.update(); }

S
Sandeep Somavarapu 已提交
508 509 510 511 512 513
	update(): void {
		this.installAction.extension = this.extension;
		this.uninstallAction.extension = this.extension;
		this.installAction.update();
		this.uninstallAction.update();

514
		if (!this.extension || this.extension.type === ExtensionType.System) {
515 516
			this.enabled = false;
			this.class = CombinedInstallAction.NoExtensionClass;
S
Sandeep Somavarapu 已提交
517 518
		} else if (this.extension.state === ExtensionState.Installing) {
			this.enabled = false;
519 520
			this.label = this.installAction.label;
			this.class = this.installAction.class;
S
Sandeep Somavarapu 已提交
521
			this.tooltip = this.installAction.tooltip;
S
Sandeep Somavarapu 已提交
522 523
		} else if (this.extension.state === ExtensionState.Uninstalling) {
			this.enabled = false;
524 525
			this.label = this.uninstallAction.label;
			this.class = this.uninstallAction.class;
S
Sandeep Somavarapu 已提交
526
			this.tooltip = this.uninstallAction.tooltip;
S
Sandeep Somavarapu 已提交
527 528
		} else if (this.installAction.enabled) {
			this.enabled = true;
529 530
			this.label = this.installAction.label;
			this.class = this.installAction.class;
S
Sandeep Somavarapu 已提交
531
			this.tooltip = this.installAction.tooltip;
S
Sandeep Somavarapu 已提交
532 533
		} else if (this.uninstallAction.enabled) {
			this.enabled = true;
534 535
			this.label = this.uninstallAction.label;
			this.class = this.uninstallAction.class;
S
Sandeep Somavarapu 已提交
536
			this.tooltip = this.uninstallAction.tooltip;
537 538 539 540
		} else {
			this.enabled = false;
			this.label = this.installAction.label;
			this.class = this.installAction.class;
S
Sandeep Somavarapu 已提交
541
			this.tooltip = this.installAction.tooltip;
542 543 544
		}
	}

S
Sandeep Somavarapu 已提交
545
	run(): Promise<any> {
546 547 548 549 550 551
		if (this.installAction.enabled) {
			return this.installAction.run();
		} else if (this.uninstallAction.enabled) {
			return this.uninstallAction.run();
		}

552
		return Promise.resolve();
553 554 555
	}
}

S
Sandeep Somavarapu 已提交
556
export class UpdateAction extends ExtensionAction {
557

S
Sandeep Somavarapu 已提交
558
	private static readonly EnabledClass = `${ExtensionAction.LABEL_ACTION_CLASS} prominent update`;
559
	private static readonly DisabledClass = `${UpdateAction.EnabledClass} disabled`;
560 561

	constructor(
562 563 564
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
		@IInstantiationService private readonly instantiationService: IInstantiationService,
		@INotificationService private readonly notificationService: INotificationService,
565
	) {
566
		super(`extensions.update`, '', UpdateAction.DisabledClass, false);
567 568 569
		this.update();
	}

S
Sandeep Somavarapu 已提交
570
	update(): void {
571 572 573
		if (!this.extension) {
			this.enabled = false;
			this.class = UpdateAction.DisabledClass;
574
			this.label = this.getUpdateLabel();
575 576 577
			return;
		}

578
		if (this.extension.type !== ExtensionType.User) {
579 580
			this.enabled = false;
			this.class = UpdateAction.DisabledClass;
581
			this.label = this.getUpdateLabel();
582 583 584 585 586 587 588 589
			return;
		}

		const canInstall = this.extensionsWorkbenchService.canInstall(this.extension);
		const isInstalled = this.extension.state === ExtensionState.Installed;

		this.enabled = canInstall && isInstalled && this.extension.outdated;
		this.class = this.enabled ? UpdateAction.EnabledClass : UpdateAction.DisabledClass;
590
		this.label = this.extension.outdated ? this.getUpdateLabel(this.extension.latestVersion) : this.getUpdateLabel();
591 592
	}

S
Sandeep Somavarapu 已提交
593 594 595 596
	async run(): Promise<any> {
		if (!this.extension) {
			return;
		}
597
		alert(localize('updateExtensionStart', "Updating extension {0} to version {1} started.", this.extension.displayName, this.extension.latestVersion));
J
Joao Moreno 已提交
598 599 600
		return this.install(this.extension);
	}

S
Sandeep Somavarapu 已提交
601
	private install(extension: IExtension): Promise<void> {
602
		return this.extensionsWorkbenchService.install(extension).then(() => {
S
Sandeep Somavarapu 已提交
603
			alert(localize('updateExtensionComplete', "Updating extension {0} to version {1} completed.", extension.displayName, extension.latestVersion));
604
		}, err => {
605
			if (!extension.gallery) {
J
Joao Moreno 已提交
606 607 608 609
				return this.notificationService.error(err);
			}

			console.error(err);
610

611
			return promptDownloadManually(extension.gallery, localize('failedToUpdate', "Failed to update \'{0}\'.", extension.identifier.id), err, this.instantiationService);
J
Joao Moreno 已提交
612
		});
613 614
	}

615
	private getUpdateLabel(version?: string): string {
616
		return version ? localize('updateTo', "Update to {0}", version) : localize('updateAction', "Update");
617
	}
618 619
}

620
interface IExtensionActionViewItemOptions extends IActionViewItemOptions {
621 622 623
	tabOnlyOnFocus?: boolean;
}

624
export class ExtensionActionViewItem extends ActionViewItem {
625

626
	constructor(context: any, action: IAction, options: IExtensionActionViewItemOptions = {}) {
627 628 629 630 631 632
		super(context, action, options);
	}

	updateEnabled(): void {
		super.updateEnabled();

S
Sandeep Somavarapu 已提交
633
		if (this.label && (<IExtensionActionViewItemOptions>this.options).tabOnlyOnFocus && this.getAction().enabled && !this._hasFocus) {
634 635 636 637
			DOM.removeTabIndexAndUpdateFocus(this.label);
		}
	}

S
Sandeep Somavarapu 已提交
638
	private _hasFocus: boolean = false;
639
	setFocus(value: boolean): void {
S
Sandeep Somavarapu 已提交
640
		if (!(<IExtensionActionViewItemOptions>this.options).tabOnlyOnFocus || this._hasFocus === value) {
641 642 643
			return;
		}
		this._hasFocus = value;
644
		if (this.label && this.getAction().enabled) {
645 646 647 648 649 650 651 652 653
			if (this._hasFocus) {
				this.label.tabIndex = 0;
			} else {
				DOM.removeTabIndexAndUpdateFocus(this.label);
			}
		}
	}
}

S
Sandeep Somavarapu 已提交
654
export abstract class ExtensionDropDownAction extends ExtensionAction {
S
Explore  
Sandeep Somavarapu 已提交
655 656 657 658 659 660 661

	constructor(
		id: string,
		label: string,
		cssClass: string,
		enabled: boolean,
		private readonly tabOnlyOnFocus: boolean,
S
Sandeep Somavarapu 已提交
662
		@IInstantiationService protected instantiationService: IInstantiationService
S
Explore  
Sandeep Somavarapu 已提交
663 664 665 666
	) {
		super(id, label, cssClass, enabled);
	}

S
Sandeep Somavarapu 已提交
667
	private _actionViewItem: DropDownMenuActionViewItem | null = null;
668 669 670
	createActionViewItem(): DropDownMenuActionViewItem {
		this._actionViewItem = this.instantiationService.createInstance(DropDownMenuActionViewItem, this, this.tabOnlyOnFocus);
		return this._actionViewItem;
S
Explore  
Sandeep Somavarapu 已提交
671 672
	}

J
Johannes Rieken 已提交
673
	public run({ actionGroups, disposeActionsOnHide }: { actionGroups: IAction[][], disposeActionsOnHide: boolean }): Promise<any> {
674 675
		if (this._actionViewItem) {
			this._actionViewItem.showMenu(actionGroups, disposeActionsOnHide);
S
Explore  
Sandeep Somavarapu 已提交
676
		}
677
		return Promise.resolve();
S
Explore  
Sandeep Somavarapu 已提交
678 679 680
	}
}

681
export class DropDownMenuActionViewItem extends ExtensionActionViewItem {
682

S
Sandeep Somavarapu 已提交
683
	constructor(action: ExtensionDropDownAction,
684
		tabOnlyOnFocus: boolean,
685
		@IContextMenuService private readonly contextMenuService: IContextMenuService
S
Sandeep Somavarapu 已提交
686
	) {
687
		super(null, action, { icon: true, label: true, tabOnlyOnFocus });
688 689
	}

S
Sandeep Somavarapu 已提交
690
	public showMenu(menuActionGroups: IAction[][], disposeActionsOnHide: boolean): void {
691 692 693 694 695 696 697 698 699 700 701
		if (this.element) {
			const actions = this.getActions(menuActionGroups);
			let elementPosition = DOM.getDomNodePagePosition(this.element);
			const anchor = { x: elementPosition.left, y: elementPosition.top + elementPosition.height + 10 };
			this.contextMenuService.showContextMenu({
				getAnchor: () => anchor,
				getActions: () => actions,
				actionRunner: this.actionRunner,
				onHide: () => { if (disposeActionsOnHide) { dispose(actions); } }
			});
		}
702 703
	}

S
Sandeep Somavarapu 已提交
704
	private getActions(menuActionGroups: IAction[][]): IAction[] {
B
Benjamin Pasero 已提交
705
		let actions: IAction[] = [];
S
Sandeep Somavarapu 已提交
706
		for (const menuActions of menuActionGroups) {
S
Sandeep Somavarapu 已提交
707
			actions = [...actions, ...menuActions, new Separator()];
708 709 710 711 712
		}
		return actions.length ? actions.slice(0, actions.length - 1) : actions;
	}
}

713
export function getContextMenuActions(menuService: IMenuService, contextKeyService: IContextKeyService, instantiationService: IInstantiationService, extension: IExtension | undefined | null): IAction[][] {
714 715
	const scopedContextKeyService = contextKeyService.createScoped();
	if (extension) {
716
		scopedContextKeyService.createKey<string>('extension', extension.identifier.id);
717 718 719 720 721 722 723
		scopedContextKeyService.createKey<boolean>('isBuiltinExtension', extension.type === ExtensionType.System);
		scopedContextKeyService.createKey<boolean>('extensionHasConfiguration', extension.local && !!extension.local.manifest.contributes && !!extension.local.manifest.contributes.configuration);
		if (extension.state === ExtensionState.Installed) {
			scopedContextKeyService.createKey<string>('extensionStatus', 'installed');
		}
	}

724
	const groups: IAction[][] = [];
725
	const menu = menuService.createMenu(MenuId.ExtensionContext, scopedContextKeyService);
726 727 728 729 730 731
	menu.getActions({ shouldForwardArgs: true }).forEach(([, actions]) => groups.push(actions.map(action => {
		if (action instanceof SubmenuAction) {
			return action;
		}
		return instantiationService.createInstance(MenuItemExtensionAction, action);
	})));
S
Sandeep Somavarapu 已提交
732
	menu.dispose();
733

S
Sandeep Somavarapu 已提交
734 735 736
	return groups;
}

S
Sandeep Somavarapu 已提交
737
export class ManageExtensionAction extends ExtensionDropDownAction {
738

739
	static readonly ID = 'extensions.manage';
S
Sandeep Somavarapu 已提交
740 741

	private static readonly Class = `${ExtensionAction.ICON_ACTION_CLASS} manage codicon-gear`;
742
	private static readonly HideManageExtensionClass = `${ManageExtensionAction.Class} hide`;
743 744

	constructor(
S
Sandeep Somavarapu 已提交
745
		@IInstantiationService instantiationService: IInstantiationService,
746
		@IExtensionService private readonly extensionService: IExtensionService,
747 748 749
		@IWorkbenchThemeService private readonly workbenchThemeService: IWorkbenchThemeService,
		@IMenuService private readonly menuService: IMenuService,
		@IContextKeyService private readonly contextKeyService: IContextKeyService,
750
	) {
S
Sandeep Somavarapu 已提交
751 752

		super(ManageExtensionAction.ID, '', '', true, true, instantiationService);
753

S
Sandeep Somavarapu 已提交
754
		this.tooltip = localize('manage', "Manage");
755 756 757 758

		this.update();
	}

759
	async getActionGroups(runningExtensions: IExtensionDescription[]): Promise<IAction[][]> {
760
		const groups: IAction[][] = [];
761
		if (this.extension) {
762 763 764 765 766 767 768 769 770 771
			const actions = await Promise.all([
				SetColorThemeAction.create(this.workbenchThemeService, this.instantiationService, this.extension),
				SetFileIconThemeAction.create(this.workbenchThemeService, this.instantiationService, this.extension),
				SetProductIconThemeAction.create(this.workbenchThemeService, this.instantiationService, this.extension)
			]);

			const themesGroup: ExtensionAction[] = [];
			for (let action of actions) {
				if (action) {
					themesGroup.push(action);
772
				}
773 774
			}
			if (themesGroup.length) {
775 776 777
				groups.push(themesGroup);
			}
		}
S
Sandeep Somavarapu 已提交
778
		groups.push([
S
Sandeep Somavarapu 已提交
779
			this.instantiationService.createInstance(EnableGloballyAction),
780
			this.instantiationService.createInstance(EnableForWorkspaceAction)
S
Sandeep Somavarapu 已提交
781 782
		]);
		groups.push([
S
Sandeep Somavarapu 已提交
783 784
			this.instantiationService.createInstance(DisableGloballyAction, runningExtensions),
			this.instantiationService.createInstance(DisableForWorkspaceAction, runningExtensions)
S
Sandeep Somavarapu 已提交
785
		]);
786
		groups.push([this.instantiationService.createInstance(UninstallAction)]);
S
Sandeep Somavarapu 已提交
787
		groups.push([this.instantiationService.createInstance(InstallAnotherVersionAction)]);
P
Peng Lyu 已提交
788

S
Sandeep Somavarapu 已提交
789
		getContextMenuActions(this.menuService, this.contextKeyService, this.instantiationService, this.extension).forEach(actions => groups.push(actions));
P
Peng Lyu 已提交
790

791 792 793 794 795
		groups.forEach(group => group.forEach(extensionAction => {
			if (extensionAction instanceof ExtensionAction) {
				extensionAction.extension = this.extension;
			}
		}));
S
Sandeep Somavarapu 已提交
796 797 798 799

		return groups;
	}

800 801
	async run(): Promise<any> {
		const runtimeExtensions = await this.extensionService.getExtensions();
802
		return super.run({ actionGroups: await this.getActionGroups(runtimeExtensions), disposeActionsOnHide: true });
S
Sandeep Somavarapu 已提交
803 804
	}

S
Sandeep Somavarapu 已提交
805
	update(): void {
S
Sandeep Somavarapu 已提交
806
		this.class = ManageExtensionAction.HideManageExtensionClass;
807
		this.enabled = false;
S
Sandeep Somavarapu 已提交
808
		if (this.extension) {
809 810
			const state = this.extension.state;
			this.enabled = state === ExtensionState.Installed;
S
Sandeep Somavarapu 已提交
811
			this.class = this.enabled || state === ExtensionState.Uninstalling ? ManageExtensionAction.Class : ManageExtensionAction.HideManageExtensionClass;
812 813 814 815 816
			this.tooltip = state === ExtensionState.Uninstalling ? localize('ManageExtensionAction.uninstallingTooltip', "Uninstalling") : '';
		}
	}
}

817 818
export class MenuItemExtensionAction extends ExtensionAction {

S
Sandeep Somavarapu 已提交
819 820
	constructor(
		private readonly action: IAction,
821
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
Sandeep Somavarapu 已提交
822
	) {
823 824 825
		super(action.id, action.label);
	}

S
Sandeep Somavarapu 已提交
826 827 828 829 830
	update() {
		if (!this.extension) {
			return;
		}
		if (this.action.id === TOGGLE_IGNORE_EXTENSION_ACTION_ID) {
831
			this.checked = !this.extensionsWorkbenchService.isExtensionIgnoredToSync(this.extension);
S
Sandeep Somavarapu 已提交
832 833
		}
	}
834 835 836

	async run(): Promise<void> {
		if (this.extension) {
S
Sandeep Somavarapu 已提交
837
			return this.action.run(this.extension.identifier.id);
838 839 840 841
		}
	}
}

S
Sandeep Somavarapu 已提交
842
export class InstallAnotherVersionAction extends ExtensionAction {
843

844
	static readonly ID = 'workbench.extensions.action.install.anotherVersion';
845
	static readonly LABEL = localize('install another version', "Install Another Version...");
846

S
Sandeep Somavarapu 已提交
847
	constructor(
848 849 850 851 852
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
		@IExtensionGalleryService private readonly extensionGalleryService: IExtensionGalleryService,
		@IQuickInputService private readonly quickInputService: IQuickInputService,
		@IInstantiationService private readonly instantiationService: IInstantiationService,
		@INotificationService private readonly notificationService: INotificationService,
853 854
	) {
		super(InstallAnotherVersionAction.ID, InstallAnotherVersionAction.LABEL);
S
Sandeep Somavarapu 已提交
855 856 857 858
		this.update();
	}

	update(): void {
S
Sandeep Somavarapu 已提交
859
		this.enabled = !!this.extension && !!this.extension.gallery;
860 861
	}

J
Johannes Rieken 已提交
862
	run(): Promise<any> {
863 864 865
		if (!this.enabled) {
			return Promise.resolve();
		}
S
Sandeep Somavarapu 已提交
866
		return this.quickInputService.pick(this.getVersionEntries(), { placeHolder: localize('selectVersion', "Select Version to Install"), matchOnDetail: true })
867 868
			.then(pick => {
				if (pick) {
S
Sandeep Somavarapu 已提交
869
					if (this.extension!.version === pick.id) {
S
Sandeep Somavarapu 已提交
870 871
						return Promise.resolve();
					}
S
Sandeep Somavarapu 已提交
872
					const promise: Promise<any> = pick.latest ? this.extensionsWorkbenchService.install(this.extension!) : this.extensionsWorkbenchService.installVersion(this.extension!, pick.id);
S
Sandeep Somavarapu 已提交
873 874
					return promise
						.then(null, err => {
S
Sandeep Somavarapu 已提交
875
							if (!this.extension!.gallery) {
876 877 878 879
								return this.notificationService.error(err);
							}

							console.error(err);
880

881
							return promptDownloadManually(this.extension!.gallery, localize('failedToInstall', "Failed to install \'{0}\'.", this.extension!.identifier.id), err, this.instantiationService);
882 883 884 885 886
						});
				}
				return null;
			});
	}
S
Sandeep Somavarapu 已提交
887

888
	private getVersionEntries(): Promise<(IQuickPickItem & { latest: boolean, id: string })[]> {
S
Sandeep Somavarapu 已提交
889 890
		return this.extensionGalleryService.getAllVersions(this.extension!.gallery!, true)
			.then(allVersions => allVersions.map((v, i) => ({ id: v.version, label: v.version, description: `${getRelativeDateLabel(new Date(Date.parse(v.date)))}${v.version === this.extension!.version ? ` (${localize('current', "Current")})` : ''}`, latest: i === 0 })));
S
Sandeep Somavarapu 已提交
891
	}
892 893
}

S
Sandeep Somavarapu 已提交
894
export class EnableForWorkspaceAction extends ExtensionAction {
895

896
	static readonly ID = 'extensions.enableForWorkspace';
897
	static readonly LABEL = localize('enableForWorkspaceAction', "Enable (Workspace)");
898

S
Sandeep Somavarapu 已提交
899
	constructor(
900
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
rename  
Sandeep Somavarapu 已提交
901
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService
902
	) {
S
Explore  
Sandeep Somavarapu 已提交
903
		super(EnableForWorkspaceAction.ID, EnableForWorkspaceAction.LABEL);
904 905 906
		this.update();
	}

S
Sandeep Somavarapu 已提交
907
	update(): void {
908
		this.enabled = false;
909 910
		if (this.extension && this.extension.local) {
			this.enabled = this.extension.state === ExtensionState.Installed
911
				&& !this.extensionEnablementService.isEnabled(this.extension.local)
912
				&& this.extensionEnablementService.canChangeEnablement(this.extension.local);
913 914 915
		}
	}

S
Sandeep Somavarapu 已提交
916 917 918 919
	async run(): Promise<any> {
		if (!this.extension) {
			return;
		}
920
		return this.extensionsWorkbenchService.setEnablement(this.extension, EnablementState.EnabledWorkspace);
921 922 923
	}
}

S
Sandeep Somavarapu 已提交
924
export class EnableGloballyAction extends ExtensionAction {
925

926
	static readonly ID = 'extensions.enableGlobally';
927
	static readonly LABEL = localize('enableGloballyAction', "Enable");
928

S
Sandeep Somavarapu 已提交
929
	constructor(
930
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
rename  
Sandeep Somavarapu 已提交
931
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService
932
	) {
S
Sandeep Somavarapu 已提交
933
		super(EnableGloballyAction.ID, EnableGloballyAction.LABEL);
934 935 936
		this.update();
	}

S
Sandeep Somavarapu 已提交
937
	update(): void {
938
		this.enabled = false;
939
		if (this.extension && this.extension.local) {
940
			this.enabled = this.extension.state === ExtensionState.Installed
S
Sandeep Somavarapu 已提交
941
				&& this.extensionEnablementService.isDisabledGlobally(this.extension.local)
942
				&& this.extensionEnablementService.canChangeEnablement(this.extension.local);
943 944 945
		}
	}

S
Sandeep Somavarapu 已提交
946 947 948 949
	async run(): Promise<any> {
		if (!this.extension) {
			return;
		}
950
		return this.extensionsWorkbenchService.setEnablement(this.extension, EnablementState.EnabledGlobally);
951 952 953
	}
}

S
Sandeep Somavarapu 已提交
954
export class DisableForWorkspaceAction extends ExtensionAction {
955

956
	static readonly ID = 'extensions.disableForWorkspace';
957
	static readonly LABEL = localize('disableForWorkspaceAction', "Disable (Workspace)");
958

S
Sandeep Somavarapu 已提交
959
	constructor(readonly runningExtensions: IExtensionDescription[],
960 961
		@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService,
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
rename  
Sandeep Somavarapu 已提交
962
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService
963
	) {
S
Sandeep Somavarapu 已提交
964
		super(DisableForWorkspaceAction.ID, DisableForWorkspaceAction.LABEL);
965 966 967
		this.update();
	}

S
Sandeep Somavarapu 已提交
968
	update(): void {
969
		this.enabled = false;
S
Sandeep Somavarapu 已提交
970
		if (this.extension && this.extension.local && this.runningExtensions.some(e => areSameExtensions({ id: e.identifier.value, uuid: e.uuid }, this.extension!.identifier) && this.workspaceContextService.getWorkbenchState() !== WorkbenchState.EMPTY)) {
971
			this.enabled = this.extension.state === ExtensionState.Installed
972
				&& (this.extension.enablementState === EnablementState.EnabledGlobally || this.extension.enablementState === EnablementState.EnabledWorkspace)
973
				&& this.extensionEnablementService.canChangeEnablement(this.extension.local);
974 975 976
		}
	}

S
Sandeep Somavarapu 已提交
977 978 979 980
	async run(): Promise<any> {
		if (!this.extension) {
			return;
		}
981
		return this.extensionsWorkbenchService.setEnablement(this.extension, EnablementState.DisabledWorkspace);
982 983 984
	}
}

S
Sandeep Somavarapu 已提交
985
export class DisableGloballyAction extends ExtensionAction {
986

987
	static readonly ID = 'extensions.disableGlobally';
988
	static readonly LABEL = localize('disableGloballyAction', "Disable");
989

S
Sandeep Somavarapu 已提交
990
	constructor(readonly runningExtensions: IExtensionDescription[],
991
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
rename  
Sandeep Somavarapu 已提交
992
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService
993
	) {
S
Sandeep Somavarapu 已提交
994
		super(DisableGloballyAction.ID, DisableGloballyAction.LABEL);
995 996 997
		this.update();
	}

S
Sandeep Somavarapu 已提交
998
	update(): void {
999
		this.enabled = false;
S
Sandeep Somavarapu 已提交
1000
		if (this.extension && this.extension.local && this.runningExtensions.some(e => areSameExtensions({ id: e.identifier.value, uuid: e.uuid }, this.extension!.identifier))) {
1001
			this.enabled = this.extension.state === ExtensionState.Installed
1002
				&& (this.extension.enablementState === EnablementState.EnabledGlobally || this.extension.enablementState === EnablementState.EnabledWorkspace)
1003
				&& this.extensionEnablementService.canChangeEnablement(this.extension.local);
1004 1005 1006
		}
	}

S
Sandeep Somavarapu 已提交
1007 1008 1009 1010
	async run(): Promise<any> {
		if (!this.extension) {
			return;
		}
1011
		return this.extensionsWorkbenchService.setEnablement(this.extension, EnablementState.DisabledGlobally);
1012 1013 1014
	}
}

S
Sandeep Somavarapu 已提交
1015
export abstract class ExtensionEditorDropDownAction extends ExtensionDropDownAction {
1016

S
Sandeep Somavarapu 已提交
1017 1018
	private static readonly EnabledClass = `${ExtensionAction.LABEL_ACTION_CLASS} extension-editor-dropdown-action`;
	private static readonly EnabledDropDownClass = `${ExtensionEditorDropDownAction.EnabledClass} dropdown enable`;
S
Sandeep Somavarapu 已提交
1019
	private static readonly DisabledClass = `${ExtensionEditorDropDownAction.EnabledClass} disabled`;
1020 1021

	constructor(
S
Sandeep Somavarapu 已提交
1022 1023 1024
		id: string, private readonly initialLabel: string,
		readonly actions: ExtensionAction[],
		@IInstantiationService instantiationService: IInstantiationService
1025
	) {
S
Sandeep Somavarapu 已提交
1026
		super(id, initialLabel, ExtensionEditorDropDownAction.DisabledClass, false, false, instantiationService);
1027 1028 1029
		this.update();
	}

S
Sandeep Somavarapu 已提交
1030 1031 1032
	update(): void {
		this.actions.forEach(a => a.extension = this.extension);
		this.actions.forEach(a => a.update());
S
Sandeep Somavarapu 已提交
1033
		const enabledActions = this.actions.filter(a => a.enabled);
1034 1035 1036 1037
		this.enabled = enabledActions.length > 0;
		if (this.enabled) {
			if (enabledActions.length === 1) {
				this.label = enabledActions[0].label;
S
Sandeep Somavarapu 已提交
1038
				this.class = ExtensionEditorDropDownAction.EnabledClass;
1039
			} else {
S
Sandeep Somavarapu 已提交
1040
				this.label = this.initialLabel;
S
Sandeep Somavarapu 已提交
1041
				this.class = ExtensionEditorDropDownAction.EnabledDropDownClass;
1042 1043
			}
		} else {
S
Sandeep Somavarapu 已提交
1044
			this.class = ExtensionEditorDropDownAction.DisabledClass;
1045 1046 1047
		}
	}

J
Johannes Rieken 已提交
1048
	public run(): Promise<any> {
S
Sandeep Somavarapu 已提交
1049
		const enabledActions = this.actions.filter(a => a.enabled);
1050 1051 1052
		if (enabledActions.length === 1) {
			enabledActions[0].run();
		} else {
S
Sandeep Somavarapu 已提交
1053
			return super.run({ actionGroups: [this.actions], disposeActionsOnHide: false });
1054
		}
1055
		return Promise.resolve();
1056
	}
S
Sandeep Somavarapu 已提交
1057
}
1058

S
Sandeep Somavarapu 已提交
1059 1060 1061
export class EnableDropDownAction extends ExtensionEditorDropDownAction {

	constructor(
S
Sandeep Somavarapu 已提交
1062
		@IInstantiationService instantiationService: IInstantiationService
S
Sandeep Somavarapu 已提交
1063
	) {
S
Sandeep Somavarapu 已提交
1064 1065
		super('extensions.enable', localize('enableAction', "Enable"), [
			instantiationService.createInstance(EnableGloballyAction),
1066
			instantiationService.createInstance(EnableForWorkspaceAction)
S
Sandeep Somavarapu 已提交
1067
		], instantiationService);
S
Sandeep Somavarapu 已提交
1068 1069 1070 1071 1072 1073
	}
}

export class DisableDropDownAction extends ExtensionEditorDropDownAction {

	constructor(
S
Sandeep Somavarapu 已提交
1074 1075
		runningExtensions: IExtensionDescription[],
		@IInstantiationService instantiationService: IInstantiationService
S
Sandeep Somavarapu 已提交
1076
	) {
S
Sandeep Somavarapu 已提交
1077 1078 1079 1080
		super('extensions.disable', localize('disableAction', "Disable"), [
			instantiationService.createInstance(DisableGloballyAction, runningExtensions),
			instantiationService.createInstance(DisableForWorkspaceAction, runningExtensions)
		], instantiationService);
1081 1082 1083
	}
}

J
Joao Moreno 已提交
1084 1085
export class CheckForUpdatesAction extends Action {

1086
	static readonly ID = 'workbench.extensions.action.checkForUpdates';
1087
	static readonly LABEL = localize('checkForUpdates', "Check for Extension Updates");
J
Joao Moreno 已提交
1088 1089

	constructor(
1090 1091
		id = CheckForUpdatesAction.ID,
		label = CheckForUpdatesAction.LABEL,
1092
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
rename  
Sandeep Somavarapu 已提交
1093
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService,
1094 1095
		@IViewletService private readonly viewletService: IViewletService,
		@INotificationService private readonly notificationService: INotificationService
J
Joao Moreno 已提交
1096 1097 1098 1099
	) {
		super(id, label, '', true);
	}

1100
	private checkUpdatesAndNotify(): void {
1101 1102
		const outdated = this.extensionsWorkbenchService.outdated;
		if (!outdated.length) {
1103
			this.notificationService.info(localize('noUpdatesAvailable', "All extensions are up to date."));
1104 1105
			return;
		}
1106

1107
		let msgAvailableExtensions = outdated.length === 1 ? localize('singleUpdateAvailable', "An extension update is available.") : localize('updatesAvailable', "{0} extension updates are available.", outdated.length);
1108

1109
		const disabledExtensionsCount = outdated.filter(ext => ext.local && !this.extensionEnablementService.isEnabled(ext.local)).length;
1110 1111 1112 1113 1114 1115 1116 1117 1118
		if (disabledExtensionsCount) {
			if (outdated.length === 1) {
				msgAvailableExtensions = localize('singleDisabledUpdateAvailable', "An update to an extension which is disabled is available.");
			} else if (disabledExtensionsCount === 1) {
				msgAvailableExtensions = localize('updatesAvailableOneDisabled', "{0} extension updates are available. One of them is for a disabled extension.", outdated.length);
			} else if (disabledExtensionsCount === outdated.length) {
				msgAvailableExtensions = localize('updatesAvailableAllDisabled', "{0} extension updates are available. All of them are for disabled extensions.", outdated.length);
			} else {
				msgAvailableExtensions = localize('updatesAvailableIncludingDisabled', "{0} extension updates are available. {1} of them are for disabled extensions.", outdated.length, disabledExtensionsCount);
1119
			}
1120 1121 1122
		}

		this.viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
1123
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
1124 1125 1126
			.then(viewlet => viewlet.search(''));

		this.notificationService.info(msgAvailableExtensions);
1127 1128
	}

S
Sandeep Somavarapu 已提交
1129
	run(): Promise<any> {
1130
		return this.extensionsWorkbenchService.checkForUpdates().then(() => this.checkUpdatesAndNotify());
J
Joao Moreno 已提交
1131 1132 1133
	}
}

S
Sandeep Somavarapu 已提交
1134 1135 1136 1137 1138 1139
export class ToggleAutoUpdateAction extends Action {

	constructor(
		id: string,
		label: string,
		private autoUpdateValue: boolean,
1140
		@IConfigurationService private readonly configurationService: IConfigurationService
S
Sandeep Somavarapu 已提交
1141 1142 1143
	) {
		super(id, label, '', true);
		this.updateEnablement();
1144
		configurationService.onDidChangeConfiguration(() => this.updateEnablement());
S
Sandeep Somavarapu 已提交
1145 1146 1147
	}

	private updateEnablement(): void {
1148
		this.enabled = this.configurationService.getValue(AutoUpdateConfigurationKey) !== this.autoUpdateValue;
S
Sandeep Somavarapu 已提交
1149 1150
	}

S
Sandeep Somavarapu 已提交
1151
	run(): Promise<any> {
1152
		return this.configurationService.updateValue(AutoUpdateConfigurationKey, this.autoUpdateValue);
S
Sandeep Somavarapu 已提交
1153 1154 1155 1156 1157
	}
}

export class EnableAutoUpdateAction extends ToggleAutoUpdateAction {

1158
	static readonly ID = 'workbench.extensions.action.enableAutoUpdate';
1159
	static readonly LABEL = localize('enableAutoUpdate', "Enable Auto Updating Extensions");
S
Sandeep Somavarapu 已提交
1160 1161 1162 1163

	constructor(
		id = EnableAutoUpdateAction.ID,
		label = EnableAutoUpdateAction.LABEL,
1164
		@IConfigurationService configurationService: IConfigurationService
S
Sandeep Somavarapu 已提交
1165
	) {
1166
		super(id, label, true, configurationService);
S
Sandeep Somavarapu 已提交
1167 1168 1169 1170 1171
	}
}

export class DisableAutoUpdateAction extends ToggleAutoUpdateAction {

1172
	static readonly ID = 'workbench.extensions.action.disableAutoUpdate';
1173
	static readonly LABEL = localize('disableAutoUpdate', "Disable Auto Updating Extensions");
S
Sandeep Somavarapu 已提交
1174 1175 1176 1177

	constructor(
		id = EnableAutoUpdateAction.ID,
		label = EnableAutoUpdateAction.LABEL,
1178
		@IConfigurationService configurationService: IConfigurationService
S
Sandeep Somavarapu 已提交
1179
	) {
1180
		super(id, label, false, configurationService);
S
Sandeep Somavarapu 已提交
1181 1182 1183
	}
}

1184 1185
export class UpdateAllAction extends Action {

1186
	static readonly ID = 'workbench.extensions.action.updateAllExtensions';
1187
	static readonly LABEL = localize('updateAll', "Update All Extensions");
1188 1189 1190 1191

	constructor(
		id = UpdateAllAction.ID,
		label = UpdateAllAction.LABEL,
1192 1193 1194
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
		@INotificationService private readonly notificationService: INotificationService,
		@IInstantiationService private readonly instantiationService: IInstantiationService,
1195 1196 1197
	) {
		super(id, label, '', false);

M
Matt Bierner 已提交
1198
		this._register(this.extensionsWorkbenchService.onChange(() => this.update()));
1199 1200 1201 1202
		this.update();
	}

	private update(): void {
1203
		this.enabled = this.extensionsWorkbenchService.outdated.length > 0;
1204 1205
	}

S
Sandeep Somavarapu 已提交
1206
	run(): Promise<any> {
1207
		return Promise.all(this.extensionsWorkbenchService.outdated.map(e => this.install(e)));
J
Joao Moreno 已提交
1208 1209
	}

J
Johannes Rieken 已提交
1210
	private install(extension: IExtension): Promise<any> {
R
Rob Lourens 已提交
1211
		return this.extensionsWorkbenchService.install(extension).then(undefined, err => {
1212
			if (!extension.gallery) {
J
Joao Moreno 已提交
1213 1214 1215 1216
				return this.notificationService.error(err);
			}

			console.error(err);
1217

1218
			return promptDownloadManually(extension.gallery, localize('failedToUpdate', "Failed to update \'{0}\'.", extension.identifier.id), err, this.instantiationService);
J
Joao Moreno 已提交
1219
		});
1220 1221 1222
	}
}

S
Sandeep Somavarapu 已提交
1223
export class ReloadAction extends ExtensionAction {
1224

S
Sandeep Somavarapu 已提交
1225
	private static readonly EnabledClass = `${ExtensionAction.LABEL_ACTION_CLASS} reload`;
1226
	private static readonly DisabledClass = `${ReloadAction.EnabledClass} disabled`;
1227

1228
	updateWhenCounterExtensionChanges: boolean = true;
1229
	private _runningExtensions: IExtensionDescription[] | null = null;
1230 1231

	constructor(
1232
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
1233
		@IHostService private readonly hostService: IHostService,
1234
		@IExtensionService private readonly extensionService: IExtensionService,
S
rename  
Sandeep Somavarapu 已提交
1235
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService,
1236 1237 1238
		@IExtensionManagementServerService private readonly extensionManagementServerService: IExtensionManagementServerService,
		@IProductService private readonly productService: IProductService,
		@IConfigurationService private readonly configurationService: IConfigurationService,
1239 1240
	) {
		super('extensions.reload', localize('reloadAction', "Reload"), ReloadAction.DisabledClass, false);
M
Matt Bierner 已提交
1241
		this._register(this.extensionService.onDidChangeExtensions(this.updateRunningExtensions, this));
1242
		this.updateRunningExtensions();
1243 1244
	}

1245
	private updateRunningExtensions(): void {
1246
		this.extensionService.getExtensions().then(runningExtensions => { this._runningExtensions = runningExtensions; this.update(); });
1247 1248 1249 1250 1251
	}

	update(): void {
		this.enabled = false;
		this.tooltip = '';
1252
		if (!this.extension || !this._runningExtensions) {
1253 1254 1255 1256 1257 1258
			return;
		}
		const state = this.extension.state;
		if (state === ExtensionState.Installing || state === ExtensionState.Uninstalling) {
			return;
		}
1259
		if (this.extension.local && this.extension.local.manifest && this.extension.local.manifest.contributes && this.extension.local.manifest.contributes.localizations && this.extension.local.manifest.contributes.localizations.length > 0) {
1260 1261
			return;
		}
1262
		this.computeReloadState();
1263
		this.class = this.enabled ? ReloadAction.EnabledClass : ReloadAction.DisabledClass;
1264 1265
	}

1266
	private computeReloadState(): void {
S
Sandeep Somavarapu 已提交
1267
		if (!this._runningExtensions || !this.extension) {
1268 1269
			return;
		}
S
Sandeep Somavarapu 已提交
1270

1271
		const isUninstalled = this.extension.state === ExtensionState.Uninstalled;
S
Sandeep Somavarapu 已提交
1272
		const runningExtension = this._runningExtensions.filter(e => areSameExtensions({ id: e.identifier.value, uuid: e.uuid }, this.extension!.identifier))[0];
1273
		const isSameExtensionRunning = runningExtension && this.extension.server === this.extensionManagementServerService.getExtensionManagementServer(toExtension(runningExtension));
1274

1275
		if (isUninstalled) {
S
Sandeep Somavarapu 已提交
1276
			if (isSameExtensionRunning && !this.extensionService.canRemoveExtension(runningExtension)) {
1277 1278 1279 1280 1281 1282 1283
				this.enabled = true;
				this.label = localize('reloadRequired', "Reload Required");
				this.tooltip = localize('postUninstallTooltip', "Please reload Visual Studio Code to complete the uninstallation of this extension.");
				alert(localize('uninstallExtensionComplete', "Please reload Visual Studio Code to complete the uninstallation of the extension {0}.", this.extension.displayName));
			}
			return;
		}
1284 1285
		if (this.extension.local) {
			const isEnabled = this.extensionEnablementService.isEnabled(this.extension.local);
S
Sandeep Somavarapu 已提交
1286

1287
			// Extension is running
1288
			if (runningExtension) {
1289
				if (isEnabled) {
1290 1291 1292 1293
					// No Reload is required if extension can run without reload
					if (this.extensionService.canAddExtension(toExtensionDescription(this.extension.local))) {
						return;
					}
1294
					const runningExtensionServer = this.extensionManagementServerService.getExtensionManagementServer(toExtension(runningExtension));
S
Sandeep Somavarapu 已提交
1295

1296 1297 1298 1299 1300 1301
					if (isSameExtensionRunning) {
						// Different version of same extension is running. Requires reload to run the current version
						if (this.extension.version !== runningExtension.version) {
							this.enabled = true;
							this.label = localize('reloadRequired', "Reload Required");
							this.tooltip = localize('postUpdateTooltip', "Please reload Visual Studio Code to enable the updated extension.");
S
Sandeep Somavarapu 已提交
1302
							return;
1303
						}
S
Sandeep Somavarapu 已提交
1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323

						const extensionInOtherServer = this.extensionsWorkbenchService.installed.filter(e => areSameExtensions(e.identifier, this.extension!.identifier) && e.server !== this.extension!.server)[0];
						if (extensionInOtherServer) {
							// This extension prefers to run on UI/Local side but is running in remote
							if (runningExtensionServer === this.extensionManagementServerService.remoteExtensionManagementServer && prefersExecuteOnUI(this.extension.local!.manifest, this.productService, this.configurationService)) {
								this.enabled = true;
								this.label = localize('reloadRequired', "Reload Required");
								this.tooltip = localize('enable locally', "Please reload Visual Studio Code to enable this extension locally.");
								return;
							}

							// This extension prefers to run on Workspace/Remote side but is running in local
							if (runningExtensionServer === this.extensionManagementServerService.localExtensionManagementServer && prefersExecuteOnWorkspace(this.extension.local!.manifest, this.productService, this.configurationService)) {
								this.enabled = true;
								this.label = localize('reloadRequired', "Reload Required");
								this.tooltip = localize('enable remote', "Please reload Visual Studio Code to enable this extension in {0}.", this.extensionManagementServerService.remoteExtensionManagementServer?.label);
								return;
							}
						}

1324
					} else {
S
Sandeep Somavarapu 已提交
1325

1326 1327 1328
						if (this.extension.server === this.extensionManagementServerService.localExtensionManagementServer && runningExtensionServer === this.extensionManagementServerService.remoteExtensionManagementServer) {
							// This extension prefers to run on UI/Local side but is running in remote
							if (prefersExecuteOnUI(this.extension.local!.manifest, this.productService, this.configurationService)) {
1329 1330
								this.enabled = true;
								this.label = localize('reloadRequired', "Reload Required");
1331 1332 1333 1334 1335 1336 1337 1338 1339
								this.tooltip = localize('postEnableTooltip', "Please reload Visual Studio Code to enable this extension.");
							}
						}
						if (this.extension.server === this.extensionManagementServerService.remoteExtensionManagementServer && runningExtensionServer === this.extensionManagementServerService.localExtensionManagementServer) {
							// This extension prefers to run on Workspace/Remote side but is running in local
							if (prefersExecuteOnWorkspace(this.extension.local!.manifest, this.productService, this.configurationService)) {
								this.enabled = true;
								this.label = localize('reloadRequired', "Reload Required");
								this.tooltip = localize('postEnableTooltip', "Please reload Visual Studio Code to enable this extension.");
1340 1341
							}
						}
1342
					}
1343
					return;
1344 1345 1346 1347 1348
				} else {
					if (isSameExtensionRunning) {
						this.enabled = true;
						this.label = localize('reloadRequired', "Reload Required");
						this.tooltip = localize('postDisableTooltip', "Please reload Visual Studio Code to disable this extension.");
S
Sandeep Somavarapu 已提交
1349
					}
1350
				}
1351
				return;
S
Sandeep Somavarapu 已提交
1352 1353 1354 1355
			}

			// Extension is not running
			else {
1356
				if (isEnabled && !this.extensionService.canAddExtension(toExtensionDescription(this.extension.local))) {
1357
					this.enabled = true;
S
Sandeep Somavarapu 已提交
1358
					this.label = localize('reloadRequired', "Reload Required");
1359
					this.tooltip = localize('postEnableTooltip', "Please reload Visual Studio Code to enable this extension.");
1360
					return;
1361
				}
S
Sandeep Somavarapu 已提交
1362 1363 1364

				const otherServer = this.extension.server ? this.extension.server === this.extensionManagementServerService.localExtensionManagementServer ? this.extensionManagementServerService.remoteExtensionManagementServer : this.extensionManagementServerService.localExtensionManagementServer : null;
				if (otherServer && this.extension.enablementState === EnablementState.DisabledByExtensionKind) {
S
Sandeep Somavarapu 已提交
1365
					const extensionInOtherServer = this.extensionsWorkbenchService.local.filter(e => areSameExtensions(e.identifier, this.extension!.identifier) && e.server === otherServer)[0];
S
Sandeep Somavarapu 已提交
1366 1367 1368 1369 1370
					// Same extension in other server exists and
					if (extensionInOtherServer && extensionInOtherServer.local && this.extensionEnablementService.isEnabled(extensionInOtherServer.local)) {
						this.enabled = true;
						this.label = localize('reloadRequired', "Reload Required");
						this.tooltip = localize('postEnableTooltip', "Please reload Visual Studio Code to enable this extension.");
1371
						alert(localize('installExtensionCompletedAndReloadRequired', "Installing extension {0} is completed. Please reload Visual Studio Code to enable it.", this.extension.displayName));
S
Sandeep Somavarapu 已提交
1372
						return;
S
Explore  
Sandeep Somavarapu 已提交
1373
					}
1374
				}
1375 1376 1377 1378
			}
		}
	}

S
Sandeep Somavarapu 已提交
1379
	run(): Promise<any> {
1380
		return Promise.resolve(this.hostService.reload());
1381 1382 1383
	}
}

1384 1385 1386
function isThemeFromExtension(theme: IWorkbenchTheme, extension: IExtension | undefined | null): boolean {
	return !!(extension && theme.extensionData && ExtensionIdentifier.equals(theme.extensionData.extensionId, extension.identifier.id));
}
S
Sandeep Somavarapu 已提交
1387

1388 1389 1390 1391 1392 1393 1394 1395 1396 1397
function getQuickPickEntries(themes: IWorkbenchTheme[], currentTheme: IWorkbenchTheme, extension: IExtension | null | undefined, showCurrentTheme: boolean): (IQuickPickItem | IQuickPickSeparator)[] {
	const picks: (IQuickPickItem | IQuickPickSeparator)[] = [];
	for (const theme of themes) {
		if (isThemeFromExtension(theme, extension) && !(showCurrentTheme && theme === currentTheme)) {
			picks.push({ label: theme.label, id: theme.id });
		}
	}
	if (showCurrentTheme) {
		picks.push(<IQuickPickSeparator>{ type: 'separator', label: localize('current', "Current") });
		picks.push(<IQuickPickItem>{ label: currentTheme.label, id: currentTheme.id });
1398
	}
1399 1400 1401 1402 1403
	return picks;
}


export class SetColorThemeAction extends ExtensionAction {
1404

S
Sandeep Somavarapu 已提交
1405
	private static readonly EnabledClass = `${ExtensionAction.LABEL_ACTION_CLASS} theme`;
S
Sandeep Somavarapu 已提交
1406 1407
	private static readonly DisabledClass = `${SetColorThemeAction.EnabledClass} disabled`;

1408 1409 1410 1411 1412 1413 1414 1415 1416 1417
	static async create(workbenchThemeService: IWorkbenchThemeService, instantiationService: IInstantiationService, extension: IExtension): Promise<SetColorThemeAction | undefined> {
		const themes = await workbenchThemeService.getColorThemes();
		if (themes.some(th => isThemeFromExtension(th, extension))) {
			const action = instantiationService.createInstance(SetColorThemeAction, themes);
			action.extension = extension;
			return action;
		}
		return undefined;
	}

S
Sandeep Somavarapu 已提交
1418
	constructor(
1419
		private colorThemes: IWorkbenchColorTheme[],
S
Sandeep Somavarapu 已提交
1420 1421 1422 1423 1424
		@IExtensionService extensionService: IExtensionService,
		@IWorkbenchThemeService private readonly workbenchThemeService: IWorkbenchThemeService,
		@IQuickInputService private readonly quickInputService: IQuickInputService,
	) {
		super(`extensions.colorTheme`, localize('color theme', "Set Color Theme"), SetColorThemeAction.DisabledClass, false);
M
Matt Bierner 已提交
1425
		this._register(Event.any<any>(extensionService.onDidChangeExtensions, workbenchThemeService.onDidColorThemeChange)(() => this.update(), this));
S
Sandeep Somavarapu 已提交
1426 1427 1428
		this.update();
	}

1429
	update(): void {
1430
		this.enabled = !!this.extension && (this.extension.state === ExtensionState.Installed) && this.colorThemes.some(th => isThemeFromExtension(th, this.extension));
S
Sandeep Somavarapu 已提交
1431 1432 1433
		this.class = this.enabled ? SetColorThemeAction.EnabledClass : SetColorThemeAction.DisabledClass;
	}

S
Sandeep Somavarapu 已提交
1434
	async run({ showCurrentTheme, ignoreFocusLost }: { showCurrentTheme: boolean, ignoreFocusLost: boolean } = { showCurrentTheme: false, ignoreFocusLost: false }): Promise<any> {
1435 1436
		this.colorThemes = await this.workbenchThemeService.getColorThemes();

1437
		this.update();
S
Sandeep Somavarapu 已提交
1438 1439 1440
		if (!this.enabled) {
			return;
		}
1441
		const currentTheme = this.workbenchThemeService.getColorTheme();
S
Sandeep Somavarapu 已提交
1442 1443

		const delayer = new Delayer<any>(100);
1444
		const picks = getQuickPickEntries(this.colorThemes, currentTheme, this.extension, showCurrentTheme);
S
Sandeep Somavarapu 已提交
1445 1446 1447 1448
		const pickedTheme = await this.quickInputService.pick(
			picks,
			{
				placeHolder: localize('select color theme', "Select Color Theme"),
S
Sandeep Somavarapu 已提交
1449 1450
				onDidFocus: item => delayer.trigger(() => this.workbenchThemeService.setColorTheme(item.id, undefined)),
				ignoreFocusLost
S
Sandeep Somavarapu 已提交
1451
			});
1452
		return this.workbenchThemeService.setColorTheme(pickedTheme ? pickedTheme.id : currentTheme.id, 'auto');
S
Sandeep Somavarapu 已提交
1453 1454 1455 1456 1457
	}
}

export class SetFileIconThemeAction extends ExtensionAction {

S
Sandeep Somavarapu 已提交
1458
	private static readonly EnabledClass = `${ExtensionAction.LABEL_ACTION_CLASS} theme`;
S
Sandeep Somavarapu 已提交
1459 1460
	private static readonly DisabledClass = `${SetFileIconThemeAction.EnabledClass} disabled`;

1461 1462 1463 1464 1465 1466 1467 1468
	static async create(workbenchThemeService: IWorkbenchThemeService, instantiationService: IInstantiationService, extension: IExtension): Promise<SetFileIconThemeAction | undefined> {
		const themes = await workbenchThemeService.getFileIconThemes();
		if (themes.some(th => isThemeFromExtension(th, extension))) {
			const action = instantiationService.createInstance(SetFileIconThemeAction, themes);
			action.extension = extension;
			return action;
		}
		return undefined;
1469 1470
	}

S
Sandeep Somavarapu 已提交
1471
	constructor(
1472
		private fileIconThemes: IWorkbenchFileIconTheme[],
S
Sandeep Somavarapu 已提交
1473 1474
		@IExtensionService extensionService: IExtensionService,
		@IWorkbenchThemeService private readonly workbenchThemeService: IWorkbenchThemeService,
1475
		@IQuickInputService private readonly quickInputService: IQuickInputService
S
Sandeep Somavarapu 已提交
1476 1477
	) {
		super(`extensions.fileIconTheme`, localize('file icon theme', "Set File Icon Theme"), SetFileIconThemeAction.DisabledClass, false);
M
Matt Bierner 已提交
1478
		this._register(Event.any<any>(extensionService.onDidChangeExtensions, workbenchThemeService.onDidFileIconThemeChange)(() => this.update(), this));
S
Sandeep Somavarapu 已提交
1479 1480 1481
		this.update();
	}

1482
	update(): void {
1483
		this.enabled = !!this.extension && (this.extension.state === ExtensionState.Installed) && this.fileIconThemes.some(th => isThemeFromExtension(th, this.extension));
S
Sandeep Somavarapu 已提交
1484 1485 1486
		this.class = this.enabled ? SetFileIconThemeAction.EnabledClass : SetFileIconThemeAction.DisabledClass;
	}

S
Sandeep Somavarapu 已提交
1487
	async run({ showCurrentTheme, ignoreFocusLost }: { showCurrentTheme: boolean, ignoreFocusLost: boolean } = { showCurrentTheme: false, ignoreFocusLost: false }): Promise<any> {
1488 1489
		this.fileIconThemes = await this.workbenchThemeService.getFileIconThemes();
		this.update();
S
Sandeep Somavarapu 已提交
1490 1491 1492
		if (!this.enabled) {
			return;
		}
1493
		const currentTheme = this.workbenchThemeService.getFileIconTheme();
S
Sandeep Somavarapu 已提交
1494 1495

		const delayer = new Delayer<any>(100);
1496
		const picks = getQuickPickEntries(this.fileIconThemes, currentTheme, this.extension, showCurrentTheme);
S
Sandeep Somavarapu 已提交
1497 1498 1499 1500
		const pickedTheme = await this.quickInputService.pick(
			picks,
			{
				placeHolder: localize('select file icon theme', "Select File Icon Theme"),
S
Sandeep Somavarapu 已提交
1501 1502
				onDidFocus: item => delayer.trigger(() => this.workbenchThemeService.setFileIconTheme(item.id, undefined)),
				ignoreFocusLost
S
Sandeep Somavarapu 已提交
1503
			});
1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559
		return this.workbenchThemeService.setFileIconTheme(pickedTheme ? pickedTheme.id : currentTheme.id, 'auto');
	}
}

export class SetProductIconThemeAction extends ExtensionAction {

	private static readonly EnabledClass = `${ExtensionAction.LABEL_ACTION_CLASS} theme`;
	private static readonly DisabledClass = `${SetProductIconThemeAction.EnabledClass} disabled`;

	static async create(workbenchThemeService: IWorkbenchThemeService, instantiationService: IInstantiationService, extension: IExtension): Promise<SetProductIconThemeAction | undefined> {
		const themes = await workbenchThemeService.getProductIconThemes();
		if (themes.some(th => isThemeFromExtension(th, extension))) {
			const action = instantiationService.createInstance(SetProductIconThemeAction, themes);
			action.extension = extension;
			return action;
		}
		return undefined;
	}

	constructor(
		private productIconThemes: IWorkbenchProductIconTheme[],
		@IExtensionService extensionService: IExtensionService,
		@IWorkbenchThemeService private readonly workbenchThemeService: IWorkbenchThemeService,
		@IQuickInputService private readonly quickInputService: IQuickInputService
	) {
		super(`extensions.productIconTheme`, localize('product icon theme', "Set Product Icon Theme"), SetProductIconThemeAction.DisabledClass, false);
		this._register(Event.any<any>(extensionService.onDidChangeExtensions, workbenchThemeService.onDidProductIconThemeChange)(() => this.update(), this));
		this.enabled = true; // enabled by default
		this.class = SetProductIconThemeAction.EnabledClass;
		//		this.update();
	}

	update(): void {
		this.enabled = !!this.extension && (this.extension.state === ExtensionState.Installed) && this.productIconThemes.some(th => isThemeFromExtension(th, this.extension));
		this.class = this.enabled ? SetProductIconThemeAction.EnabledClass : SetProductIconThemeAction.DisabledClass;
	}

	async run({ showCurrentTheme, ignoreFocusLost }: { showCurrentTheme: boolean, ignoreFocusLost: boolean } = { showCurrentTheme: false, ignoreFocusLost: false }): Promise<any> {
		this.productIconThemes = await this.workbenchThemeService.getProductIconThemes();
		this.update();
		if (!this.enabled) {
			return;
		}

		const currentTheme = this.workbenchThemeService.getProductIconTheme();

		const delayer = new Delayer<any>(100);
		const picks = getQuickPickEntries(this.productIconThemes, currentTheme, this.extension, showCurrentTheme);
		const pickedTheme = await this.quickInputService.pick(
			picks,
			{
				placeHolder: localize('select product icon theme', "Select Product Icon Theme"),
				onDidFocus: item => delayer.trigger(() => this.workbenchThemeService.setProductIconTheme(item.id, undefined)),
				ignoreFocusLost
			});
		return this.workbenchThemeService.setProductIconTheme(pickedTheme ? pickedTheme.id : currentTheme.id, 'auto');
S
Sandeep Somavarapu 已提交
1560 1561 1562
	}
}

B
Benjamin Pasero 已提交
1563
export class OpenExtensionsViewletAction extends ShowViewletAction {
1564 1565 1566 1567 1568 1569 1570 1571

	static ID = VIEWLET_ID;
	static LABEL = localize('toggleExtensionsViewlet', "Show Extensions");

	constructor(
		id: string,
		label: string,
		@IViewletService viewletService: IViewletService,
B
Benjamin Pasero 已提交
1572
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
1573
		@IWorkbenchLayoutService layoutService: IWorkbenchLayoutService
1574
	) {
1575
		super(id, label, VIEWLET_ID, viewletService, editorGroupService, layoutService);
1576 1577 1578 1579 1580 1581 1582 1583
	}
}

export class InstallExtensionsAction extends OpenExtensionsViewletAction {
	static ID = 'workbench.extensions.action.installExtensions';
	static LABEL = localize('installExtensions', "Install Extensions");
}

1584 1585
export class ShowEnabledExtensionsAction extends Action {

1586
	static readonly ID = 'workbench.extensions.action.showEnabledExtensions';
1587
	static readonly LABEL = localize('showEnabledExtensions', "Show Enabled Extensions");
1588 1589 1590 1591

	constructor(
		id: string,
		label: string,
1592
		@IViewletService private readonly viewletService: IViewletService
1593
	) {
R
Rob Lourens 已提交
1594
		super(id, label, undefined, true);
1595 1596
	}

J
Johannes Rieken 已提交
1597
	run(): Promise<void> {
1598
		return this.viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
1599
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
1600
			.then(viewlet => {
1601
				viewlet.search('@enabled ');
1602 1603 1604 1605 1606
				viewlet.focus();
			});
	}
}

1607 1608
export class ShowInstalledExtensionsAction extends Action {

1609
	static readonly ID = 'workbench.extensions.action.showInstalledExtensions';
1610
	static readonly LABEL = localize('showInstalledExtensions', "Show Installed Extensions");
1611 1612 1613 1614

	constructor(
		id: string,
		label: string,
1615
		@IViewletService private readonly viewletService: IViewletService
1616
	) {
R
Rob Lourens 已提交
1617
		super(id, label, undefined, true);
1618 1619
	}

1620
	run(refresh?: boolean): Promise<void> {
1621
		return this.viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
1622
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
1623
			.then(viewlet => {
1624
				viewlet.search('@installed ', refresh);
1625 1626 1627 1628 1629 1630 1631
				viewlet.focus();
			});
	}
}

export class ShowDisabledExtensionsAction extends Action {

1632
	static readonly ID = 'workbench.extensions.action.showDisabledExtensions';
1633
	static readonly LABEL = localize('showDisabledExtensions', "Show Disabled Extensions");
1634 1635 1636 1637

	constructor(
		id: string,
		label: string,
1638
		@IViewletService private readonly viewletService: IViewletService
1639 1640 1641 1642
	) {
		super(id, label, 'null', true);
	}

J
Johannes Rieken 已提交
1643
	run(): Promise<void> {
1644
		return this.viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
1645
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
1646 1647 1648 1649 1650 1651 1652
			.then(viewlet => {
				viewlet.search('@disabled ');
				viewlet.focus();
			});
	}
}

S
Sandeep Somavarapu 已提交
1653
export class ClearExtensionsSearchResultsAction extends Action {
1654

S
Sandeep Somavarapu 已提交
1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676
	static readonly ID = 'workbench.extensions.action.clearExtensionsSearchResults';
	static readonly LABEL = localize('clearExtensionsSearchResults', "Clear Extensions Search Results");

	constructor(
		id: string,
		label: string,
		@IViewsService private readonly viewsService: IViewsService
	) {
		super(id, label, 'codicon-clear-all', true);
	}

	async run(): Promise<void> {
		const viewPaneContainer = this.viewsService.getActiveViewPaneContainerWithId(VIEWLET_ID);
		if (viewPaneContainer) {
			const extensionsViewPaneContainer = viewPaneContainer as IExtensionsViewPaneContainer;
			extensionsViewPaneContainer.search('');
			extensionsViewPaneContainer.focus();
		}
	}
}

export class ClearExtensionsInputAction extends ClearExtensionsSearchResultsAction {
1677 1678 1679 1680 1681

	constructor(
		id: string,
		label: string,
		onSearchChange: Event<string>,
1682
		value: string,
S
Sandeep Somavarapu 已提交
1683
		@IViewsService viewsService: IViewsService
1684
	) {
S
Sandeep Somavarapu 已提交
1685
		super(id, label, viewsService);
1686
		this.onSearchChange(value);
M
Matt Bierner 已提交
1687
		this._register(onSearchChange(this.onSearchChange, this));
1688 1689 1690 1691 1692 1693 1694 1695
	}

	private onSearchChange(value: string): void {
		this.enabled = !!value;
	}

}

S
Sandeep Somavarapu 已提交
1696 1697 1698
export class ShowBuiltInExtensionsAction extends Action {

	static readonly ID = 'workbench.extensions.action.listBuiltInExtensions';
1699
	static readonly LABEL = localize('showBuiltInExtensions', "Show Built-in Extensions");
S
Sandeep Somavarapu 已提交
1700 1701 1702 1703

	constructor(
		id: string,
		label: string,
1704
		@IViewletService private readonly viewletService: IViewletService
S
Sandeep Somavarapu 已提交
1705
	) {
R
Rob Lourens 已提交
1706
		super(id, label, undefined, true);
S
Sandeep Somavarapu 已提交
1707 1708
	}

J
Johannes Rieken 已提交
1709
	run(): Promise<void> {
S
Sandeep Somavarapu 已提交
1710
		return this.viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
1711
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
S
Sandeep Somavarapu 已提交
1712 1713 1714 1715 1716 1717 1718
			.then(viewlet => {
				viewlet.search('@builtin ');
				viewlet.focus();
			});
	}
}

1719 1720
export class ShowOutdatedExtensionsAction extends Action {

1721
	static readonly ID = 'workbench.extensions.action.listOutdatedExtensions';
1722
	static readonly LABEL = localize('showOutdatedExtensions', "Show Outdated Extensions");
1723 1724 1725 1726

	constructor(
		id: string,
		label: string,
1727
		@IViewletService private readonly viewletService: IViewletService
1728
	) {
R
Rob Lourens 已提交
1729
		super(id, label, undefined, true);
1730 1731
	}

J
Johannes Rieken 已提交
1732
	run(): Promise<void> {
1733
		return this.viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
1734
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
1735 1736 1737 1738 1739 1740 1741 1742 1743
			.then(viewlet => {
				viewlet.search('@outdated ');
				viewlet.focus();
			});
	}
}

export class ShowPopularExtensionsAction extends Action {

1744
	static readonly ID = 'workbench.extensions.action.showPopularExtensions';
1745
	static readonly LABEL = localize('showPopularExtensions', "Show Popular Extensions");
1746 1747 1748 1749

	constructor(
		id: string,
		label: string,
1750
		@IViewletService private readonly viewletService: IViewletService
1751
	) {
R
Rob Lourens 已提交
1752
		super(id, label, undefined, true);
1753 1754
	}

J
Johannes Rieken 已提交
1755
	run(): Promise<void> {
1756
		return this.viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
1757
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
1758
			.then(viewlet => {
S
Sandeep Somavarapu 已提交
1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780
				viewlet.search('@popular ');
				viewlet.focus();
			});
	}
}

export class PredefinedExtensionFilterAction extends Action {

	constructor(
		id: string,
		label: string,
		private readonly filter: string,
		@IViewletService private readonly viewletService: IViewletService
	) {
		super(id, label, undefined, true);
	}

	run(): Promise<void> {
		return this.viewletService.openViewlet(VIEWLET_ID, true)
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
			.then(viewlet => {
				viewlet.search(`${this.filter} `);
1781 1782 1783 1784 1785
				viewlet.focus();
			});
	}
}

S
Sandeep Somavarapu 已提交
1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808
export class RecentlyPublishedExtensionsAction extends Action {

	static readonly ID = 'workbench.extensions.action.recentlyPublishedExtensions';
	static readonly LABEL = localize('recentlyPublishedExtensions', "Recently Published Extensions");

	constructor(
		id: string,
		label: string,
		@IViewletService private readonly viewletService: IViewletService
	) {
		super(id, label, undefined, true);
	}

	run(): Promise<void> {
		return this.viewletService.openViewlet(VIEWLET_ID, true)
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
			.then(viewlet => {
				viewlet.search('@sort:publishedDate ');
				viewlet.focus();
			});
	}
}

1809 1810
export class ShowRecommendedExtensionsAction extends Action {

1811
	static readonly ID = 'workbench.extensions.action.showRecommendedExtensions';
1812
	static readonly LABEL = localize('showRecommendedExtensions', "Show Recommended Extensions");
1813 1814 1815 1816

	constructor(
		id: string,
		label: string,
1817
		@IViewletService private readonly viewletService: IViewletService
1818
	) {
R
Rob Lourens 已提交
1819
		super(id, label, undefined, true);
1820 1821
	}

J
Johannes Rieken 已提交
1822
	run(): Promise<void> {
1823
		return this.viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
1824
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
1825
			.then(viewlet => {
S
Sandeep Somavarapu 已提交
1826
				viewlet.search('@recommended ', true);
1827 1828 1829 1830 1831
				viewlet.focus();
			});
	}
}

S
Sandeep Somavarapu 已提交
1832
export class InstallRecommendedExtensionsAction extends Action {
1833

S
Sandeep Somavarapu 已提交
1834 1835
	static readonly ID = 'workbench.extensions.action.installRecommendedExtensions';
	static readonly LABEL = localize('installRecommendedExtensions', "Install Recommended Extensions");
1836

1837 1838 1839
	private _recommendations: string[] = [];
	get recommendations(): string[] { return this._recommendations; }
	set recommendations(recommendations: string[]) { this._recommendations = recommendations; this.enabled = this._recommendations.length > 0; }
S
Sandeep Somavarapu 已提交
1840

1841
	constructor(
S
Sandeep Somavarapu 已提交
1842 1843
		id: string,
		label: string,
1844
		recommendations: string[],
1845
		private readonly searchValue: string,
S
Sandeep Somavarapu 已提交
1846
		private readonly source: string,
1847 1848
		@IViewletService private readonly viewletService: IViewletService,
		@IInstantiationService private readonly instantiationService: IInstantiationService,
1849 1850
		@IExtensionsWorkbenchService private readonly extensionWorkbenchService: IExtensionsWorkbenchService,
		@IConfigurationService private readonly configurationService: IConfigurationService,
A
Alex Dima 已提交
1851 1852
		@IExtensionManagementServerService private readonly extensionManagementServerService: IExtensionManagementServerService,
		@IProductService private readonly productService: IProductService,
1853 1854
	) {
		super(id, label, 'extension-action');
S
Sandeep Somavarapu 已提交
1855
		this.recommendations = recommendations;
1856 1857
	}

1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868
	async run(): Promise<any> {
		await new SearchExtensionsAction(this.searchValue, this.viewletService).run();
		const names = this.recommendations;
		const pager = await this.extensionWorkbenchService.queryGallery({ names, source: this.source }, CancellationToken.None);
		const installPromises: Promise<any>[] = [];
		const model = new PagedModel(pager);
		for (let i = 0; i < pager.total; i++) {
			installPromises.push(model.resolve(i, CancellationToken.None)
				.then(e => this.installExtension(e)));
		}
		return Promise.all(installPromises);
1869
	}
1870 1871 1872 1873

	private async installExtension(extension: IExtension): Promise<void> {
		try {
			if (extension.local && extension.gallery) {
1874
				if (prefersExecuteOnUI(extension.local.manifest, this.productService, this.configurationService)) {
1875 1876 1877 1878
					if (this.extensionManagementServerService.localExtensionManagementServer) {
						await this.extensionManagementServerService.localExtensionManagementServer.extensionManagementService.installFromGallery(extension.gallery);
						return;
					}
1879 1880 1881 1882 1883
				} else if (this.extensionManagementServerService.remoteExtensionManagementServer) {
					await this.extensionManagementServerService.remoteExtensionManagementServer.extensionManagementService.installFromGallery(extension.gallery);
					return;
				}
			}
1884
			this.extensionWorkbenchService.open(extension, { pinned: true });
1885 1886 1887
			await this.extensionWorkbenchService.install(extension);
		} catch (err) {
			console.error(err);
1888
			return promptDownloadManually(extension.gallery, localize('failedToInstall', "Failed to install \'{0}\'.", extension.identifier.id), err, this.instantiationService);
1889 1890
		}
	}
1891 1892
}

S
Sandeep Somavarapu 已提交
1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903
export class InstallWorkspaceRecommendedExtensionsAction extends InstallRecommendedExtensionsAction {

	constructor(
		recommendations: string[],
		@IViewletService viewletService: IViewletService,
		@IInstantiationService instantiationService: IInstantiationService,
		@IExtensionsWorkbenchService extensionWorkbenchService: IExtensionsWorkbenchService,
		@IConfigurationService configurationService: IConfigurationService,
		@IExtensionManagementServerService extensionManagementServerService: IExtensionManagementServerService,
		@IProductService productService: IProductService,
	) {
1904
		super('workbench.extensions.action.installWorkspaceRecommendedExtensions', localize('installWorkspaceRecommendedExtensions', "Install Workspace Recommended Extensions"), recommendations, '@recommended ', 'install-all-workspace-recommendations',
S
Sandeep Somavarapu 已提交
1905 1906 1907 1908
			viewletService, instantiationService, extensionWorkbenchService, configurationService, extensionManagementServerService, productService);
	}
}

1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942
export class ShowRecommendedExtensionAction extends Action {

	static readonly ID = 'workbench.extensions.action.showRecommendedExtension';
	static readonly LABEL = localize('showRecommendedExtension', "Show Recommended Extension");

	private extensionId: string;

	constructor(
		extensionId: string,
		@IViewletService private readonly viewletService: IViewletService,
		@IExtensionsWorkbenchService private readonly extensionWorkbenchService: IExtensionsWorkbenchService,
	) {
		super(InstallRecommendedExtensionAction.ID, InstallRecommendedExtensionAction.LABEL, undefined, false);
		this.extensionId = extensionId;
	}

	run(): Promise<any> {
		return this.viewletService.openViewlet(VIEWLET_ID, true)
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
			.then(viewlet => {
				viewlet.search(`@id:${this.extensionId}`);
				viewlet.focus();
				return this.extensionWorkbenchService.queryGallery({ names: [this.extensionId], source: 'install-recommendation', pageSize: 1 }, CancellationToken.None)
					.then(pager => {
						if (pager && pager.firstPage && pager.firstPage.length) {
							const extension = pager.firstPage[0];
							return this.extensionWorkbenchService.open(extension);
						}
						return null;
					});
			});
	}
}

1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955
export class OpenExtensionEditorAction extends Action {

	constructor(
		private readonly extensionId: string,
		@IExtensionsWorkbenchService private readonly extensionWorkbenchService: IExtensionsWorkbenchService,
	) {
		super('extensions.openExtension', localize('open extension', "Open Extension"), undefined, true);
	}

	async run(): Promise<any> {
		const pager = await this.extensionWorkbenchService.queryGallery({ names: [this.extensionId], source: 'install-recommendation', pageSize: 1 }, CancellationToken.None);
		if (pager && pager.firstPage && pager.firstPage.length) {
			const extension = pager.firstPage[0];
S
Sandeep Somavarapu 已提交
1956
			return this.extensionWorkbenchService.open(extension, { pinned: true });
1957 1958 1959 1960
		}
	}
}

1961
export class InstallRecommendedExtensionAction extends Action {
1962

1963
	static readonly ID = 'workbench.extensions.action.installRecommendedExtension';
1964
	static readonly LABEL = localize('installRecommendedExtension', "Install Recommended Extension");
1965 1966 1967 1968

	private extensionId: string;

	constructor(
1969
		extensionId: string,
1970 1971
		@IViewletService private readonly viewletService: IViewletService,
		@IInstantiationService private readonly instantiationService: IInstantiationService,
1972
		@IExtensionsWorkbenchService private readonly extensionWorkbenchService: IExtensionsWorkbenchService,
1973
	) {
R
Rob Lourens 已提交
1974
		super(InstallRecommendedExtensionAction.ID, InstallRecommendedExtensionAction.LABEL, undefined, false);
1975 1976 1977
		this.extensionId = extensionId;
	}

J
Johannes Rieken 已提交
1978
	run(): Promise<any> {
1979
		return this.viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
1980
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
1981
			.then(viewlet => {
1982
				viewlet.search(`@id:${this.extensionId}`);
1983
				viewlet.focus();
S
Sandeep Somavarapu 已提交
1984
				return this.extensionWorkbenchService.queryGallery({ names: [this.extensionId], source: 'install-recommendation', pageSize: 1 }, CancellationToken.None)
S
Sandeep Somavarapu 已提交
1985 1986
					.then(pager => {
						if (pager && pager.firstPage && pager.firstPage.length) {
1987 1988
							const extension = pager.firstPage[0];
							return this.extensionWorkbenchService.install(extension)
1989
								.then(() => this.extensionWorkbenchService.open(extension))
1990 1991
								.then(() => null, err => {
									console.error(err);
1992
									return promptDownloadManually(extension.gallery, localize('failedToInstall', "Failed to install \'{0}\'.", extension.identifier.id), err, this.instantiationService);
1993
								});
S
Sandeep Somavarapu 已提交
1994
						}
1995
						return null;
S
Sandeep Somavarapu 已提交
1996
					});
1997
			});
1998 1999 2000
	}
}

2001 2002 2003 2004
export class IgnoreExtensionRecommendationAction extends Action {

	static readonly ID = 'extensions.ignore';

2005
	private static readonly Class = 'extension-action ignore';
2006 2007

	constructor(
S
Sandeep Somavarapu 已提交
2008
		private readonly extension: IExtension,
2009
		@IExtensionRecommendationsService private readonly extensionsTipsService: IExtensionRecommendationsService,
2010
	) {
2011
		super(IgnoreExtensionRecommendationAction.ID, 'Ignore Recommendation');
2012 2013 2014 2015 2016 2017

		this.class = IgnoreExtensionRecommendationAction.Class;
		this.tooltip = localize('ignoreExtensionRecommendation', "Do not recommend this extension again");
		this.enabled = true;
	}

S
Sandeep Somavarapu 已提交
2018
	public run(): Promise<any> {
S
Sandeep Somavarapu 已提交
2019
		this.extensionsTipsService.toggleIgnoredRecommendation(this.extension.identifier.id, true);
2020
		return Promise.resolve();
2021 2022 2023 2024 2025 2026 2027 2028 2029 2030
	}
}

export class UndoIgnoreExtensionRecommendationAction extends Action {

	static readonly ID = 'extensions.ignore';

	private static readonly Class = 'extension-action undo-ignore';

	constructor(
S
Sandeep Somavarapu 已提交
2031
		private readonly extension: IExtension,
2032
		@IExtensionRecommendationsService private readonly extensionsTipsService: IExtensionRecommendationsService,
2033 2034 2035 2036 2037 2038 2039 2040
	) {
		super(UndoIgnoreExtensionRecommendationAction.ID, 'Undo');

		this.class = UndoIgnoreExtensionRecommendationAction.Class;
		this.tooltip = localize('undo', "Undo");
		this.enabled = true;
	}

S
Sandeep Somavarapu 已提交
2041
	public run(): Promise<any> {
S
Sandeep Somavarapu 已提交
2042
		this.extensionsTipsService.toggleIgnoredRecommendation(this.extension.identifier.id, false);
2043
		return Promise.resolve();
2044 2045 2046
	}
}

2047 2048
export class ShowRecommendedKeymapExtensionsAction extends Action {

2049
	static readonly ID = 'workbench.extensions.action.showRecommendedKeymapExtensions';
2050
	static readonly LABEL = localize('showRecommendedKeymapExtensionsShort', "Keymaps");
2051 2052 2053 2054

	constructor(
		id: string,
		label: string,
2055
		@IViewletService private readonly viewletService: IViewletService
2056
	) {
R
Rob Lourens 已提交
2057
		super(id, label, undefined, true);
2058 2059
	}

J
Johannes Rieken 已提交
2060
	run(): Promise<void> {
2061
		return this.viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
2062
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
2063 2064 2065 2066 2067 2068 2069
			.then(viewlet => {
				viewlet.search('@recommended:keymaps ');
				viewlet.focus();
			});
	}
}

2070
export class ShowLanguageExtensionsAction extends Action {
2071

2072
	static readonly ID = 'workbench.extensions.action.showLanguageExtensions';
2073
	static readonly LABEL = localize('showLanguageExtensionsShort', "Language Extensions");
2074 2075 2076 2077

	constructor(
		id: string,
		label: string,
2078
		@IViewletService private readonly viewletService: IViewletService
2079
	) {
R
Rob Lourens 已提交
2080
		super(id, label, undefined, true);
2081 2082
	}

J
Johannes Rieken 已提交
2083
	run(): Promise<void> {
2084
		return this.viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
2085
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
2086
			.then(viewlet => {
C
Christof Marti 已提交
2087
				viewlet.search('@category:"programming languages" @sort:installs ');
2088 2089 2090 2091 2092
				viewlet.focus();
			});
	}
}

S
Sandeep Somavarapu 已提交
2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104
export class SearchCategoryAction extends Action {

	constructor(
		id: string,
		label: string,
		private readonly category: string,
		@IViewletService private readonly viewletService: IViewletService
	) {
		super(id, label, undefined, true);
	}

	run(): Promise<void> {
2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121
		return new SearchExtensionsAction(`@category:"${this.category.toLowerCase()}"`, this.viewletService).run();
	}
}

export class SearchExtensionsAction extends Action {

	constructor(
		private readonly searchValue: string,
		@IViewletService private readonly viewletService: IViewletService
	) {
		super('extensions.searchExtensions', localize('search recommendations', "Search Extensions"), undefined, true);
	}

	async run(): Promise<void> {
		const viewPaneContainer = (await this.viewletService.openViewlet(VIEWLET_ID, true))?.getViewPaneContainer() as IExtensionsViewPaneContainer;
		viewPaneContainer.search(this.searchValue);
		viewPaneContainer.focus();
S
Sandeep Somavarapu 已提交
2122 2123 2124
	}
}

2125 2126 2127 2128 2129 2130 2131 2132 2133
export class ChangeSortAction extends Action {

	private query: Query;

	constructor(
		id: string,
		label: string,
		onSearchChange: Event<string>,
		private sortBy: string,
2134
		@IViewletService private readonly viewletService: IViewletService
2135
	) {
R
Rob Lourens 已提交
2136
		super(id, label, undefined, true);
2137

J
Joao Moreno 已提交
2138
		if (sortBy === undefined) {
2139 2140 2141 2142 2143
			throw new Error('bad arguments');
		}

		this.query = Query.parse('');
		this.enabled = false;
M
Matt Bierner 已提交
2144
		this._register(onSearchChange(this.onSearchChange, this));
2145 2146 2147 2148
	}

	private onSearchChange(value: string): void {
		const query = Query.parse(value);
2149
		this.query = new Query(query.value, this.sortBy || query.sortBy, query.groupBy);
2150
		this.enabled = !!value && this.query.isValid() && !this.query.equals(query);
2151 2152
	}

J
Johannes Rieken 已提交
2153
	run(): Promise<void> {
2154
		return this.viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
2155
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
2156 2157 2158 2159 2160 2161 2162
			.then(viewlet => {
				viewlet.search(this.query.toString());
				viewlet.focus();
			});
	}
}

S
Sandeep Somavarapu 已提交
2163 2164 2165 2166
export class ConfigureRecommendedExtensionsCommandsContributor extends Disposable implements IWorkbenchContribution {

	private workspaceContextKey = new RawContextKey<boolean>('workspaceRecommendations', true);
	private workspaceFolderContextKey = new RawContextKey<boolean>('workspaceFolderRecommendations', true);
2167 2168
	private addToWorkspaceRecommendationsContextKey = new RawContextKey<boolean>('addToWorkspaceRecommendations', false);
	private addToWorkspaceFolderRecommendationsContextKey = new RawContextKey<boolean>('addToWorkspaceFolderRecommendations', false);
S
Sandeep Somavarapu 已提交
2169 2170 2171

	constructor(
		@IContextKeyService contextKeyService: IContextKeyService,
2172 2173
		@IWorkspaceContextService workspaceContextService: IWorkspaceContextService,
		@IEditorService editorService: IEditorService
S
Sandeep Somavarapu 已提交
2174 2175 2176 2177 2178 2179 2180 2181 2182 2183
	) {
		super();
		const boundWorkspaceContextKey = this.workspaceContextKey.bindTo(contextKeyService);
		boundWorkspaceContextKey.set(workspaceContextService.getWorkbenchState() === WorkbenchState.WORKSPACE);
		this._register(workspaceContextService.onDidChangeWorkbenchState(() => boundWorkspaceContextKey.set(workspaceContextService.getWorkbenchState() === WorkbenchState.WORKSPACE)));

		const boundWorkspaceFolderContextKey = this.workspaceFolderContextKey.bindTo(contextKeyService);
		boundWorkspaceFolderContextKey.set(workspaceContextService.getWorkspace().folders.length > 0);
		this._register(workspaceContextService.onDidChangeWorkspaceFolders(() => boundWorkspaceFolderContextKey.set(workspaceContextService.getWorkspace().folders.length > 0)));

2184 2185 2186 2187 2188 2189 2190 2191 2192 2193
		const boundAddToWorkspaceRecommendationsContextKey = this.addToWorkspaceRecommendationsContextKey.bindTo(contextKeyService);
		boundAddToWorkspaceRecommendationsContextKey.set(editorService.activeEditor instanceof ExtensionsInput && workspaceContextService.getWorkbenchState() === WorkbenchState.WORKSPACE);
		this._register(editorService.onDidActiveEditorChange(() => boundAddToWorkspaceRecommendationsContextKey.set(
			editorService.activeEditor instanceof ExtensionsInput && workspaceContextService.getWorkbenchState() === WorkbenchState.WORKSPACE)));
		this._register(workspaceContextService.onDidChangeWorkbenchState(() => boundAddToWorkspaceRecommendationsContextKey.set(
			editorService.activeEditor instanceof ExtensionsInput && workspaceContextService.getWorkbenchState() === WorkbenchState.WORKSPACE)));

		const boundAddToWorkspaceFolderRecommendationsContextKey = this.addToWorkspaceFolderRecommendationsContextKey.bindTo(contextKeyService);
		boundAddToWorkspaceFolderRecommendationsContextKey.set(editorService.activeEditor instanceof ExtensionsInput);
		this._register(editorService.onDidActiveEditorChange(() => boundAddToWorkspaceFolderRecommendationsContextKey.set(editorService.activeEditor instanceof ExtensionsInput)));
2194

S
Sandeep Somavarapu 已提交
2195 2196 2197 2198 2199 2200 2201 2202 2203 2204
		this.registerCommands();
	}

	private registerCommands(): void {
		CommandsRegistry.registerCommand(ConfigureWorkspaceRecommendedExtensionsAction.ID, serviceAccessor => {
			serviceAccessor.get(IInstantiationService).createInstance(ConfigureWorkspaceRecommendedExtensionsAction, ConfigureWorkspaceRecommendedExtensionsAction.ID, ConfigureWorkspaceRecommendedExtensionsAction.LABEL).run();
		});
		MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
			command: {
				id: ConfigureWorkspaceRecommendedExtensionsAction.ID,
2205
				title: { value: ConfigureWorkspaceRecommendedExtensionsAction.LABEL, original: 'Configure Recommended Extensions (Workspace)' },
2206
				category: localize('extensions', "Extensions")
S
Sandeep Somavarapu 已提交
2207 2208 2209 2210 2211 2212 2213 2214 2215 2216
			},
			when: this.workspaceContextKey
		});

		CommandsRegistry.registerCommand(ConfigureWorkspaceFolderRecommendedExtensionsAction.ID, serviceAccessor => {
			serviceAccessor.get(IInstantiationService).createInstance(ConfigureWorkspaceFolderRecommendedExtensionsAction, ConfigureWorkspaceFolderRecommendedExtensionsAction.ID, ConfigureWorkspaceFolderRecommendedExtensionsAction.LABEL).run();
		});
		MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
			command: {
				id: ConfigureWorkspaceFolderRecommendedExtensionsAction.ID,
2217
				title: { value: ConfigureWorkspaceFolderRecommendedExtensionsAction.LABEL, original: 'Configure Recommended Extensions (Workspace Folder)' },
2218
				category: localize('extensions', "Extensions")
S
Sandeep Somavarapu 已提交
2219 2220 2221
			},
			when: this.workspaceFolderContextKey
		});
2222

2223 2224 2225 2226
		CommandsRegistry.registerCommand(AddToWorkspaceRecommendationsAction.ADD_ID, serviceAccessor => {
			serviceAccessor.get(IInstantiationService)
				.createInstance(AddToWorkspaceRecommendationsAction, AddToWorkspaceRecommendationsAction.ADD_ID, AddToWorkspaceRecommendationsAction.ADD_LABEL)
				.run(AddToWorkspaceRecommendationsAction.ADD);
2227 2228 2229
		});
		MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
			command: {
2230
				id: AddToWorkspaceRecommendationsAction.ADD_ID,
2231
				title: { value: AddToWorkspaceRecommendationsAction.ADD_LABEL, original: 'Add to Recommended Extensions (Workspace)' },
2232
				category: localize('extensions', "Extensions")
2233
			},
2234
			when: this.addToWorkspaceRecommendationsContextKey
2235 2236
		});

2237 2238 2239 2240 2241 2242 2243 2244
		CommandsRegistry.registerCommand(AddToWorkspaceFolderRecommendationsAction.ADD_ID, serviceAccessor => {
			serviceAccessor.get(IInstantiationService)
				.createInstance(AddToWorkspaceFolderRecommendationsAction, AddToWorkspaceFolderRecommendationsAction.ADD_ID, AddToWorkspaceFolderRecommendationsAction.ADD_LABEL)
				.run(AddToWorkspaceRecommendationsAction.ADD);
		});
		MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
			command: {
				id: AddToWorkspaceFolderRecommendationsAction.ADD_ID,
2245
				title: { value: AddToWorkspaceFolderRecommendationsAction.ADD_LABEL, original: 'Extensions: Add to Recommended Extensions (Workspace Folder)' },
2246
				category: localize('extensions', "Extensions")
2247 2248 2249
			},
			when: this.addToWorkspaceFolderRecommendationsContextKey
		});
S
Sandeep Somavarapu 已提交
2250

2251 2252 2253 2254 2255 2256 2257 2258
		CommandsRegistry.registerCommand(AddToWorkspaceRecommendationsAction.IGNORE_ID, serviceAccessor => {
			serviceAccessor.get(IInstantiationService)
				.createInstance(AddToWorkspaceRecommendationsAction, AddToWorkspaceRecommendationsAction.IGNORE_ID, AddToWorkspaceRecommendationsAction.IGNORE_LABEL)
				.run(AddToWorkspaceRecommendationsAction.IGNORE);
		});
		MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
			command: {
				id: AddToWorkspaceRecommendationsAction.IGNORE_ID,
2259
				title: { value: AddToWorkspaceRecommendationsAction.IGNORE_LABEL, original: 'Extensions: Ignore Recommended Extension (Workspace)' },
2260
				category: localize('extensions', "Extensions")
2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272
			},
			when: this.addToWorkspaceRecommendationsContextKey
		});

		CommandsRegistry.registerCommand(AddToWorkspaceFolderRecommendationsAction.IGNORE_ID, serviceAccessor => {
			serviceAccessor.get(IInstantiationService)
				.createInstance(AddToWorkspaceFolderRecommendationsAction, AddToWorkspaceFolderRecommendationsAction.IGNORE_ID, AddToWorkspaceFolderRecommendationsAction.IGNORE_LABEL)
				.run(AddToWorkspaceRecommendationsAction.IGNORE);
		});
		MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
			command: {
				id: AddToWorkspaceFolderRecommendationsAction.IGNORE_ID,
2273
				title: { value: AddToWorkspaceFolderRecommendationsAction.IGNORE_LABEL, original: 'Extensions: Ignore Recommended Extension (Workspace Folder)' },
2274
				category: localize('extensions', "Extensions")
2275 2276 2277 2278
			},
			when: this.addToWorkspaceFolderRecommendationsContextKey
		});
	}
2279 2280 2281 2282 2283 2284 2285 2286
}

export abstract class AbstractConfigureRecommendedExtensionsAction extends Action {

	constructor(
		id: string,
		label: string,
		@IWorkspaceContextService protected contextService: IWorkspaceContextService,
2287
		@IFileService private readonly fileService: IFileService,
2288
		@ITextFileService private readonly textFileService: ITextFileService,
2289
		@IEditorService protected editorService: IEditorService,
2290 2291
		@IJSONEditingService private readonly jsonEditingService: IJSONEditingService,
		@ITextModelService private readonly textModelResolverService: ITextModelService
2292
	) {
2293
		super(id, label);
2294 2295
	}

S
Sandeep Somavarapu 已提交
2296
	protected openExtensionsFile(extensionsFileResource: URI): Promise<any> {
2297
		return this.getOrCreateExtensionsFile(extensionsFileResource)
S
Sandeep Somavarapu 已提交
2298 2299 2300 2301 2302 2303 2304 2305 2306
			.then(({ created, content }) =>
				this.getSelectionPosition(content, extensionsFileResource, ['recommendations'])
					.then(selection => this.editorService.openEditor({
						resource: extensionsFileResource,
						options: {
							pinned: created,
							selection
						}
					})),
S
Sandeep Somavarapu 已提交
2307
				error => Promise.reject(new Error(localize('OpenExtensionsFile.failed', "Unable to create 'extensions.json' file inside the '.vscode' folder ({0}).", error))));
2308 2309
	}

S
Sandeep Somavarapu 已提交
2310
	protected openWorkspaceConfigurationFile(workspaceConfigurationFile: URI): Promise<any> {
2311
		return this.getOrUpdateWorkspaceConfigurationFile(workspaceConfigurationFile)
B
Benjamin Pasero 已提交
2312
			.then(content => this.getSelectionPosition(content.value.toString(), content.resource, ['extensions', 'recommendations']))
2313 2314 2315
			.then(selection => this.editorService.openEditor({
				resource: workspaceConfigurationFile,
				options: {
B
Benjamin Pasero 已提交
2316 2317
					selection,
					forceReload: true // because content has changed
2318 2319 2320 2321
				}
			}));
	}

2322 2323 2324 2325
	protected addExtensionToWorkspaceConfig(workspaceConfigurationFile: URI, extensionId: string, shouldRecommend: boolean) {
		return this.getOrUpdateWorkspaceConfigurationFile(workspaceConfigurationFile)
			.then(content => {
				const extensionIdLowerCase = extensionId.toLowerCase();
B
Benjamin Pasero 已提交
2326
				const workspaceExtensionsConfigContent: IExtensionsConfigContent = (json.parse(content.value.toString()) || {})['extensions'] || {};
2327 2328 2329 2330
				let insertInto = shouldRecommend ? workspaceExtensionsConfigContent.recommendations || [] : workspaceExtensionsConfigContent.unwantedRecommendations || [];
				let removeFrom = shouldRecommend ? workspaceExtensionsConfigContent.unwantedRecommendations || [] : workspaceExtensionsConfigContent.recommendations || [];

				if (insertInto.some(e => e.toLowerCase() === extensionIdLowerCase)) {
S
Sandeep Somavarapu 已提交
2331
					return Promise.resolve(null);
2332 2333 2334 2335 2336 2337
				}

				insertInto.push(extensionId);
				removeFrom = removeFrom.filter(x => x.toLowerCase() !== extensionIdLowerCase);

				return this.jsonEditingService.write(workspaceConfigurationFile,
2338
					[{
S
Sandeep Somavarapu 已提交
2339
						path: ['extensions'],
2340 2341 2342 2343
						value: {
							recommendations: shouldRecommend ? insertInto : removeFrom,
							unwantedRecommendations: shouldRecommend ? removeFrom : insertInto
						}
2344
					}],
2345 2346 2347 2348
					true);
			});
	}

S
Sandeep Somavarapu 已提交
2349
	protected addExtensionToWorkspaceFolderConfig(extensionsFileResource: URI, extensionId: string, shouldRecommend: boolean): Promise<any> {
2350 2351 2352
		return this.getOrCreateExtensionsFile(extensionsFileResource)
			.then(({ content }) => {
				const extensionIdLowerCase = extensionId.toLowerCase();
2353 2354 2355
				const extensionsConfigContent: IExtensionsConfigContent = json.parse(content) || {};
				let insertInto = shouldRecommend ? extensionsConfigContent.recommendations || [] : extensionsConfigContent.unwantedRecommendations || [];
				let removeFrom = shouldRecommend ? extensionsConfigContent.unwantedRecommendations || [] : extensionsConfigContent.recommendations || [];
2356

2357
				if (insertInto.some(e => e.toLowerCase() === extensionIdLowerCase)) {
S
Sandeep Somavarapu 已提交
2358
					return Promise.resolve(null);
2359 2360
				}

2361 2362
				insertInto.push(extensionId);

2363
				let removeFromPromise: Promise<void> = Promise.resolve();
2364 2365 2366
				if (removeFrom.some(e => e.toLowerCase() === extensionIdLowerCase)) {
					removeFrom = removeFrom.filter(x => x.toLowerCase() !== extensionIdLowerCase);
					removeFromPromise = this.jsonEditingService.write(extensionsFileResource,
2367
						[{
S
Sandeep Somavarapu 已提交
2368
							path: shouldRecommend ? ['unwantedRecommendations'] : ['recommendations'],
2369
							value: removeFrom
2370
						}],
2371 2372 2373
						true);
				}

2374
				return removeFromPromise.then(() =>
2375
					this.jsonEditingService.write(extensionsFileResource,
2376
						[{
S
Sandeep Somavarapu 已提交
2377
							path: shouldRecommend ? ['recommendations'] : ['unwantedRecommendations'],
2378
							value: insertInto
2379
						}],
2380 2381 2382 2383 2384
						true)
				);
			});
	}

S
Sandeep Somavarapu 已提交
2385
	protected getWorkspaceExtensionsConfigContent(extensionsFileResource: URI): Promise<IExtensionsConfigContent> {
B
Benjamin Pasero 已提交
2386
		return Promise.resolve(this.fileService.readFile(extensionsFileResource))
2387
			.then(content => {
B
Benjamin Pasero 已提交
2388
				return (json.parse(content.value.toString()) || {})['extensions'] || {};
2389 2390 2391
			}, err => ({ recommendations: [], unwantedRecommendations: [] }));
	}

S
Sandeep Somavarapu 已提交
2392
	protected getWorkspaceFolderExtensionsConfigContent(extensionsFileResource: URI): Promise<IExtensionsConfigContent> {
B
Benjamin Pasero 已提交
2393
		return Promise.resolve(this.fileService.readFile(extensionsFileResource))
2394
			.then(content => {
2395
				return (<IExtensionsConfigContent>json.parse(content.value.toString()) || {});
2396
			}, err => ({ recommendations: [], unwantedRecommendations: [] }));
2397 2398
	}

B
Benjamin Pasero 已提交
2399 2400
	private getOrUpdateWorkspaceConfigurationFile(workspaceConfigurationFile: URI): Promise<IFileContent> {
		return Promise.resolve(this.fileService.readFile(workspaceConfigurationFile))
2401
			.then(content => {
B
Benjamin Pasero 已提交
2402
				const workspaceRecommendations = <IExtensionsConfigContent>json.parse(content.value.toString())['extensions'];
2403
				if (!workspaceRecommendations || !workspaceRecommendations.recommendations) {
S
Sandeep Somavarapu 已提交
2404
					return this.jsonEditingService.write(workspaceConfigurationFile, [{ path: ['extensions'], value: { recommendations: [] } }], true)
B
Benjamin Pasero 已提交
2405
						.then(() => this.fileService.readFile(workspaceConfigurationFile));
2406 2407 2408 2409 2410
				}
				return content;
			});
	}

J
Johannes Rieken 已提交
2411
	private getSelectionPosition(content: string, resource: URI, path: json.JSONPath): Promise<ITextEditorSelection | undefined> {
S
Sandeep Somavarapu 已提交
2412 2413
		const tree = json.parseTree(content);
		const node = json.findNodeAtLocation(tree, path);
2414
		if (node && node.parent && node.parent.children) {
S
Sandeep Somavarapu 已提交
2415 2416 2417
			const recommendationsValueNode = node.parent.children[1];
			const lastExtensionNode = recommendationsValueNode.children && recommendationsValueNode.children.length ? recommendationsValueNode.children[recommendationsValueNode.children.length - 1] : null;
			const offset = lastExtensionNode ? lastExtensionNode.offset + lastExtensionNode.length : recommendationsValueNode.offset + 1;
S
Sandeep Somavarapu 已提交
2418
			return Promise.resolve(this.textModelResolverService.createModelReference(resource))
2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429
				.then(reference => {
					const position = reference.object.textEditorModel.getPositionAt(offset);
					reference.dispose();
					return <ITextEditorSelection>{
						startLineNumber: position.lineNumber,
						startColumn: position.column,
						endLineNumber: position.lineNumber,
						endColumn: position.column,
					};
				});
		}
J
Johannes Rieken 已提交
2430
		return Promise.resolve(undefined);
2431 2432
	}

S
Sandeep Somavarapu 已提交
2433
	private getOrCreateExtensionsFile(extensionsFileResource: URI): Promise<{ created: boolean, extensionsFileResource: URI, content: string }> {
B
Benjamin Pasero 已提交
2434 2435
		return Promise.resolve(this.fileService.readFile(extensionsFileResource)).then(content => {
			return { created: false, extensionsFileResource, content: content.value.toString() };
2436
		}, err => {
B
Benjamin Pasero 已提交
2437
			return this.textFileService.write(extensionsFileResource, ExtensionsConfigurationInitialContent).then(() => {
S
Sandeep Somavarapu 已提交
2438
				return { created: true, extensionsFileResource, content: ExtensionsConfigurationInitialContent };
2439 2440 2441 2442 2443 2444
			});
		});
	}
}

export class ConfigureWorkspaceRecommendedExtensionsAction extends AbstractConfigureRecommendedExtensionsAction {
2445

2446
	static readonly ID = 'workbench.extensions.action.configureWorkspaceRecommendedExtensions';
2447
	static readonly LABEL = localize('configureWorkspaceRecommendedExtensions', "Configure Recommended Extensions (Workspace)");
2448 2449 2450 2451

	constructor(
		id: string,
		label: string,
2452
		@IFileService fileService: IFileService,
2453
		@ITextFileService textFileService: ITextFileService,
2454
		@IWorkspaceContextService contextService: IWorkspaceContextService,
2455
		@IEditorService editorService: IEditorService,
2456 2457
		@IJSONEditingService jsonEditingService: IJSONEditingService,
		@ITextModelService textModelResolverService: ITextModelService
2458
	) {
2459
		super(id, label, contextService, fileService, textFileService, editorService, jsonEditingService, textModelResolverService);
M
Matt Bierner 已提交
2460
		this._register(this.contextService.onDidChangeWorkbenchState(() => this.update(), this));
2461 2462 2463 2464 2465
		this.update();
	}

	private update(): void {
		this.enabled = this.contextService.getWorkbenchState() !== WorkbenchState.EMPTY;
2466 2467
	}

2468
	public run(): Promise<void> {
2469 2470
		switch (this.contextService.getWorkbenchState()) {
			case WorkbenchState.FOLDER:
2471
				return this.openExtensionsFile(this.contextService.getWorkspace().folders[0].toResource(EXTENSIONS_CONFIG));
2472
			case WorkbenchState.WORKSPACE:
2473
				return this.openWorkspaceConfigurationFile(this.contextService.getWorkspace().configuration!);
2474
		}
2475
		return Promise.resolve();
2476
	}
2477
}
2478

2479 2480
export class ConfigureWorkspaceFolderRecommendedExtensionsAction extends AbstractConfigureRecommendedExtensionsAction {

2481
	static readonly ID = 'workbench.extensions.action.configureWorkspaceFolderRecommendedExtensions';
2482
	static readonly LABEL = localize('configureWorkspaceFolderRecommendedExtensions', "Configure Recommended Extensions (Workspace Folder)");
2483 2484 2485 2486 2487

	constructor(
		id: string,
		label: string,
		@IFileService fileService: IFileService,
2488
		@ITextFileService textFileService: ITextFileService,
2489
		@IWorkspaceContextService contextService: IWorkspaceContextService,
2490
		@IEditorService editorService: IEditorService,
2491
		@IJSONEditingService jsonEditingService: IJSONEditingService,
S
Sandeep Somavarapu 已提交
2492
		@ITextModelService textModelResolverService: ITextModelService,
2493
		@ICommandService private readonly commandService: ICommandService
2494
	) {
2495
		super(id, label, contextService, fileService, textFileService, editorService, jsonEditingService, textModelResolverService);
M
Matt Bierner 已提交
2496
		this._register(this.contextService.onDidChangeWorkspaceFolders(() => this.update(), this));
2497
		this.update();
2498 2499
	}

2500 2501 2502
	private update(): void {
		this.enabled = this.contextService.getWorkspace().folders.length > 0;
	}
2503

S
Sandeep Somavarapu 已提交
2504
	public run(): Promise<any> {
2505
		const folderCount = this.contextService.getWorkspace().folders.length;
S
Sandeep Somavarapu 已提交
2506 2507
		const pickFolderPromise = folderCount === 1 ? Promise.resolve(this.contextService.getWorkspace().folders[0]) : this.commandService.executeCommand<IWorkspaceFolder>(PICK_WORKSPACE_FOLDER_COMMAND_ID);
		return Promise.resolve(pickFolderPromise)
S
Sandeep Somavarapu 已提交
2508 2509
			.then(workspaceFolder => {
				if (workspaceFolder) {
2510
					return this.openExtensionsFile(workspaceFolder.toResource(EXTENSIONS_CONFIG));
2511
				}
S
Sandeep Somavarapu 已提交
2512
				return null;
2513
			});
2514 2515 2516
	}
}

2517 2518 2519 2520 2521 2522 2523
export class AddToWorkspaceFolderRecommendationsAction extends AbstractConfigureRecommendedExtensionsAction {
	static readonly ADD = true;
	static readonly IGNORE = false;
	static readonly ADD_ID = 'workbench.extensions.action.addToWorkspaceFolderRecommendations';
	static readonly ADD_LABEL = localize('addToWorkspaceFolderRecommendations', "Add to Recommended Extensions (Workspace Folder)");
	static readonly IGNORE_ID = 'workbench.extensions.action.addToWorkspaceFolderIgnoredRecommendations';
	static readonly IGNORE_LABEL = localize('addToWorkspaceFolderIgnoredRecommendations', "Ignore Recommended Extension (Workspace Folder)");
2524 2525 2526 2527 2528

	constructor(
		id: string,
		label: string,
		@IFileService fileService: IFileService,
2529
		@ITextFileService textFileService: ITextFileService,
2530 2531 2532 2533
		@IWorkspaceContextService contextService: IWorkspaceContextService,
		@IEditorService editorService: IEditorService,
		@IJSONEditingService jsonEditingService: IJSONEditingService,
		@ITextModelService textModelResolverService: ITextModelService,
2534 2535
		@ICommandService private readonly commandService: ICommandService,
		@INotificationService private readonly notificationService: INotificationService
2536
	) {
2537
		super(id, label, contextService, fileService, textFileService, editorService, jsonEditingService, textModelResolverService);
2538 2539
	}

S
Sandeep Somavarapu 已提交
2540
	run(shouldRecommend: boolean): Promise<void> {
2541
		if (!(this.editorService.activeEditor instanceof ExtensionsInput) || !this.editorService.activeEditor.extension) {
2542
			return Promise.resolve();
2543 2544 2545
		}
		const folders = this.contextService.getWorkspace().folders;
		if (!folders || !folders.length) {
2546
			this.notificationService.info(localize('AddToWorkspaceFolderRecommendations.noWorkspace', 'There are no workspace folders open to add recommendations.'));
2547
			return Promise.resolve();
2548 2549
		}

S
Sandeep Somavarapu 已提交
2550
		const extensionId = this.editorService.activeEditor.extension.identifier;
2551
		const pickFolderPromise = folders.length === 1
S
Sandeep Somavarapu 已提交
2552
			? Promise.resolve(folders[0])
2553
			: this.commandService.executeCommand<IWorkspaceFolder>(PICK_WORKSPACE_FOLDER_COMMAND_ID);
S
Sandeep Somavarapu 已提交
2554
		return Promise.resolve(pickFolderPromise)
2555 2556
			.then(workspaceFolder => {
				if (!workspaceFolder) {
2557
					return Promise.resolve();
2558
				}
2559
				const configurationFile = workspaceFolder.toResource(EXTENSIONS_CONFIG);
2560
				return this.getWorkspaceFolderExtensionsConfigContent(configurationFile).then(content => {
S
Sandeep Somavarapu 已提交
2561
					const extensionIdLowerCase = extensionId.id.toLowerCase();
2562
					if (shouldRecommend) {
2563
						if ((content.recommendations || []).some(e => e.toLowerCase() === extensionIdLowerCase)) {
2564
							this.notificationService.info(localize('AddToWorkspaceFolderRecommendations.alreadyExists', 'This extension is already present in this workspace folder\'s recommendations.'));
2565
							return Promise.resolve();
2566 2567
						}

S
Sandeep Somavarapu 已提交
2568
						return this.addExtensionToWorkspaceFolderConfig(configurationFile, extensionId.id, shouldRecommend).then(() => {
2569 2570 2571 2572 2573 2574
							this.notificationService.prompt(Severity.Info,
								localize('AddToWorkspaceFolderRecommendations.success', 'The extension was successfully added to this workspace folder\'s recommendations.'),
								[{
									label: localize('viewChanges', "View Changes"),
									run: () => this.openExtensionsFile(configurationFile)
								}]);
2575 2576 2577
						}, err => {
							this.notificationService.error(localize('AddToWorkspaceFolderRecommendations.failure', 'Failed to write to extensions.json. {0}', err));
						});
2578
					}
2579
					else {
2580
						if ((content.unwantedRecommendations || []).some(e => e.toLowerCase() === extensionIdLowerCase)) {
2581
							this.notificationService.info(localize('AddToWorkspaceFolderIgnoredRecommendations.alreadyExists', 'This extension is already present in this workspace folder\'s unwanted recommendations.'));
2582
							return Promise.resolve();
2583
						}
2584

S
Sandeep Somavarapu 已提交
2585
						return this.addExtensionToWorkspaceFolderConfig(configurationFile, extensionId.id, shouldRecommend).then(() => {
2586 2587 2588 2589 2590 2591
							this.notificationService.prompt(Severity.Info,
								localize('AddToWorkspaceFolderIgnoredRecommendations.success', 'The extension was successfully added to this workspace folder\'s unwanted recommendations.'),
								[{
									label: localize('viewChanges', "View Changes"),
									run: () => this.openExtensionsFile(configurationFile)
								}]);
2592 2593 2594 2595
						}, err => {
							this.notificationService.error(localize('AddToWorkspaceFolderRecommendations.failure', 'Failed to write to extensions.json. {0}', err));
						});
					}
2596 2597 2598 2599 2600
				});
			});
	}
}

2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612
export class AddToWorkspaceRecommendationsAction extends AbstractConfigureRecommendedExtensionsAction {
	static readonly ADD = true;
	static readonly IGNORE = false;
	static readonly ADD_ID = 'workbench.extensions.action.addToWorkspaceRecommendations';
	static readonly ADD_LABEL = localize('addToWorkspaceRecommendations', "Add to Recommended Extensions (Workspace)");
	static readonly IGNORE_ID = 'workbench.extensions.action.addToWorkspaceIgnoredRecommendations';
	static readonly IGNORE_LABEL = localize('addToWorkspaceIgnoredRecommendations', "Ignore Recommended Extension (Workspace)");

	constructor(
		id: string,
		label: string,
		@IFileService fileService: IFileService,
2613
		@ITextFileService textFileService: ITextFileService,
2614 2615 2616 2617
		@IWorkspaceContextService contextService: IWorkspaceContextService,
		@IEditorService editorService: IEditorService,
		@IJSONEditingService jsonEditingService: IJSONEditingService,
		@ITextModelService textModelResolverService: ITextModelService,
2618
		@INotificationService private readonly notificationService: INotificationService
2619
	) {
2620
		super(id, label, contextService, fileService, textFileService, editorService, jsonEditingService, textModelResolverService);
2621 2622
	}

S
Sandeep Somavarapu 已提交
2623
	run(shouldRecommend: boolean): Promise<void> {
2624 2625
		const workspaceConfig = this.contextService.getWorkspace().configuration;

2626 2627 2628 2629
		if (!(this.editorService.activeEditor instanceof ExtensionsInput) || !this.editorService.activeEditor.extension || !workspaceConfig) {
			return Promise.resolve();
		}

S
Sandeep Somavarapu 已提交
2630
		const extensionId = this.editorService.activeEditor.extension.identifier;
2631 2632

		return this.getWorkspaceExtensionsConfigContent(workspaceConfig).then(content => {
S
Sandeep Somavarapu 已提交
2633
			const extensionIdLowerCase = extensionId.id.toLowerCase();
2634 2635 2636
			if (shouldRecommend) {
				if ((content.recommendations || []).some(e => e.toLowerCase() === extensionIdLowerCase)) {
					this.notificationService.info(localize('AddToWorkspaceRecommendations.alreadyExists', 'This extension is already present in workspace recommendations.'));
2637
					return Promise.resolve();
2638 2639
				}

S
Sandeep Somavarapu 已提交
2640
				return this.addExtensionToWorkspaceConfig(workspaceConfig, extensionId.id, shouldRecommend).then(() => {
2641 2642 2643 2644 2645 2646 2647
					this.notificationService.prompt(Severity.Info,
						localize('AddToWorkspaceRecommendations.success', 'The extension was successfully added to this workspace\'s recommendations.'),
						[{
							label: localize('viewChanges', "View Changes"),
							run: () => this.openWorkspaceConfigurationFile(workspaceConfig)
						}]);

2648 2649 2650 2651 2652 2653
				}, err => {
					this.notificationService.error(localize('AddToWorkspaceRecommendations.failure', 'Failed to write. {0}', err));
				});
			} else {
				if ((content.unwantedRecommendations || []).some(e => e.toLowerCase() === extensionIdLowerCase)) {
					this.notificationService.info(localize('AddToWorkspaceUnwantedRecommendations.alreadyExists', 'This extension is already present in workspace unwanted recommendations.'));
2654
					return Promise.resolve();
2655 2656
				}

S
Sandeep Somavarapu 已提交
2657
				return this.addExtensionToWorkspaceConfig(workspaceConfig, extensionId.id, shouldRecommend).then(() => {
2658 2659 2660 2661 2662 2663
					this.notificationService.prompt(Severity.Info,
						localize('AddToWorkspaceUnwantedRecommendations.success', 'The extension was successfully added to this workspace\'s unwanted recommendations.'),
						[{
							label: localize('viewChanges', "View Changes"),
							run: () => this.openWorkspaceConfigurationFile(workspaceConfig)
						}]);
2664 2665 2666 2667 2668 2669 2670 2671
				}, err => {
					this.notificationService.error(localize('AddToWorkspaceRecommendations.failure', 'Failed to write. {0}', err));
				});
			}
		});
	}
}

S
#66931  
Sandeep Somavarapu 已提交
2672 2673
export class StatusLabelAction extends Action implements IExtensionContainer {

S
Sandeep Somavarapu 已提交
2674
	private static readonly ENABLED_CLASS = `${ExtensionAction.TEXT_ACTION_CLASS} extension-status-label`;
S
#66931  
Sandeep Somavarapu 已提交
2675 2676
	private static readonly DISABLED_CLASS = `${StatusLabelAction.ENABLED_CLASS} hide`;

S
Sandeep Somavarapu 已提交
2677
	private initialStatus: ExtensionState | null = null;
S
#66931  
Sandeep Somavarapu 已提交
2678 2679 2680
	private status: ExtensionState | null = null;
	private enablementState: EnablementState | null = null;

S
Sandeep Somavarapu 已提交
2681 2682 2683
	private _extension: IExtension | null = null;
	get extension(): IExtension | null { return this._extension; }
	set extension(extension: IExtension | null) {
S
Sandeep Somavarapu 已提交
2684
		if (!(this._extension && extension && areSameExtensions(this._extension.identifier, extension.identifier))) {
S
#66931  
Sandeep Somavarapu 已提交
2685
			// Different extension. Reset
S
Sandeep Somavarapu 已提交
2686
			this.initialStatus = null;
S
#66931  
Sandeep Somavarapu 已提交
2687 2688 2689 2690 2691 2692 2693 2694
			this.status = null;
			this.enablementState = null;
		}
		this._extension = extension;
		this.update();
	}

	constructor(
2695 2696
		@IExtensionService private readonly extensionService: IExtensionService,
		@IExtensionManagementServerService private readonly extensionManagementServerService: IExtensionManagementServerService
S
#66931  
Sandeep Somavarapu 已提交
2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716
	) {
		super('extensions.action.statusLabel', '', StatusLabelAction.DISABLED_CLASS, false);
	}

	update(): void {
		this.computeLabel()
			.then(label => {
				this.label = label || '';
				this.class = label ? StatusLabelAction.ENABLED_CLASS : StatusLabelAction.DISABLED_CLASS;
			});
	}

	private async computeLabel(): Promise<string | null> {
		if (!this.extension) {
			return null;
		}

		const currentStatus = this.status;
		const currentEnablementState = this.enablementState;
		this.status = this.extension.state;
S
Sandeep Somavarapu 已提交
2717 2718 2719
		if (this.initialStatus === null) {
			this.initialStatus = this.status;
		}
S
#66931  
Sandeep Somavarapu 已提交
2720 2721 2722
		this.enablementState = this.extension.enablementState;

		const runningExtensions = await this.extensionService.getExtensions();
S
Sandeep Somavarapu 已提交
2723
		const canAddExtension = () => {
S
Sandeep Somavarapu 已提交
2724 2725 2726
			const runningExtension = runningExtensions.filter(e => areSameExtensions({ id: e.identifier.value, uuid: e.uuid }, this.extension!.identifier))[0];
			if (this.extension!.local) {
				if (runningExtension && this.extension!.version === runningExtension.version) {
S
Sandeep Somavarapu 已提交
2727 2728
					return true;
				}
S
Sandeep Somavarapu 已提交
2729
				return this.extensionService.canAddExtension(toExtensionDescription(this.extension!.local));
S
Sandeep Somavarapu 已提交
2730 2731 2732 2733
			}
			return false;
		};
		const canRemoveExtension = () => {
S
Sandeep Somavarapu 已提交
2734
			if (this.extension!.local) {
2735
				if (runningExtensions.every(e => !(areSameExtensions({ id: e.identifier.value, uuid: e.uuid }, this.extension!.identifier) && this.extension!.server === this.extensionManagementServerService.getExtensionManagementServer(toExtension(e))))) {
S
Sandeep Somavarapu 已提交
2736 2737
					return true;
				}
S
Sandeep Somavarapu 已提交
2738
				return this.extensionService.canRemoveExtension(toExtensionDescription(this.extension!.local));
S
Sandeep Somavarapu 已提交
2739 2740 2741
			}
			return false;
		};
S
#66931  
Sandeep Somavarapu 已提交
2742 2743 2744

		if (currentStatus !== null) {
			if (currentStatus === ExtensionState.Installing && this.status === ExtensionState.Installed) {
S
Sandeep Somavarapu 已提交
2745
				return canAddExtension() ? this.initialStatus === ExtensionState.Installed ? localize('updated', "Updated") : localize('installed', "Installed") : null;
S
#66931  
Sandeep Somavarapu 已提交
2746 2747
			}
			if (currentStatus === ExtensionState.Uninstalling && this.status === ExtensionState.Uninstalled) {
S
Sandeep Somavarapu 已提交
2748
				this.initialStatus = this.status;
S
#66931  
Sandeep Somavarapu 已提交
2749 2750 2751 2752 2753
				return canRemoveExtension() ? localize('uninstalled', "Uninstalled") : null;
			}
		}

		if (currentEnablementState !== null) {
2754 2755
			const currentlyEnabled = currentEnablementState === EnablementState.EnabledGlobally || currentEnablementState === EnablementState.EnabledWorkspace;
			const enabled = this.enablementState === EnablementState.EnabledGlobally || this.enablementState === EnablementState.EnabledWorkspace;
S
#66931  
Sandeep Somavarapu 已提交
2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768
			if (!currentlyEnabled && enabled) {
				return canAddExtension() ? localize('enabled', "Enabled") : null;
			}
			if (currentlyEnabled && !enabled) {
				return canRemoveExtension() ? localize('disabled', "Disabled") : null;
			}

		}

		return null;
	}

	run(): Promise<any> {
2769
		return Promise.resolve();
S
#66931  
Sandeep Somavarapu 已提交
2770 2771 2772 2773
	}

}

S
Sandeep Somavarapu 已提交
2774
export class MaliciousStatusLabelAction extends ExtensionAction {
J
Joao Moreno 已提交
2775

S
Sandeep Somavarapu 已提交
2776
	private static readonly Class = `${ExtensionAction.TEXT_ACTION_CLASS} malicious-status`;
J
Joao Moreno 已提交
2777 2778

	constructor(long: boolean) {
J
Joao Moreno 已提交
2779
		const tooltip = localize('malicious tooltip', "This extension was reported to be problematic.");
2780
		const label = long ? tooltip : localize({ key: 'malicious', comment: ['Refers to a malicious extension'] }, "Malicious");
J
Joao Moreno 已提交
2781
		super('extensions.install', label, '', false);
J
Joao Moreno 已提交
2782
		this.tooltip = localize('malicious tooltip', "This extension was reported to be problematic.");
J
Joao Moreno 已提交
2783 2784
	}

S
Sandeep Somavarapu 已提交
2785
	update(): void {
J
Joao Moreno 已提交
2786 2787 2788 2789 2790 2791 2792
		if (this.extension && this.extension.isMalicious) {
			this.class = `${MaliciousStatusLabelAction.Class} malicious`;
		} else {
			this.class = `${MaliciousStatusLabelAction.Class} not-malicious`;
		}
	}

S
Sandeep Somavarapu 已提交
2793
	run(): Promise<any> {
2794
		return Promise.resolve();
J
Joao Moreno 已提交
2795 2796 2797
	}
}

S
Sandeep Somavarapu 已提交
2798 2799
export class SyncIgnoredIconAction extends ExtensionAction {

S
Sandeep Somavarapu 已提交
2800
	private static readonly ENABLE_CLASS = `${ExtensionAction.ICON_ACTION_CLASS} codicon-sync-ignored`;
S
Sandeep Somavarapu 已提交
2801 2802 2803
	private static readonly DISABLE_CLASS = `${SyncIgnoredIconAction.ENABLE_CLASS} hide`;

	constructor(
2804 2805
		@IConfigurationService private readonly configurationService: IConfigurationService,
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
Sandeep Somavarapu 已提交
2806 2807
	) {
		super('extensions.syncignore', '', SyncIgnoredIconAction.DISABLE_CLASS, false);
S
Sandeep Somavarapu 已提交
2808
		this._register(Event.filter(this.configurationService.onDidChangeConfiguration, e => e.affectedKeys.includes('settingsSync.ignoredExtensions'))(() => this.update()));
S
Sandeep Somavarapu 已提交
2809 2810 2811 2812 2813
		this.update();
		this.tooltip = localize('syncingore.label', "This extension is ignored during sync.");
	}

	update(): void {
2814
		this.class = SyncIgnoredIconAction.DISABLE_CLASS;
2815 2816
		if (this.extension && this.extensionsWorkbenchService.isExtensionIgnoredToSync(this.extension)) {
			this.class = SyncIgnoredIconAction.ENABLE_CLASS;
2817
		}
S
Sandeep Somavarapu 已提交
2818 2819 2820 2821 2822 2823 2824
	}

	run(): Promise<any> {
		return Promise.resolve();
	}
}

S
Sandeep Somavarapu 已提交
2825
export class ExtensionToolTipAction extends ExtensionAction {
2826

S
Sandeep Somavarapu 已提交
2827
	private static readonly Class = `${ExtensionAction.TEXT_ACTION_CLASS} disable-status`;
2828 2829

	updateWhenCounterExtensionChanges: boolean = true;
2830
	private _runningExtensions: IExtensionDescription[] | null = null;
2831

2832 2833
	constructor(
		private readonly warningAction: SystemDisabledWarningAction,
S
Sandeep Somavarapu 已提交
2834
		private readonly reloadAction: ReloadAction,
S
rename  
Sandeep Somavarapu 已提交
2835
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService,
2836
		@IExtensionService private readonly extensionService: IExtensionService,
S
Sandeep Somavarapu 已提交
2837
		@IExtensionManagementServerService private readonly extensionManagementServerService: IExtensionManagementServerService
2838
	) {
S
Sandeep Somavarapu 已提交
2839
		super('extensions.tooltip', warningAction.tooltip, `${ExtensionToolTipAction.Class} hide`, false);
M
Matt Bierner 已提交
2840 2841
		this._register(warningAction.onDidChange(() => this.update(), this));
		this._register(this.extensionService.onDidChangeExtensions(this.updateRunningExtensions, this));
2842 2843 2844 2845 2846
		this.updateRunningExtensions();
	}

	private updateRunningExtensions(): void {
		this.extensionService.getExtensions().then(runningExtensions => { this._runningExtensions = runningExtensions; this.update(); });
2847 2848 2849
	}

	update(): void {
S
Sandeep Somavarapu 已提交
2850 2851 2852 2853
		this.label = this.getTooltip();
		this.class = ExtensionToolTipAction.Class;
		if (!this.label) {
			this.class = `${ExtensionToolTipAction.Class} hide`;
2854
		}
S
Sandeep Somavarapu 已提交
2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865
	}

	private getTooltip(): string {
		if (!this.extension) {
			return '';
		}
		if (this.reloadAction.enabled) {
			return this.reloadAction.tooltip;
		}
		if (this.warningAction.tooltip) {
			return this.warningAction.tooltip;
2866
		}
S
Sandeep Somavarapu 已提交
2867
		if (this.extension && this.extension.local && this.extension.state === ExtensionState.Installed && this._runningExtensions) {
S
Sandeep Somavarapu 已提交
2868
			const isRunning = this._runningExtensions.some(e => areSameExtensions({ id: e.identifier.value, uuid: e.uuid }, this.extension!.identifier));
2869
			const isEnabled = this.extensionEnablementService.isEnabled(this.extension.local);
S
Sandeep Somavarapu 已提交
2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891

			if (isEnabled && isRunning) {
				if (this.extensionManagementServerService.localExtensionManagementServer && this.extensionManagementServerService.remoteExtensionManagementServer) {
					if (this.extension.server === this.extensionManagementServerService.remoteExtensionManagementServer) {
						return localize('extension enabled on remote', "Extension is enabled on '{0}'", this.extension.server.label);
					}
				}
				if (this.extension.enablementState === EnablementState.EnabledGlobally) {
					return localize('globally enabled', "This extension is enabled globally.");
				}
				if (this.extension.enablementState === EnablementState.EnabledWorkspace) {
					return localize('workspace enabled', "This extension is enabled for this workspace by the user.");
				}
			}

			if (!isEnabled && !isRunning) {
				if (this.extension.enablementState === EnablementState.DisabledGlobally) {
					return localize('globally disabled', "This extension is disabled globally by the user.");
				}
				if (this.extension.enablementState === EnablementState.DisabledWorkspace) {
					return localize('workspace disabled', "This extension is disabled for this workspace by the user.");
				}
2892
			}
2893
		}
S
Sandeep Somavarapu 已提交
2894
		return '';
2895 2896 2897 2898 2899 2900 2901 2902 2903
	}

	run(): Promise<any> {
		return Promise.resolve(null);
	}
}

export class SystemDisabledWarningAction extends ExtensionAction {

S
Sandeep Somavarapu 已提交
2904
	private static readonly CLASS = `${ExtensionAction.ICON_ACTION_CLASS} system-disable`;
2905 2906
	private static readonly WARNING_CLASS = `${SystemDisabledWarningAction.CLASS} ${Codicon.warning.classNames}`;
	private static readonly INFO_CLASS = `${SystemDisabledWarningAction.CLASS} ${Codicon.info.classNames}`;
2907 2908

	updateWhenCounterExtensionChanges: boolean = true;
2909
	private _runningExtensions: IExtensionDescription[] | null = null;
2910

2911 2912 2913
	constructor(
		@IExtensionManagementServerService private readonly extensionManagementServerService: IExtensionManagementServerService,
		@ILabelService private readonly labelService: ILabelService,
2914
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
2915 2916 2917
		@IExtensionService private readonly extensionService: IExtensionService,
		@IProductService private readonly productService: IProductService,
		@IConfigurationService private readonly configurationService: IConfigurationService,
2918
	) {
2919
		super('extensions.install', '', `${SystemDisabledWarningAction.CLASS} hide`, false);
M
Matt Bierner 已提交
2920 2921
		this._register(this.labelService.onDidChangeFormatters(() => this.update(), this));
		this._register(this.extensionService.onDidChangeExtensions(this.updateRunningExtensions, this));
2922
		this.updateRunningExtensions();
2923 2924 2925
		this.update();
	}

2926 2927 2928 2929
	private updateRunningExtensions(): void {
		this.extensionService.getExtensions().then(runningExtensions => { this._runningExtensions = runningExtensions; this.update(); });
	}

2930
	update(): void {
2931
		this.class = `${SystemDisabledWarningAction.CLASS} hide`;
2932
		this.tooltip = '';
2933 2934 2935 2936 2937
		if (
			!this.extension ||
			!this.extension.local ||
			!this.extension.server ||
			!this._runningExtensions ||
2938
			this.extension.state !== ExtensionState.Installed
2939
		) {
2940 2941
			return;
		}
2942 2943 2944 2945 2946
		if (this.extensionManagementServerService.localExtensionManagementServer && this.extensionManagementServerService.remoteExtensionManagementServer) {
			if (isLanguagePackExtension(this.extension.local.manifest)) {
				if (!this.extensionsWorkbenchService.installed.some(e => areSameExtensions(e.identifier, this.extension!.identifier) && e.server !== this.extension!.server)) {
					this.class = `${SystemDisabledWarningAction.INFO_CLASS}`;
					this.tooltip = this.extension.server === this.extensionManagementServerService.localExtensionManagementServer
D
Daniel Imms 已提交
2947 2948
						? localize('Install language pack also in remote server', "Install the language pack extension on '{0}' to enable it there also.", this.extensionManagementServerService.remoteExtensionManagementServer.label)
						: localize('Install language pack also locally', "Install the language pack extension locally to enable it there also.");
2949 2950
				}
				return;
2951 2952
			}
		}
S
Sandeep Somavarapu 已提交
2953
		if (this.extension.enablementState === EnablementState.DisabledByExtensionKind) {
S
Sandeep Somavarapu 已提交
2954
			if (!this.extensionsWorkbenchService.installed.some(e => areSameExtensions(e.identifier, this.extension!.identifier) && e.server !== this.extension!.server)) {
S
Sandeep Somavarapu 已提交
2955
				const server = this.extensionManagementServerService.localExtensionManagementServer === this.extension.server ? this.extensionManagementServerService.remoteExtensionManagementServer : this.extensionManagementServerService.localExtensionManagementServer;
2956
				this.class = `${SystemDisabledWarningAction.WARNING_CLASS}`;
2957 2958 2959
				if (server) {
					this.tooltip = localize('Install in other server to enable', "Install the extension on '{0}' to enable.", server.label);
				} else {
S
Sandeep Somavarapu 已提交
2960
					this.tooltip = localize('disabled because of extension kind', "This extension has defined that it cannot run on the remote server");
2961
				}
S
Sandeep Somavarapu 已提交
2962 2963
				return;
			}
2964
		}
2965 2966
		if (this.extensionManagementServerService.localExtensionManagementServer && this.extensionManagementServerService.remoteExtensionManagementServer) {
			const runningExtension = this._runningExtensions.filter(e => areSameExtensions({ id: e.identifier.value, uuid: e.uuid }, this.extension!.identifier))[0];
2967
			const runningExtensionServer = runningExtension ? this.extensionManagementServerService.getExtensionManagementServer(toExtension(runningExtension)) : null;
2968 2969 2970 2971 2972 2973
			if (this.extension.server === this.extensionManagementServerService.localExtensionManagementServer && runningExtensionServer === this.extensionManagementServerService.remoteExtensionManagementServer) {
				if (prefersExecuteOnWorkspace(this.extension.local!.manifest, this.productService, this.configurationService)) {
					this.class = `${SystemDisabledWarningAction.INFO_CLASS}`;
					this.tooltip = localize('disabled locally', "Extension is enabled on '{0}' and disabled locally.", this.extensionManagementServerService.remoteExtensionManagementServer.label);
				}
				return;
2974
			}
2975 2976 2977 2978 2979 2980
			if (this.extension.server === this.extensionManagementServerService.remoteExtensionManagementServer && runningExtensionServer === this.extensionManagementServerService.localExtensionManagementServer) {
				if (prefersExecuteOnUI(this.extension.local!.manifest, this.productService, this.configurationService)) {
					this.class = `${SystemDisabledWarningAction.INFO_CLASS}`;
					this.tooltip = localize('disabled remotely', "Extension is enabled locally and disabled on '{0}'.", this.extensionManagementServerService.remoteExtensionManagementServer.label);
				}
				return;
2981
			}
2982 2983 2984 2985 2986 2987 2988 2989
		}
	}

	run(): Promise<any> {
		return Promise.resolve(null);
	}
}

2990 2991
export class DisableAllAction extends Action {

2992
	static readonly ID = 'workbench.extensions.action.disableAll';
2993
	static readonly LABEL = localize('disableAll', "Disable All Installed Extensions");
2994 2995 2996

	constructor(
		id: string = DisableAllAction.ID, label: string = DisableAllAction.LABEL,
2997
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
rename  
Sandeep Somavarapu 已提交
2998
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService
2999 3000 3001
	) {
		super(id, label);
		this.update();
M
Matt Bierner 已提交
3002
		this._register(this.extensionsWorkbenchService.onChange(() => this.update()));
3003 3004 3005
	}

	private update(): void {
3006
		this.enabled = this.extensionsWorkbenchService.local.some(e => e.type === ExtensionType.User && !!e.local && this.extensionEnablementService.isEnabled(e.local) && this.extensionEnablementService.canChangeEnablement(e.local));
3007 3008
	}

S
Sandeep Somavarapu 已提交
3009
	run(): Promise<any> {
3010
		return this.extensionsWorkbenchService.setEnablement(this.extensionsWorkbenchService.local.filter(e => e.type === ExtensionType.User), EnablementState.DisabledGlobally);
3011 3012 3013
	}
}

3014
export class DisableAllWorkspaceAction extends Action {
3015

3016
	static readonly ID = 'workbench.extensions.action.disableAllWorkspace';
3017
	static readonly LABEL = localize('disableAllWorkspace', "Disable All Installed Extensions for this Workspace");
3018 3019

	constructor(
3020
		id: string = DisableAllWorkspaceAction.ID, label: string = DisableAllWorkspaceAction.LABEL,
3021
		@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService,
3022
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
rename  
Sandeep Somavarapu 已提交
3023
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService
3024 3025 3026
	) {
		super(id, label);
		this.update();
M
Matt Bierner 已提交
3027 3028
		this._register(this.workspaceContextService.onDidChangeWorkbenchState(() => this.update(), this));
		this._register(this.extensionsWorkbenchService.onChange(() => this.update(), this));
3029 3030 3031
	}

	private update(): void {
3032
		this.enabled = this.workspaceContextService.getWorkbenchState() !== WorkbenchState.EMPTY && this.extensionsWorkbenchService.local.some(e => e.type === ExtensionType.User && !!e.local && this.extensionEnablementService.isEnabled(e.local) && this.extensionEnablementService.canChangeEnablement(e.local));
3033 3034
	}

S
Sandeep Somavarapu 已提交
3035
	run(): Promise<any> {
3036
		return this.extensionsWorkbenchService.setEnablement(this.extensionsWorkbenchService.local.filter(e => e.type === ExtensionType.User), EnablementState.DisabledWorkspace);
3037 3038 3039 3040 3041
	}
}

export class EnableAllAction extends Action {

3042
	static readonly ID = 'workbench.extensions.action.enableAll';
3043
	static readonly LABEL = localize('enableAll', "Enable All Extensions");
3044 3045 3046

	constructor(
		id: string = EnableAllAction.ID, label: string = EnableAllAction.LABEL,
3047
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
rename  
Sandeep Somavarapu 已提交
3048
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService
3049 3050 3051
	) {
		super(id, label);
		this.update();
M
Matt Bierner 已提交
3052
		this._register(this.extensionsWorkbenchService.onChange(() => this.update()));
3053 3054 3055
	}

	private update(): void {
3056
		this.enabled = this.extensionsWorkbenchService.local.some(e => !!e.local && this.extensionEnablementService.canChangeEnablement(e.local) && !this.extensionEnablementService.isEnabled(e.local));
3057 3058
	}

S
Sandeep Somavarapu 已提交
3059
	run(): Promise<any> {
3060
		return this.extensionsWorkbenchService.setEnablement(this.extensionsWorkbenchService.local, EnablementState.EnabledGlobally);
3061 3062 3063
	}
}

3064
export class EnableAllWorkspaceAction extends Action {
3065

3066
	static readonly ID = 'workbench.extensions.action.enableAllWorkspace';
3067
	static readonly LABEL = localize('enableAllWorkspace', "Enable All Extensions for this Workspace");
3068 3069

	constructor(
3070
		id: string = EnableAllWorkspaceAction.ID, label: string = EnableAllWorkspaceAction.LABEL,
3071 3072
		@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService,
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
rename  
Sandeep Somavarapu 已提交
3073
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService
3074 3075 3076
	) {
		super(id, label);
		this.update();
M
Matt Bierner 已提交
3077 3078
		this._register(this.extensionsWorkbenchService.onChange(() => this.update(), this));
		this._register(this.workspaceContextService.onDidChangeWorkbenchState(() => this.update(), this));
3079 3080 3081
	}

	private update(): void {
3082
		this.enabled = this.workspaceContextService.getWorkbenchState() !== WorkbenchState.EMPTY && this.extensionsWorkbenchService.local.some(e => !!e.local && this.extensionEnablementService.canChangeEnablement(e.local) && !this.extensionEnablementService.isEnabled(e.local));
3083 3084
	}

S
Sandeep Somavarapu 已提交
3085
	run(): Promise<any> {
3086
		return this.extensionsWorkbenchService.setEnablement(this.extensionsWorkbenchService.local, EnablementState.EnabledWorkspace);
3087
	}
3088 3089
}

J
Joao Moreno 已提交
3090 3091 3092
export class InstallVSIXAction extends Action {

	static readonly ID = 'workbench.extensions.action.installVSIX';
3093
	static readonly LABEL = localize('installVSIX', "Install from VSIX...");
J
Joao Moreno 已提交
3094 3095 3096 3097

	constructor(
		id = InstallVSIXAction.ID,
		label = InstallVSIXAction.LABEL,
3098 3099
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
		@INotificationService private readonly notificationService: INotificationService,
3100
		@IHostService private readonly hostService: IHostService,
3101
		@IFileDialogService private readonly fileDialogService: IFileDialogService,
S
Sandeep Somavarapu 已提交
3102 3103
		@IExtensionService private readonly extensionService: IExtensionService,
		@IInstantiationService private readonly instantiationService: IInstantiationService
J
Joao Moreno 已提交
3104
	) {
S
Sandeep Somavarapu 已提交
3105
		super(id, label, 'extension-action install-vsix', true);
J
Joao Moreno 已提交
3106 3107
	}

3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118
	async run(vsixPaths?: URI[]): Promise<void> {
		if (!vsixPaths) {
			vsixPaths = await this.fileDialogService.showOpenDialog({
				title: localize('installFromVSIX', "Install from VSIX"),
				filters: [{ name: 'VSIX Extensions', extensions: ['vsix'] }],
				canSelectFiles: true,
				openLabel: mnemonicButtonLabel(localize({ key: 'installButton', comment: ['&& denotes a mnemonic'] }, "&&Install"))
			});

			if (!vsixPaths) {
				return;
J
Joao Moreno 已提交
3119
			}
3120
		}
J
Joao Moreno 已提交
3121

3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141
		// Install extension(s), display notification(s), display @installed extensions
		await Promise.all(vsixPaths.map(async (vsix) => await this.extensionsWorkbenchService.install(vsix)))
			.then(async (extensions) => {
				for (const extension of extensions) {
					const requireReload = !(extension.local && this.extensionService.canAddExtension(toExtensionDescription(extension.local)));
					const message = requireReload ? localize('InstallVSIXAction.successReload', "Please reload Visual Studio Code to complete installing the extension {0}.", extension.displayName || extension.name)
						: localize('InstallVSIXAction.success', "Completed installing the extension {0}.", extension.displayName || extension.name);
					const actions = requireReload ? [{
						label: localize('InstallVSIXAction.reloadNow', "Reload Now"),
						run: () => this.hostService.reload()
					}] : [];
					this.notificationService.prompt(
						Severity.Info,
						message,
						actions,
						{ sticky: true }
					);
				}
				await this.instantiationService.createInstance(ShowInstalledExtensionsAction, ShowInstalledExtensionsAction.ID, ShowInstalledExtensionsAction.LABEL).run(true);
			});
J
Joao Moreno 已提交
3142 3143 3144 3145 3146 3147
	}
}

export class ReinstallAction extends Action {

	static readonly ID = 'workbench.extensions.action.reinstall';
3148
	static readonly LABEL = localize('reinstall', "Reinstall Extension...");
J
Joao Moreno 已提交
3149 3150 3151

	constructor(
		id: string = ReinstallAction.ID, label: string = ReinstallAction.LABEL,
3152 3153 3154
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
		@IQuickInputService private readonly quickInputService: IQuickInputService,
		@INotificationService private readonly notificationService: INotificationService,
3155
		@IHostService private readonly hostService: IHostService,
S
Sandeep Somavarapu 已提交
3156 3157
		@IInstantiationService private readonly instantiationService: IInstantiationService,
		@IExtensionService private readonly extensionService: IExtensionService
J
Joao Moreno 已提交
3158 3159 3160 3161 3162
	) {
		super(id, label);
	}

	get enabled(): boolean {
3163
		return this.extensionsWorkbenchService.local.filter(l => l.type === ExtensionType.User && l.local).length > 0;
J
Joao Moreno 已提交
3164 3165
	}

J
Johannes Rieken 已提交
3166
	run(): Promise<any> {
S
Sandeep Somavarapu 已提交
3167
		return this.quickInputService.pick(this.getEntries(), { placeHolder: localize('selectExtensionToReinstall', "Select Extension to Reinstall") })
C
Christof Marti 已提交
3168
			.then(pick => pick && this.reinstallExtension(pick.extension));
J
Joao Moreno 已提交
3169 3170
	}

J
Johannes Rieken 已提交
3171
	private getEntries(): Promise<(IQuickPickItem & { extension: IExtension })[]> {
J
Joao Moreno 已提交
3172 3173
		return this.extensionsWorkbenchService.queryLocal()
			.then(local => {
C
Christof Marti 已提交
3174
				const entries = local
3175
					.filter(extension => extension.type === ExtensionType.User)
J
Joao Moreno 已提交
3176
					.map(extension => {
C
Christof Marti 已提交
3177
						return {
S
Sandeep Somavarapu 已提交
3178
							id: extension.identifier.id,
J
Joao Moreno 已提交
3179
							label: extension.displayName,
S
Sandeep Somavarapu 已提交
3180
							description: extension.identifier.id,
C
Christof Marti 已提交
3181 3182
							extension,
						} as (IQuickPickItem & { extension: IExtension });
J
Joao Moreno 已提交
3183 3184 3185 3186 3187
					});
				return entries;
			});
	}

J
Johannes Rieken 已提交
3188
	private reinstallExtension(extension: IExtension): Promise<void> {
S
Sandeep Somavarapu 已提交
3189 3190
		return this.instantiationService.createInstance(ShowInstalledExtensionsAction, ShowInstalledExtensionsAction.ID, ShowInstalledExtensionsAction.LABEL).run()
			.then(() => {
3191
				return this.extensionsWorkbenchService.reinstall(extension)
S
Sandeep Somavarapu 已提交
3192 3193 3194 3195 3196 3197
					.then(extension => {
						const requireReload = !(extension.local && this.extensionService.canAddExtension(toExtensionDescription(extension.local)));
						const message = requireReload ? localize('ReinstallAction.successReload', "Please reload Visual Studio Code to complete reinstalling the extension {0}.", extension.identifier.id)
							: localize('ReinstallAction.success', "Reinstalling the extension {0} is completed.", extension.identifier.id);
						const actions = requireReload ? [{
							label: localize('InstallVSIXAction.reloadNow', "Reload Now"),
3198
							run: () => this.hostService.reload()
S
Sandeep Somavarapu 已提交
3199
						}] : [];
3200 3201
						this.notificationService.prompt(
							Severity.Info,
S
Sandeep Somavarapu 已提交
3202 3203
							message,
							actions,
3204 3205 3206 3207
							{ sticky: true }
						);
					}, error => this.notificationService.error(error));
			});
J
Joao Moreno 已提交
3208 3209 3210
	}
}

S
Sandeep Somavarapu 已提交
3211
export class InstallSpecificVersionOfExtensionAction extends Action {
3212

S
Sandeep Somavarapu 已提交
3213
	static readonly ID = 'workbench.extensions.action.install.specificVersion';
3214
	static readonly LABEL = localize('install previous version', "Install Specific Version of Extension...");
3215 3216

	constructor(
S
Sandeep Somavarapu 已提交
3217
		id: string = InstallSpecificVersionOfExtensionAction.ID, label: string = InstallSpecificVersionOfExtensionAction.LABEL,
3218 3219 3220 3221
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
		@IExtensionGalleryService private readonly extensionGalleryService: IExtensionGalleryService,
		@IQuickInputService private readonly quickInputService: IQuickInputService,
		@INotificationService private readonly notificationService: INotificationService,
3222
		@IHostService private readonly hostService: IHostService,
S
Sandeep Somavarapu 已提交
3223
		@IInstantiationService private readonly instantiationService: IInstantiationService,
3224
		@IExtensionService private readonly extensionService: IExtensionService,
S
rename  
Sandeep Somavarapu 已提交
3225
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService,
3226 3227 3228 3229 3230
	) {
		super(id, label);
	}

	get enabled(): boolean {
S
Sandeep Somavarapu 已提交
3231
		return this.extensionsWorkbenchService.local.some(l => this.isEnabled(l));
3232 3233
	}

S
Sandeep Somavarapu 已提交
3234 3235 3236
	async run(): Promise<any> {
		const extensionPick = await this.quickInputService.pick(this.getExtensionEntries(), { placeHolder: localize('selectExtension', "Select Extension"), matchOnDetail: true });
		if (extensionPick && extensionPick.extension) {
3237
			const versionPick = await this.quickInputService.pick(extensionPick.versions.map(v => ({ id: v.version, label: v.version, description: `${getRelativeDateLabel(new Date(Date.parse(v.date)))}${v.version === extensionPick.extension.version ? ` (${localize('current', "Current")})` : ''}` })), { placeHolder: localize('selectVersion', "Select Version to Install"), matchOnDetail: true });
S
Sandeep Somavarapu 已提交
3238 3239
			if (versionPick) {
				if (extensionPick.extension.version !== versionPick.id) {
3240
					await this.install(extensionPick.extension, versionPick.id);
S
Sandeep Somavarapu 已提交
3241 3242
				}
			}
S
Sandeep Somavarapu 已提交
3243 3244 3245 3246
		}
	}

	private isEnabled(extension: IExtension): boolean {
3247
		return !!extension.gallery && !!extension.local && this.extensionEnablementService.isEnabled(extension.local);
3248 3249
	}

S
Sandeep Somavarapu 已提交
3250
	private async getExtensionEntries(): Promise<(IQuickPickItem & { extension: IExtension, versions: IGalleryExtensionVersion[] })[]> {
3251
		const installed = await this.extensionsWorkbenchService.queryLocal();
3252
		const versionsPromises: Promise<{ extension: IExtension, versions: IGalleryExtensionVersion[] } | null>[] = [];
3253
		for (const extension of installed) {
S
Sandeep Somavarapu 已提交
3254
			if (this.isEnabled(extension)) {
3255
				versionsPromises.push(this.extensionGalleryService.getAllVersions(extension.gallery!, true)
S
Sandeep Somavarapu 已提交
3256
					.then(versions => (versions.length ? { extension, versions } : null)));
3257 3258 3259
			}
		}

S
Sandeep Somavarapu 已提交
3260
		const extensions = await Promise.all(versionsPromises);
M
Matt Bierner 已提交
3261
		return coalesce(extensions)
3262
			.sort((e1, e2) => e1.extension.displayName.localeCompare(e2.extension.displayName))
S
Sandeep Somavarapu 已提交
3263
			.map(({ extension, versions }) => {
3264
				return {
S
Sandeep Somavarapu 已提交
3265 3266 3267
					id: extension.identifier.id,
					label: extension.displayName || extension.identifier.id,
					description: extension.identifier.id,
3268
					extension,
S
Sandeep Somavarapu 已提交
3269 3270
					versions
				} as (IQuickPickItem & { extension: IExtension, versions: IGalleryExtensionVersion[] });
3271 3272 3273
			});
	}

J
Johannes Rieken 已提交
3274
	private install(extension: IExtension, version: string): Promise<void> {
S
Sandeep Somavarapu 已提交
3275 3276
		return this.instantiationService.createInstance(ShowInstalledExtensionsAction, ShowInstalledExtensionsAction.ID, ShowInstalledExtensionsAction.LABEL).run()
			.then(() => {
3277
				return this.extensionsWorkbenchService.installVersion(extension, version)
S
Sandeep Somavarapu 已提交
3278 3279 3280 3281 3282 3283
					.then(extension => {
						const requireReload = !(extension.local && this.extensionService.canAddExtension(toExtensionDescription(extension.local)));
						const message = requireReload ? localize('InstallAnotherVersionExtensionAction.successReload', "Please reload Visual Studio Code to complete installing the extension {0}.", extension.identifier.id)
							: localize('InstallAnotherVersionExtensionAction.success', "Installing the extension {0} is completed.", extension.identifier.id);
						const actions = requireReload ? [{
							label: localize('InstallAnotherVersionExtensionAction.reloadNow', "Reload Now"),
3284
							run: () => this.hostService.reload()
S
Sandeep Somavarapu 已提交
3285
						}] : [];
3286 3287
						this.notificationService.prompt(
							Severity.Info,
S
Sandeep Somavarapu 已提交
3288 3289
							message,
							actions,
3290 3291 3292 3293
							{ sticky: true }
						);
					}, error => this.notificationService.error(error));
			});
J
Joao Moreno 已提交
3294 3295 3296
	}
}

3297 3298 3299 3300
interface IExtensionPickItem extends IQuickPickItem {
	extension?: IExtension;
}

3301
export class InstallLocalExtensionsInRemoteAction extends Action {
3302

3303 3304
	private extensions: IExtension[] | undefined = undefined;

3305 3306 3307 3308 3309 3310
	constructor(
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
		@IExtensionManagementServerService private readonly extensionManagementServerService: IExtensionManagementServerService,
		@IExtensionGalleryService private readonly extensionGalleryService: IExtensionGalleryService,
		@IQuickInputService private readonly quickInputService: IQuickInputService,
		@INotificationService private readonly notificationService: INotificationService,
3311
		@IHostService private readonly hostService: IHostService,
3312 3313
		@IProgressService private readonly progressService: IProgressService,
		@IInstantiationService private readonly instantiationService: IInstantiationService
3314
	) {
3315
		super('workbench.extensions.actions.installLocalExtensionsInRemote');
3316
		this.update();
3317 3318 3319 3320 3321 3322
		this.extensionsWorkbenchService.queryLocal().then(() => this.updateExtensions());
		this._register(this.extensionsWorkbenchService.onChange(() => {
			if (this.extensions) {
				this.updateExtensions();
			}
		}));
3323 3324 3325
	}

	get label(): string {
S
Sandeep Somavarapu 已提交
3326
		if (this.extensionManagementServerService.remoteExtensionManagementServer) {
3327
			return localize('select and install local extensions', "Install Local Extensions in '{0}'...", this.extensionManagementServerService.remoteExtensionManagementServer.label);
S
Sandeep Somavarapu 已提交
3328 3329
		}
		return '';
3330 3331
	}

3332 3333 3334 3335 3336
	private updateExtensions(): void {
		this.extensions = this.extensionsWorkbenchService.local;
		this.update();
	}

3337
	private update(): void {
3338
		this.enabled = !!this.extensions && this.getExtensionsToInstall(this.extensions).length > 0;
S
Sandeep Somavarapu 已提交
3339
		this.tooltip = this.label;
3340 3341
	}

3342
	async run(): Promise<void> {
3343
		return this.selectAndInstallLocalExtensions();
3344 3345 3346 3347 3348 3349 3350 3351 3352
	}

	private async queryExtensionsToInstall(): Promise<IExtension[]> {
		const local = await this.extensionsWorkbenchService.queryLocal();
		return this.getExtensionsToInstall(local);
	}

	private getExtensionsToInstall(local: IExtension[]): IExtension[] {
		return local.filter(extension => {
S
Sandeep Somavarapu 已提交
3353
			const action = this.instantiationService.createInstance(RemoteInstallAction, true);
3354 3355 3356
			action.extension = extension;
			return action.enabled;
		});
3357 3358
	}

3359
	private async selectAndInstallLocalExtensions(): Promise<void> {
3360 3361 3362 3363 3364 3365 3366 3367 3368
		const quickPick = this.quickInputService.createQuickPick<IExtensionPickItem>();
		quickPick.busy = true;
		const disposable = quickPick.onDidAccept(() => {
			disposable.dispose();
			quickPick.hide();
			quickPick.dispose();
			this.onDidAccept(quickPick.selectedItems);
		});
		quickPick.show();
3369
		const localExtensionsToInstall = await this.queryExtensionsToInstall();
3370 3371
		quickPick.busy = false;
		if (localExtensionsToInstall.length) {
3372
			quickPick.title = localize('install local extensions title', "Install Local Extensions in '{0}'", this.extensionManagementServerService.remoteExtensionManagementServer!.label);
3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383
			quickPick.placeholder = localize('select extensions to install', "Select extensions to install");
			quickPick.canSelectMany = true;
			localExtensionsToInstall.sort((e1, e2) => e1.displayName.localeCompare(e2.displayName));
			quickPick.items = localExtensionsToInstall.map<IExtensionPickItem>(extension => ({ extension, label: extension.displayName, description: extension.version }));
		} else {
			quickPick.hide();
			quickPick.dispose();
			this.notificationService.notify({
				severity: Severity.Info,
				message: localize('no local extensions', "There are no extensions to install.")
			});
3384 3385 3386
		}
	}

3387 3388 3389
	private onDidAccept(selectedItems: ReadonlyArray<IExtensionPickItem>): void {
		if (selectedItems.length) {
			const localExtensionsToInstall = selectedItems.filter(r => !!r.extension).map(r => r.extension!);
3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420
			if (localExtensionsToInstall.length) {
				this.progressService.withProgress(
					{
						location: ProgressLocation.Notification,
						title: localize('installing extensions', "Installing Extensions...")
					},
					() => this.installLocalExtensions(localExtensionsToInstall));
			}
		}
	}

	private async installLocalExtensions(localExtensionsToInstall: IExtension[]): Promise<void> {
		const galleryExtensions: IGalleryExtension[] = [];
		const vsixs: URI[] = [];
		await Promise.all(localExtensionsToInstall.map(async extension => {
			if (this.extensionGalleryService.isEnabled()) {
				const gallery = await this.extensionGalleryService.getCompatibleExtension(extension.identifier, extension.version);
				if (gallery) {
					galleryExtensions.push(gallery);
					return;
				}
			}
			const vsix = await this.extensionManagementServerService.localExtensionManagementServer!.extensionManagementService.zip(extension.local!);
			vsixs.push(vsix);
		}));

		await Promise.all(galleryExtensions.map(gallery => this.extensionManagementServerService.remoteExtensionManagementServer!.extensionManagementService.installFromGallery(gallery)));
		await Promise.all(vsixs.map(vsix => this.extensionManagementServerService.remoteExtensionManagementServer!.extensionManagementService.install(vsix)));

		this.notificationService.notify({
			severity: Severity.Info,
3421
			message: localize('finished installing', "Successfully installed extensions in {0}. Please reload the window to enable them.", this.extensionManagementServerService.remoteExtensionManagementServer!.label),
3422
			actions: {
S
Sandeep Somavarapu 已提交
3423
				primary: [new Action('realod', localize('reload', "Reload Window"), '', true,
3424
					() => this.hostService.reload())]
3425 3426 3427 3428 3429
			}
		});
	}
}

S
Sandeep Somavarapu 已提交
3430
CommandsRegistry.registerCommand('workbench.extensions.action.showExtensionsForLanguage', function (accessor: ServicesAccessor, fileExtension: string) {
3431 3432 3433
	const viewletService = accessor.get(IViewletService);

	return viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
3434
		.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
3435 3436 3437 3438 3439
		.then(viewlet => {
			viewlet.search(`ext:${fileExtension.replace(/^\./, '')}`);
			viewlet.focus();
		});
});
B
Benjamin Pasero 已提交
3440

3441
CommandsRegistry.registerCommand('workbench.extensions.action.showExtensionsWithIds', function (accessor: ServicesAccessor, extensionIds: string[]) {
3442 3443 3444
	const viewletService = accessor.get(IViewletService);

	return viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
3445
		.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
3446
		.then(viewlet => {
3447 3448 3449 3450
			const query = extensionIds
				.map(id => `@id:${id}`)
				.join(' ');
			viewlet.search(query);
3451 3452 3453 3454
			viewlet.focus();
		});
});

B
Benjamin Pasero 已提交
3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472
export const extensionButtonProminentBackground = registerColor('extensionButton.prominentBackground', {
	dark: '#327e36',
	light: '#327e36',
	hc: null
}, localize('extensionButtonProminentBackground', "Button background color for actions extension that stand out (e.g. install button)."));

export const extensionButtonProminentForeground = registerColor('extensionButton.prominentForeground', {
	dark: Color.white,
	light: Color.white,
	hc: null
}, localize('extensionButtonProminentForeground', "Button foreground color for actions extension that stand out (e.g. install button)."));

export const extensionButtonProminentHoverBackground = registerColor('extensionButton.prominentHoverBackground', {
	dark: '#28632b',
	light: '#28632b',
	hc: null
}, localize('extensionButtonProminentHoverBackground', "Button background hover color for actions extension that stand out (e.g. install button)."));

M
Martin Aeschlimann 已提交
3473
registerThemingParticipant((theme: IColorTheme, collector: ICssStyleCollector) => {
B
Benjamin Pasero 已提交
3474 3475
	const foregroundColor = theme.getColor(foreground);
	if (foregroundColor) {
3476
		collector.addRule(`.extension-list-item .monaco-action-bar .action-item .action-label.extension-action.built-in-status { border-color: ${foregroundColor}; }`);
3477
		collector.addRule(`.extension-editor .monaco-action-bar .action-item .action-label.extension-action.built-in-status { border-color: ${foregroundColor}; }`);
B
Benjamin Pasero 已提交
3478 3479
	}

B
Benjamin Pasero 已提交
3480 3481
	const buttonBackgroundColor = theme.getColor(buttonBackground);
	if (buttonBackgroundColor) {
S
Sandeep Somavarapu 已提交
3482 3483
		collector.addRule(`.extension-list-item .monaco-action-bar .action-item .action-label.extension-action.label { background-color: ${buttonBackgroundColor}; }`);
		collector.addRule(`.extension-editor .monaco-action-bar .action-item .action-label.extension-action.label { background-color: ${buttonBackgroundColor}; }`);
B
Benjamin Pasero 已提交
3484 3485 3486 3487
	}

	const buttonForegroundColor = theme.getColor(buttonForeground);
	if (buttonForegroundColor) {
S
Sandeep Somavarapu 已提交
3488 3489
		collector.addRule(`.extension-list-item .monaco-action-bar .action-item .action-label.extension-action.label { color: ${buttonForegroundColor}; }`);
		collector.addRule(`.extension-editor .monaco-action-bar .action-item .action-label.extension-action.label { color: ${buttonForegroundColor}; }`);
B
Benjamin Pasero 已提交
3490 3491 3492 3493
	}

	const buttonHoverBackgroundColor = theme.getColor(buttonHoverBackground);
	if (buttonHoverBackgroundColor) {
S
Sandeep Somavarapu 已提交
3494 3495
		collector.addRule(`.extension-list-item .monaco-action-bar .action-item:hover .action-label.extension-action.label { background-color: ${buttonHoverBackgroundColor}; }`);
		collector.addRule(`.extension-editor .monaco-action-bar .action-item:hover .action-label.extension-action.label { background-color: ${buttonHoverBackgroundColor}; }`);
B
Benjamin Pasero 已提交
3496 3497 3498 3499
	}

	const extensionButtonProminentBackgroundColor = theme.getColor(extensionButtonProminentBackground);
	if (extensionButtonProminentBackground) {
S
Sandeep Somavarapu 已提交
3500 3501
		collector.addRule(`.extension-list-item .monaco-action-bar .action-item .action-label.extension-action.label.prominent { background-color: ${extensionButtonProminentBackgroundColor}; }`);
		collector.addRule(`.extension-editor .monaco-action-bar .action-item .action-label.extension-action.label.prominent { background-color: ${extensionButtonProminentBackgroundColor}; }`);
B
Benjamin Pasero 已提交
3502 3503 3504 3505
	}

	const extensionButtonProminentForegroundColor = theme.getColor(extensionButtonProminentForeground);
	if (extensionButtonProminentForeground) {
S
Sandeep Somavarapu 已提交
3506 3507
		collector.addRule(`.extension-list-item .monaco-action-bar .action-item .action-label.extension-action.label.prominent { color: ${extensionButtonProminentForegroundColor}; }`);
		collector.addRule(`.extension-editor .monaco-action-bar .action-item .action-label.extension-action.label.prominent { color: ${extensionButtonProminentForegroundColor}; }`);
B
Benjamin Pasero 已提交
3508 3509 3510 3511
	}

	const extensionButtonProminentHoverBackgroundColor = theme.getColor(extensionButtonProminentHoverBackground);
	if (extensionButtonProminentHoverBackground) {
S
Sandeep Somavarapu 已提交
3512 3513 3514 3515 3516 3517 3518 3519
		collector.addRule(`.extension-list-item .monaco-action-bar .action-item:hover .action-label.extension-action.label.prominent { background-color: ${extensionButtonProminentHoverBackgroundColor}; }`);
		collector.addRule(`.extension-editor .monaco-action-bar .action-item:hover .action-label.extension-action.label.prominent { background-color: ${extensionButtonProminentHoverBackgroundColor}; }`);
	}

	const contrastBorderColor = theme.getColor(contrastBorder);
	if (contrastBorderColor) {
		collector.addRule(`.extension-list-item .monaco-action-bar .action-item .action-label.extension-action { border: 1px solid ${contrastBorderColor}; }`);
		collector.addRule(`.extension-editor .monaco-action-bar .action-item .action-label.extension-action { border: 1px solid ${contrastBorderColor}; }`);
B
Benjamin Pasero 已提交
3520
	}
A
Alex Dima 已提交
3521
});