extensionsActions.ts 135.7 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';
S
Sandeep Somavarapu 已提交
14
import { dispose } from 'vs/base/common/lifecycle';
15
import { IExtension, ExtensionState, IExtensionsWorkbenchService, VIEWLET_ID, IExtensionsViewPaneContainer, AutoUpdateConfigurationKey, IExtensionContainer, TOGGLE_IGNORE_EXTENSION_ACTION_ID, INSTALL_EXTENSION_FROM_VSIX_COMMAND_ID } from 'vs/workbench/contrib/extensions/common/extensions';
16
import { ExtensionsConfigurationInitialContent } from 'vs/workbench/contrib/extensions/common/extensionsFileTemplate';
S
Sandeep Somavarapu 已提交
17
import { IGalleryExtension, IExtensionGalleryService, INSTALL_ERROR_MALICIOUS, INSTALL_ERROR_INCOMPATIBLE, IGalleryExtensionVersion, ILocalExtension, INSTALL_ERROR_NOT_SUPPORTED, InstallOptions, InstallOperation } from 'vs/platform/extensionManagement/common/extensionManagement';
18
import { IWorkbenchExtensionEnablementService, EnablementState, IExtensionManagementServerService, IExtensionManagementServer } from 'vs/workbench/services/extensionManagement/common/extensionManagement';
S
Sandeep Somavarapu 已提交
19
import { ExtensionRecommendationReason, IExtensionIgnoredRecommendationsService, IExtensionRecommendationsService } from 'vs/workbench/services/extensionRecommendations/common/extensionRecommendations';
20
import { areSameExtensions } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
21
import { ExtensionType, ExtensionIdentifier, IExtensionDescription, IExtensionManifest, isLanguagePackExtension } from 'vs/platform/extensions/common/extensions';
22
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
B
Benjamin Pasero 已提交
23
import { ShowViewletAction } from 'vs/workbench/browser/viewlet';
B
Benjamin Pasero 已提交
24
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
25
import { Query } from 'vs/workbench/contrib/extensions/common/extensionQuery';
B
Benjamin Pasero 已提交
26
import { IFileService, IFileContent } from 'vs/platform/files/common/files';
S
Sandeep Somavarapu 已提交
27
import { IWorkspaceContextService, WorkbenchState, IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
28
import { IHostService } from 'vs/workbench/services/host/browser/host';
29
import { IExtensionService, toExtension, toExtensionDescription } from 'vs/workbench/services/extensions/common/extensions';
30
import { URI } from 'vs/base/common/uri';
S
Sandeep Somavarapu 已提交
31
import { CommandsRegistry, ICommandService } from 'vs/platform/commands/common/commands';
32
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
M
Martin Aeschlimann 已提交
33
import { registerThemingParticipant, IColorTheme, ICssStyleCollector } from 'vs/platform/theme/common/themeService';
34 35
import { buttonBackground, buttonForeground, buttonHoverBackground, contrastBorder, registerColor, foreground } from 'vs/platform/theme/common/colorRegistry';
import { Color } from 'vs/base/common/color';
36 37 38
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';
S
Sandeep Somavarapu 已提交
39 40
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { MenuId, IMenuService } from 'vs/platform/actions/common/actions';
I
isidor 已提交
41
import { PICK_WORKSPACE_FOLDER_COMMAND_ID } from 'vs/workbench/browser/actions/workspaceCommands';
S
Sandeep Somavarapu 已提交
42
import { INotificationService, IPromptChoice, Severity } from 'vs/platform/notification/common/notification';
J
Joao Moreno 已提交
43 44
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { mnemonicButtonLabel } from 'vs/base/common/labels';
45
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
46
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
47
import { IQuickPickItem, IQuickInputService, IQuickPickSeparator } from 'vs/platform/quickinput/common/quickInput';
48
import { CancellationToken } from 'vs/base/common/cancellation';
49
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
50
import { alert } from 'vs/base/browser/ui/aria/aria';
M
Matt Bierner 已提交
51
import { coalesce } from 'vs/base/common/arrays';
52
import { IWorkbenchThemeService, IWorkbenchTheme, IWorkbenchColorTheme, IWorkbenchFileIconTheme, IWorkbenchProductIconTheme } from 'vs/workbench/services/themes/common/workbenchThemeService';
53
import { ILabelService } from 'vs/platform/label/common/label';
54
import { prefersExecuteOnUI, prefersExecuteOnWorkspace, canExecuteOnUI, canExecuteOnWorkspace, prefersExecuteOnWeb } from 'vs/workbench/services/extensions/common/extensionsUtil';
55
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
56
import { IProductService } from 'vs/platform/product/common/productService';
S
Sandeep Somavarapu 已提交
57
import { IFileDialogService, IDialogService } from 'vs/platform/dialogs/common/dialogs';
58
import { IProgressService, ProgressLocation } from 'vs/platform/progress/common/progress';
59
import { Codicon } from 'vs/base/common/codicons';
S
Sandeep Somavarapu 已提交
60
import { IViewsService } from 'vs/workbench/common/views';
61
import { IActionViewItemOptions, ActionViewItem } from 'vs/base/browser/ui/actionbar/actionViewItems';
S
Sandeep Somavarapu 已提交
62
import { EXTENSIONS_CONFIG, IExtensionsConfigContent } from 'vs/workbench/services/extensionRecommendations/common/workspaceExtensionsConfig';
S
Sandeep Somavarapu 已提交
63
import { getErrorMessage, isPromiseCanceledError } from 'vs/base/common/errors';
64 65 66
import { IUserDataAutoSyncEnablementService, IUserDataSyncResourceEnablementService, SyncResource } from 'vs/platform/userDataSync/common/userDataSync';
import { ActionWithDropdownActionViewItem, IActionWithDropdownActionViewItemOptions } from 'vs/base/browser/ui/dropdown/dropdownActionViewItem';
import { IContextMenuProvider } from 'vs/base/browser/contextmenu';
S
Sandeep Somavarapu 已提交
67 68
import { ILogService } from 'vs/platform/log/common/log';
import * as Constants from 'vs/workbench/contrib/logs/common/logConstants';
69

70 71 72 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
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 已提交
104 105 106 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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
class PromptExtensionInstallFailureAction extends Action {

	constructor(
		private readonly extension: IExtension,
		private readonly installOperation: InstallOperation,
		private readonly error: Error,
		@IProductService private readonly productService: IProductService,
		@IOpenerService private readonly openerService: IOpenerService,
		@INotificationService private readonly notificationService: INotificationService,
		@IDialogService private readonly dialogService: IDialogService,
		@IInstantiationService private readonly instantiationService: IInstantiationService,
		@ILogService private readonly logService: ILogService,
	) {
		super('extension.promptExtensionInstallFailure');
	}

	async run(): Promise<void> {
		if (isPromiseCanceledError(this.error)) {
			return;
		}

		this.logService.error(this.error);
		const operationMessage = this.installOperation === InstallOperation.Update ? localize('update operation', "Error while updating '{0}' extension.", this.extension.displayName || this.extension.identifier.id)
			: localize('install operation', "Error while installing '{0}' extension.", this.extension.displayName || this.extension.identifier.id);

		if ([INSTALL_ERROR_INCOMPATIBLE, INSTALL_ERROR_MALICIOUS, INSTALL_ERROR_NOT_SUPPORTED].includes(this.error.name)) {
			await this.dialogService.show(Severity.Error, `${operationMessage}\n${getErrorMessage(this.error)}`, []);
			return;
		}

		const promptChoices: IPromptChoice[] = [];
		if (this.extension.gallery && this.productService.extensionsGallery) {
			promptChoices.push({
				label: localize('download', "Try Downloading Manually..."),
				run: () => this.openerService.open(URI.parse(`${this.productService.extensionsGallery!.serviceUrl}/publishers/${this.extension.publisher}/vsextensions/${this.extension.name}/${this.extension.version}/vspackage`)).then(() => {
					this.notificationService.prompt(
						Severity.Info,
						localize('install vsix', 'Once downloaded, please manually install the downloaded VSIX of \'{0}\'.', this.extension.identifier.id),
						[{
							label: InstallVSIXAction.LABEL,
							run: () => {
								const action = this.instantiationService.createInstance(InstallVSIXAction, InstallVSIXAction.ID, InstallVSIXAction.LABEL);
								action.run();
								action.dispose();
							}
						}]
					);
				})
			});
		}
		const checkLogsMessage = localize('check logs', "Please check [logs]({0}) for more details.", `command:${Constants.showWindowLogActionId}`);
		this.notificationService.prompt(Severity.Error, `${operationMessage} ${checkLogsMessage}`, promptChoices);
	}
}

S
Sandeep Somavarapu 已提交
159
export abstract class ExtensionAction extends Action implements IExtensionContainer {
S
Sandeep Somavarapu 已提交
160 161 162 163
	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 已提交
164 165 166
	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 已提交
167
	abstract update(): void;
168
}
169

S
Sandeep Somavarapu 已提交
170
export class ActionWithDropDownAction extends ExtensionAction {
171

172
	private action: IAction | undefined;
173

174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
	private _menuActions: IAction[] = [];
	get menuActions(): IAction[] { return [...this._menuActions]; }

	set extension(extension: IExtension | null) {
		this.actions.forEach(a => a.extension = extension);
		super.extension = extension;
	}

	constructor(
		id: string, label: string,
		protected readonly actions: ExtensionAction[],
	) {
		super(id, label);
		this.update();
		this._register(Event.any(...actions.map(a => a.onDidChange))(() => this.update(true)));
	}

	update(donotUpdateActions?: boolean): void {
		if (!donotUpdateActions) {
			this.actions.forEach(a => a.update());
		}

		const enabledActions = this.actions.filter(a => a.enabled);
		this.action = enabledActions[0];
		this._menuActions = enabledActions.slice(1);

		this.enabled = !!this.action;
		if (this.action) {
			this.label = this.action.label;
			this.tooltip = this.action.tooltip;
		}

		let clazz = (this.action || this.actions[0])?.class || '';
		clazz = clazz ? `${clazz} action-dropdown` : 'action-dropdown';
		if (this._menuActions.length === 0) {
			clazz += ' action-dropdown';
		}
		this.class = clazz;
	}
213

214 215 216 217 218 219 220 221 222 223 224
	run(): Promise<void> {
		const enabledActions = this.actions.filter(a => a.enabled);
		return enabledActions[0].run();
	}
}

export abstract class AbstractInstallAction extends ExtensionAction {

	static readonly Class = `${ExtensionAction.LABEL_ACTION_CLASS} prominent install`;

	protected _manifest: IExtensionManifest | null = null;
225 226 227 228 229
	set manifest(manifest: IExtensionManifest) {
		this._manifest = manifest;
		this.updateLabel();
	}

230
	constructor(
231
		id: string, label: string, cssClass: string,
232 233
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
		@IInstantiationService private readonly instantiationService: IInstantiationService,
S
Sandeep Somavarapu 已提交
234
		@IExtensionService private readonly runtimeExtensionService: IExtensionService,
235
		@IWorkbenchThemeService private readonly workbenchThemeService: IWorkbenchThemeService,
236
		@ILabelService private readonly labelService: ILabelService,
237
	) {
238
		super(id, label, cssClass, false);
239
		this.update();
M
Matt Bierner 已提交
240
		this._register(this.labelService.onDidChangeFormatters(() => this.updateLabel(), this));
241 242
	}

S
Sandeep Somavarapu 已提交
243
	update(): void {
S
Sandeep Somavarapu 已提交
244
		this.enabled = false;
245
		if (this.extension && !this.extension.isBuiltin) {
S
Sandeep Somavarapu 已提交
246 247 248
			if (this.extension.state === ExtensionState.Uninstalled && this.extensionsWorkbenchService.canInstall(this.extension)) {
				this.enabled = true;
				this.updateLabel();
249
			}
250 251 252
		}
	}

S
Sandeep Somavarapu 已提交
253
	async run(): Promise<any> {
S
Sandeep Somavarapu 已提交
254 255 256
		if (!this.extension) {
			return;
		}
257
		this.extensionsWorkbenchService.open(this.extension);
J
Joao Moreno 已提交
258

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

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

S
Sandeep Somavarapu 已提交
263 264
		if (extension?.local) {
			alert(localize('installExtensionComplete', "Installing extension {0} is completed.", this.extension.displayName));
S
Sandeep Somavarapu 已提交
265
			const runningExtension = await this.getRunningExtension(extension.local);
S
Sandeep Somavarapu 已提交
266
			if (runningExtension && !(runningExtension.activationEvents && runningExtension.activationEvents.some(activationEent => activationEent.startsWith('onLanguage')))) {
267 268 269 270 271 272 273 274 275
				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 已提交
276 277
				}
			}
S
Sandeep Somavarapu 已提交
278 279
		}

J
Joao Moreno 已提交
280 281
	}

S
Sandeep Somavarapu 已提交
282 283 284 285 286 287 288
	private async install(extension: IExtension): Promise<IExtension | undefined> {
		try {
			return await this.extensionsWorkbenchService.install(extension, this.getInstallOptions());
		} catch (error) {
			await this.instantiationService.createInstance(PromptExtensionInstallFailureAction, extension, InstallOperation.Install, error).run();
			return undefined;
		}
S
Sandeep Somavarapu 已提交
289
	}
J
Joao Moreno 已提交
290

S
Sandeep Somavarapu 已提交
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
	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;
308
	}
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328

	protected abstract updateLabel(): void;
	protected abstract getInstallOptions(): InstallOptions;
}

export class InstallAction extends AbstractInstallAction {

	constructor(
		@IExtensionsWorkbenchService extensionsWorkbenchService: IExtensionsWorkbenchService,
		@IInstantiationService instantiationService: IInstantiationService,
		@IExtensionService runtimeExtensionService: IExtensionService,
		@IWorkbenchThemeService workbenchThemeService: IWorkbenchThemeService,
		@ILabelService labelService: ILabelService,
		@IConfigurationService private readonly configurationService: IConfigurationService,
		@IProductService private readonly productService: IProductService,
		@IExtensionManagementServerService private readonly extensionManagementServerService: IExtensionManagementServerService,
		@IUserDataAutoSyncEnablementService protected readonly userDataAutoSyncEnablementService: IUserDataAutoSyncEnablementService,
		@IUserDataSyncResourceEnablementService protected readonly userDataSyncResourceEnablementService: IUserDataSyncResourceEnablementService,
	) {
		super(`extensions.installAndSync`, localize('install', "Install"), InstallAction.Class,
S
Sandeep Somavarapu 已提交
329
			extensionsWorkbenchService, instantiationService, runtimeExtensionService, workbenchThemeService, labelService);
330 331 332 333 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 376 377 378 379 380 381 382 383
		this.updateLabel();
		this._register(labelService.onDidChangeFormatters(() => this.updateLabel(), this));
		this._register(Event.any(userDataAutoSyncEnablementService.onDidChangeEnablement,
			Event.filter(userDataSyncResourceEnablementService.onDidChangeResourceEnablement, e => e[0] === SyncResource.Extensions))(() => this.update()));
	}

	protected updateLabel(): void {
		if (!this.extension) {
			return;
		}

		const isMachineScoped = this.getInstallOptions().isMachineScoped;
		this.label = isMachineScoped ? localize('install and do no sync', "Install (Do not sync)") : localize('install', "Install");

		// When remote connection exists
		if (this._manifest && this.extensionManagementServerService.remoteExtensionManagementServer) {

			// On Desktop and UI Extension
			if (this.extensionManagementServerService.localExtensionManagementServer && prefersExecuteOnUI(this._manifest, this.productService, this.configurationService)) {
				this.label = isMachineScoped ? localize('install locally and do not sync', "Install Locally (Do not sync)") : localize('install locally', "Install Locally");
				return;
			}

			// On Web and Web Extension
			if (this.extensionManagementServerService.webExtensionManagementServer && prefersExecuteOnWeb(this._manifest, this.productService, this.configurationService)) {
				this.label = isMachineScoped ? localize('install locally and do not sync', "Install Locally (Do not sync)") : localize('install locally', "Install Locally");
				return;
			}

			const host = this.extensionManagementServerService.remoteExtensionManagementServer.label;
			this.label = isMachineScoped ? localize('install on remote and do not sync', "Install on {0} (Do not sync)", host) : localize('install on remote', "Install on {0}", host);
			return;
		}
	}

	protected getInstallOptions(): InstallOptions {
		return { isMachineScoped: this.userDataAutoSyncEnablementService.isEnabled() && this.userDataSyncResourceEnablementService.isResourceEnabled(SyncResource.Extensions) };
	}

}

export class InstallAndSyncAction extends AbstractInstallAction {

	constructor(
		@IExtensionsWorkbenchService extensionsWorkbenchService: IExtensionsWorkbenchService,
		@IInstantiationService instantiationService: IInstantiationService,
		@IExtensionService runtimeExtensionService: IExtensionService,
		@IWorkbenchThemeService workbenchThemeService: IWorkbenchThemeService,
		@ILabelService labelService: ILabelService,
		@IProductService productService: IProductService,
		@IUserDataAutoSyncEnablementService private readonly userDataAutoSyncEnablementService: IUserDataAutoSyncEnablementService,
		@IUserDataSyncResourceEnablementService private readonly userDataSyncResourceEnablementService: IUserDataSyncResourceEnablementService,
	) {
		super(`extensions.installAndSync`, localize('install', "Install"), InstallAndSyncAction.Class,
S
Sandeep Somavarapu 已提交
384
			extensionsWorkbenchService, instantiationService, runtimeExtensionService, workbenchThemeService, labelService);
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
		this.tooltip = localize('install everywhere tooltip', "Install this extension in all your synced {0} instances", productService.nameLong);
		this._register(Event.any(userDataAutoSyncEnablementService.onDidChangeEnablement,
			Event.filter(userDataSyncResourceEnablementService.onDidChangeResourceEnablement, e => e[0] === SyncResource.Extensions))(() => this.update()));
	}


	update(): void {
		super.update();
		if (this.enabled) {
			this.enabled = this.userDataAutoSyncEnablementService.isEnabled() && this.userDataSyncResourceEnablementService.isResourceEnabled(SyncResource.Extensions);
		}
	}

	protected updateLabel(): void { }

	protected getInstallOptions(): InstallOptions {
		return { isMachineScoped: false };
	}
}

export class InstallDropdownAction extends ActionWithDropDownAction {

	set manifest(manifest: IExtensionManifest) {
		this.actions.forEach(a => (<AbstractInstallAction>a).manifest = manifest);
		this.actions.forEach(a => a.update());
		this.update();
	}

	constructor(
		@IInstantiationService instantiationService: IInstantiationService,
	) {
		super(`extensions.installActions`, '', [
			instantiationService.createInstance(InstallAndSyncAction),
			instantiationService.createInstance(InstallAction),
		]);
	}

}

export class InstallingLabelAction extends ExtensionAction {

	private static readonly LABEL = localize('installing', "Installing");
	private static readonly CLASS = `${ExtensionAction.LABEL_ACTION_CLASS} install installing`;

	constructor() {
		super('extension.installing', InstallingLabelAction.LABEL, InstallingLabelAction.CLASS, false);
	}

	update(): void {
		this.class = `${InstallingLabelAction.CLASS}${this.extension && this.extension.state === ExtensionState.Installing ? '' : ' hide'}`;
	}
436 437
}

S
Sandeep Somavarapu 已提交
438
export abstract class InstallInOtherServerAction extends ExtensionAction {
439

440 441
	protected static readonly INSTALL_LABEL = localize('install', "Install");
	protected static readonly INSTALLING_LABEL = localize('installing', "Installing");
442

S
Sandeep Somavarapu 已提交
443 444
	private static readonly Class = `${ExtensionAction.LABEL_ACTION_CLASS} prominent install`;
	private static readonly InstallingClass = `${ExtensionAction.LABEL_ACTION_CLASS} install installing`;
445

446
	updateWhenCounterExtensionChanges: boolean = true;
447 448

	constructor(
S
Sandeep Somavarapu 已提交
449 450
		id: string,
		private readonly server: IExtensionManagementServer | null,
S
Sandeep Somavarapu 已提交
451
		private readonly canInstallAnyWhere: boolean,
452
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
Sandeep Somavarapu 已提交
453 454 455
		@IExtensionManagementServerService protected readonly extensionManagementServerService: IExtensionManagementServerService,
		@IProductService private readonly productService: IProductService,
		@IConfigurationService private readonly configurationService: IConfigurationService,
456
	) {
S
Sandeep Somavarapu 已提交
457
		super(id, InstallInOtherServerAction.INSTALL_LABEL, InstallInOtherServerAction.Class, false);
458 459 460
		this.update();
	}

461
	update(): void {
462
		this.enabled = false;
S
Sandeep Somavarapu 已提交
463 464
		this.class = InstallInOtherServerAction.Class;

S
Sandeep Somavarapu 已提交
465
		if (this.canInstall()) {
S
Sandeep Somavarapu 已提交
466
			const extensionInOtherServer = this.extensionsWorkbenchService.installed.filter(e => areSameExtensions(e.identifier, this.extension!.identifier) && e.server === this.server)[0];
S
Sandeep Somavarapu 已提交
467 468 469 470 471 472 473 474 475 476 477 478
			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();
			}
479 480 481
		}
	}

S
Sandeep Somavarapu 已提交
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523
	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;
	}

524
	async run(): Promise<void> {
S
Sandeep Somavarapu 已提交
525 526 527
		if (!this.extension) {
			return;
		}
S
Sandeep Somavarapu 已提交
528
		if (this.server) {
529 530
			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 已提交
531 532 533 534 535
			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);
536 537 538
			}
		}
	}
S
Sandeep Somavarapu 已提交
539 540

	protected abstract getInstallLabel(): string;
541 542
}

S
Sandeep Somavarapu 已提交
543
export class RemoteInstallAction extends InstallInOtherServerAction {
544

S
Sandeep Somavarapu 已提交
545
	constructor(
S
Sandeep Somavarapu 已提交
546
		canInstallAnyWhere: boolean,
S
Sandeep Somavarapu 已提交
547
		@IExtensionsWorkbenchService extensionsWorkbenchService: IExtensionsWorkbenchService,
S
Sandeep Somavarapu 已提交
548 549 550
		@IExtensionManagementServerService extensionManagementServerService: IExtensionManagementServerService,
		@IProductService productService: IProductService,
		@IConfigurationService configurationService: IConfigurationService,
S
Sandeep Somavarapu 已提交
551
	) {
S
Sandeep Somavarapu 已提交
552
		super(`extensions.remoteinstall`, extensionManagementServerService.remoteExtensionManagementServer, canInstallAnyWhere, extensionsWorkbenchService, extensionManagementServerService, productService, configurationService);
S
Sandeep Somavarapu 已提交
553
	}
554

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

S
Sandeep Somavarapu 已提交
559
}
560

S
Sandeep Somavarapu 已提交
561
export class LocalInstallAction extends InstallInOtherServerAction {
562 563

	constructor(
S
Sandeep Somavarapu 已提交
564
		@IExtensionsWorkbenchService extensionsWorkbenchService: IExtensionsWorkbenchService,
S
Sandeep Somavarapu 已提交
565 566 567
		@IExtensionManagementServerService extensionManagementServerService: IExtensionManagementServerService,
		@IProductService productService: IProductService,
		@IConfigurationService configurationService: IConfigurationService,
568
	) {
S
Sandeep Somavarapu 已提交
569
		super(`extensions.localinstall`, extensionManagementServerService.localExtensionManagementServer, false, extensionsWorkbenchService, extensionManagementServerService, productService, configurationService);
570 571
	}

S
Sandeep Somavarapu 已提交
572 573
	protected getInstallLabel(): string {
		return localize('install locally', "Install Locally");
574 575 576 577
	}

}

S
Sandeep Somavarapu 已提交
578
export class UninstallAction extends ExtensionAction {
579

S
Sandeep Somavarapu 已提交
580
	static readonly UninstallLabel = localize('uninstallAction', "Uninstall");
581
	private static readonly UninstallingLabel = localize('Uninstalling', "Uninstalling");
582

S
Sandeep Somavarapu 已提交
583 584
	private static readonly UninstallClass = `${ExtensionAction.LABEL_ACTION_CLASS} uninstall`;
	private static readonly UnInstallingClass = `${ExtensionAction.LABEL_ACTION_CLASS} uninstall uninstalling`;
S
Sandeep Somavarapu 已提交
585

586
	constructor(
S
Sandeep Somavarapu 已提交
587
		@IExtensionsWorkbenchService private extensionsWorkbenchService: IExtensionsWorkbenchService
588
	) {
S
Sandeep Somavarapu 已提交
589
		super('extensions.uninstall', UninstallAction.UninstallLabel, UninstallAction.UninstallClass, false);
590 591 592
		this.update();
	}

S
Sandeep Somavarapu 已提交
593
	update(): void {
594 595 596 597 598 599 600 601 602
		if (!this.extension) {
			this.enabled = false;
			return;
		}

		const state = this.extension.state;

		if (state === ExtensionState.Uninstalling) {
			this.label = UninstallAction.UninstallingLabel;
S
Sandeep Somavarapu 已提交
603
			this.class = UninstallAction.UnInstallingClass;
604 605 606 607 608
			this.enabled = false;
			return;
		}

		this.label = UninstallAction.UninstallLabel;
S
Sandeep Somavarapu 已提交
609
		this.class = UninstallAction.UninstallClass;
S
Sandeep Somavarapu 已提交
610
		this.tooltip = UninstallAction.UninstallLabel;
611

S
Sandeep Somavarapu 已提交
612 613 614 615 616
		if (state !== ExtensionState.Installed) {
			this.enabled = false;
			return;
		}

617
		if (this.extension.isBuiltin) {
618 619 620 621 622 623 624
			this.enabled = false;
			return;
		}

		this.enabled = true;
	}

S
Sandeep Somavarapu 已提交
625 626 627 628
	async run(): Promise<any> {
		if (!this.extension) {
			return;
		}
629 630 631
		alert(localize('uninstallExtensionStart', "Uninstalling extension {0} started.", this.extension.displayName));

		return this.extensionsWorkbenchService.uninstall(this.extension).then(() => {
S
Sandeep Somavarapu 已提交
632
			alert(localize('uninstallExtensionComplete', "Please reload Visual Studio Code to complete the uninstallation of the extension {0}.", this.extension!.displayName));
633
		});
634 635 636
	}
}

S
Sandeep Somavarapu 已提交
637
export class UpdateAction extends ExtensionAction {
638

S
Sandeep Somavarapu 已提交
639
	private static readonly EnabledClass = `${ExtensionAction.LABEL_ACTION_CLASS} prominent update`;
640
	private static readonly DisabledClass = `${UpdateAction.EnabledClass} disabled`;
641 642

	constructor(
643 644
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
		@IInstantiationService private readonly instantiationService: IInstantiationService,
645
	) {
646
		super(`extensions.update`, '', UpdateAction.DisabledClass, false);
647 648 649
		this.update();
	}

S
Sandeep Somavarapu 已提交
650
	update(): void {
651 652 653
		if (!this.extension) {
			this.enabled = false;
			this.class = UpdateAction.DisabledClass;
654
			this.label = this.getUpdateLabel();
655 656 657
			return;
		}

658
		if (this.extension.type !== ExtensionType.User) {
659 660
			this.enabled = false;
			this.class = UpdateAction.DisabledClass;
661
			this.label = this.getUpdateLabel();
662 663 664 665 666 667 668 669
			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;
670
		this.label = this.extension.outdated ? this.getUpdateLabel(this.extension.latestVersion) : this.getUpdateLabel();
671 672
	}

S
Sandeep Somavarapu 已提交
673 674 675 676
	async run(): Promise<any> {
		if (!this.extension) {
			return;
		}
677
		alert(localize('updateExtensionStart', "Updating extension {0} to version {1} started.", this.extension.displayName, this.extension.latestVersion));
J
Joao Moreno 已提交
678 679 680
		return this.install(this.extension);
	}

S
Sandeep Somavarapu 已提交
681 682 683
	private async install(extension: IExtension): Promise<void> {
		try {
			await this.extensionsWorkbenchService.install(extension);
S
Sandeep Somavarapu 已提交
684
			alert(localize('updateExtensionComplete', "Updating extension {0} to version {1} completed.", extension.displayName, extension.latestVersion));
S
Sandeep Somavarapu 已提交
685 686 687
		} catch (err) {
			this.instantiationService.createInstance(PromptExtensionInstallFailureAction, extension, InstallOperation.Update, err).run();
		}
688 689
	}

690
	private getUpdateLabel(version?: string): string {
691
		return version ? localize('updateTo', "Update to {0}", version) : localize('updateAction', "Update");
692
	}
693 694
}

695
export interface IExtensionActionViewItemOptions extends IActionViewItemOptions {
696 697 698
	tabOnlyOnFocus?: boolean;
}

699
export class ExtensionActionViewItem extends ActionViewItem {
700

701
	constructor(context: any, action: IAction, options: IExtensionActionViewItemOptions = {}) {
702 703 704 705 706 707
		super(context, action, options);
	}

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

S
Sandeep Somavarapu 已提交
708
		if (this.label && (<IExtensionActionViewItemOptions>this.options).tabOnlyOnFocus && this.getAction().enabled && !this._hasFocus) {
709 710 711 712
			DOM.removeTabIndexAndUpdateFocus(this.label);
		}
	}

S
Sandeep Somavarapu 已提交
713
	private _hasFocus: boolean = false;
714
	setFocus(value: boolean): void {
S
Sandeep Somavarapu 已提交
715
		if (!(<IExtensionActionViewItemOptions>this.options).tabOnlyOnFocus || this._hasFocus === value) {
716 717 718
			return;
		}
		this._hasFocus = value;
719
		if (this.label && this.getAction().enabled) {
720 721 722 723 724 725 726 727 728
			if (this._hasFocus) {
				this.label.tabIndex = 0;
			} else {
				DOM.removeTabIndexAndUpdateFocus(this.label);
			}
		}
	}
}

729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775
export class ExtensionActionWithDropdownActionViewItem extends ActionWithDropdownActionViewItem {

	constructor(
		action: ActionWithDropDownAction,
		options: IExtensionActionViewItemOptions & IActionWithDropdownActionViewItemOptions,
		contextMenuProvider: IContextMenuProvider
	) {
		super(null, action, options, contextMenuProvider);
	}

	render(container: HTMLElement): void {
		super.render(container);
		this.updateClass();
	}

	updateClass(): void {
		super.updateClass();
		if (this.dropdownMenuActionViewItem && this.dropdownMenuActionViewItem.element) {
			this.dropdownMenuActionViewItem.element.classList.toggle('hide', (<ActionWithDropDownAction>this._action).menuActions.length === 0);
		}
	}

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

		if (this.label && (<IExtensionActionViewItemOptions>this.options).tabOnlyOnFocus && this.getAction().enabled && !this._hasFocus) {
			DOM.removeTabIndexAndUpdateFocus(this.label);
		}
	}

	private _hasFocus: boolean = false;
	setFocus(value: boolean): void {
		if (!(<IExtensionActionViewItemOptions>this.options).tabOnlyOnFocus || this._hasFocus === value) {
			return;
		}
		this._hasFocus = value;
		if (this.label && this.getAction().enabled) {
			if (this._hasFocus) {
				this.label.tabIndex = 0;
			} else {
				DOM.removeTabIndexAndUpdateFocus(this.label);
			}
		}
	}

}

S
Sandeep Somavarapu 已提交
776
export abstract class ExtensionDropDownAction extends ExtensionAction {
S
Explore  
Sandeep Somavarapu 已提交
777 778 779 780 781 782 783

	constructor(
		id: string,
		label: string,
		cssClass: string,
		enabled: boolean,
		private readonly tabOnlyOnFocus: boolean,
S
Sandeep Somavarapu 已提交
784
		@IInstantiationService protected instantiationService: IInstantiationService
S
Explore  
Sandeep Somavarapu 已提交
785 786 787 788
	) {
		super(id, label, cssClass, enabled);
	}

S
Sandeep Somavarapu 已提交
789
	private _actionViewItem: DropDownMenuActionViewItem | null = null;
790 791 792
	createActionViewItem(): DropDownMenuActionViewItem {
		this._actionViewItem = this.instantiationService.createInstance(DropDownMenuActionViewItem, this, this.tabOnlyOnFocus);
		return this._actionViewItem;
S
Explore  
Sandeep Somavarapu 已提交
793 794
	}

J
Johannes Rieken 已提交
795
	public run({ actionGroups, disposeActionsOnHide }: { actionGroups: IAction[][], disposeActionsOnHide: boolean }): Promise<any> {
796 797
		if (this._actionViewItem) {
			this._actionViewItem.showMenu(actionGroups, disposeActionsOnHide);
S
Explore  
Sandeep Somavarapu 已提交
798
		}
799
		return Promise.resolve();
S
Explore  
Sandeep Somavarapu 已提交
800 801 802
	}
}

803
export class DropDownMenuActionViewItem extends ExtensionActionViewItem {
804

S
Sandeep Somavarapu 已提交
805
	constructor(action: ExtensionDropDownAction,
806
		tabOnlyOnFocus: boolean,
807
		@IContextMenuService private readonly contextMenuService: IContextMenuService
S
Sandeep Somavarapu 已提交
808
	) {
809
		super(null, action, { icon: true, label: true, tabOnlyOnFocus });
810 811
	}

S
Sandeep Somavarapu 已提交
812
	public showMenu(menuActionGroups: IAction[][], disposeActionsOnHide: boolean): void {
813 814 815 816 817 818 819 820 821 822 823
		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); } }
			});
		}
824 825
	}

S
Sandeep Somavarapu 已提交
826
	private getActions(menuActionGroups: IAction[][]): IAction[] {
B
Benjamin Pasero 已提交
827
		let actions: IAction[] = [];
S
Sandeep Somavarapu 已提交
828
		for (const menuActions of menuActionGroups) {
S
Sandeep Somavarapu 已提交
829
			actions = [...actions, ...menuActions, new Separator()];
830 831 832 833 834
		}
		return actions.length ? actions.slice(0, actions.length - 1) : actions;
	}
}

S
Sandeep Somavarapu 已提交
835
export function getContextMenuActions(extension: IExtension | undefined | null, inExtensionEditor: boolean, instantiationService: IInstantiationService): IAction[][] {
S
Sandeep Somavarapu 已提交
836 837 838 839 840 841 842 843 844 845 846 847
	return instantiationService.invokeFunction(accessor => {
		const scopedContextKeyService = accessor.get(IContextKeyService).createScoped();
		const menuService = accessor.get(IMenuService);
		const extensionRecommendationsService = accessor.get(IExtensionRecommendationsService);
		const extensionIgnoredRecommendationsService = accessor.get(IExtensionIgnoredRecommendationsService);
		if (extension) {
			scopedContextKeyService.createKey<string>('extension', extension.identifier.id);
			scopedContextKeyService.createKey<boolean>('isBuiltinExtension', extension.isBuiltin);
			scopedContextKeyService.createKey<boolean>('extensionHasConfiguration', extension.local && !!extension.local.manifest.contributes && !!extension.local.manifest.contributes.configuration);
			scopedContextKeyService.createKey<boolean>('isExtensionRecommended', !!extensionRecommendationsService.getAllRecommendationsWithReason()[extension.identifier.id.toLowerCase()]);
			scopedContextKeyService.createKey<boolean>('isExtensionWorkspaceRecommended', extensionRecommendationsService.getAllRecommendationsWithReason()[extension.identifier.id.toLowerCase()]?.reasonId === ExtensionRecommendationReason.Workspace);
			scopedContextKeyService.createKey<boolean>('isUserIgnoredRecommendation', extensionIgnoredRecommendationsService.globalIgnoredRecommendations.some(e => e === extension.identifier.id.toLowerCase()));
S
Sandeep Somavarapu 已提交
848
			scopedContextKeyService.createKey<boolean>('inExtensionEditor', inExtensionEditor);
S
Sandeep Somavarapu 已提交
849 850 851
			if (extension.state === ExtensionState.Installed) {
				scopedContextKeyService.createKey<string>('extensionStatus', 'installed');
			}
852 853
		}

S
Sandeep Somavarapu 已提交
854 855 856 857 858 859 860 861 862 863
		const groups: IAction[][] = [];
		const menu = menuService.createMenu(MenuId.ExtensionContext, scopedContextKeyService);
		menu.getActions({ shouldForwardArgs: true }).forEach(([, actions]) => groups.push(actions.map(action => {
			if (action instanceof SubmenuAction) {
				return action;
			}
			return instantiationService.createInstance(MenuItemExtensionAction, action);
		})));
		menu.dispose();
		scopedContextKeyService.dispose();
864

S
Sandeep Somavarapu 已提交
865 866
		return groups;
	});
S
Sandeep Somavarapu 已提交
867 868
}

S
Sandeep Somavarapu 已提交
869
export class ManageExtensionAction extends ExtensionDropDownAction {
870

871
	static readonly ID = 'extensions.manage';
S
Sandeep Somavarapu 已提交
872 873

	private static readonly Class = `${ExtensionAction.ICON_ACTION_CLASS} manage codicon-gear`;
874
	private static readonly HideManageExtensionClass = `${ManageExtensionAction.Class} hide`;
875 876

	constructor(
S
Sandeep Somavarapu 已提交
877
		@IInstantiationService instantiationService: IInstantiationService,
878
		@IExtensionService private readonly extensionService: IExtensionService,
879
		@IWorkbenchThemeService private readonly workbenchThemeService: IWorkbenchThemeService,
880
	) {
S
Sandeep Somavarapu 已提交
881 882

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

S
Sandeep Somavarapu 已提交
884
		this.tooltip = localize('manage', "Manage");
885 886 887 888

		this.update();
	}

889
	async getActionGroups(runningExtensions: IExtensionDescription[]): Promise<IAction[][]> {
890
		const groups: IAction[][] = [];
891
		if (this.extension) {
892 893 894 895 896 897 898 899 900 901
			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);
902
				}
903 904
			}
			if (themesGroup.length) {
905 906 907
				groups.push(themesGroup);
			}
		}
S
Sandeep Somavarapu 已提交
908
		groups.push([
S
Sandeep Somavarapu 已提交
909
			this.instantiationService.createInstance(EnableGloballyAction),
910
			this.instantiationService.createInstance(EnableForWorkspaceAction)
S
Sandeep Somavarapu 已提交
911 912
		]);
		groups.push([
S
Sandeep Somavarapu 已提交
913 914
			this.instantiationService.createInstance(DisableGloballyAction, runningExtensions),
			this.instantiationService.createInstance(DisableForWorkspaceAction, runningExtensions)
S
Sandeep Somavarapu 已提交
915
		]);
916 917 918 919
		groups.push([
			this.instantiationService.createInstance(UninstallAction),
			this.instantiationService.createInstance(InstallAnotherVersionAction)
		]);
P
Peng Lyu 已提交
920

S
Sandeep Somavarapu 已提交
921
		getContextMenuActions(this.extension, false, this.instantiationService).forEach(actions => groups.push(actions));
P
Peng Lyu 已提交
922

923 924 925 926 927
		groups.forEach(group => group.forEach(extensionAction => {
			if (extensionAction instanceof ExtensionAction) {
				extensionAction.extension = this.extension;
			}
		}));
S
Sandeep Somavarapu 已提交
928 929 930 931

		return groups;
	}

932 933
	async run(): Promise<any> {
		const runtimeExtensions = await this.extensionService.getExtensions();
934
		return super.run({ actionGroups: await this.getActionGroups(runtimeExtensions), disposeActionsOnHide: true });
S
Sandeep Somavarapu 已提交
935 936
	}

S
Sandeep Somavarapu 已提交
937
	update(): void {
S
Sandeep Somavarapu 已提交
938
		this.class = ManageExtensionAction.HideManageExtensionClass;
939
		this.enabled = false;
S
Sandeep Somavarapu 已提交
940
		if (this.extension) {
941 942
			const state = this.extension.state;
			this.enabled = state === ExtensionState.Installed;
S
Sandeep Somavarapu 已提交
943
			this.class = this.enabled || state === ExtensionState.Uninstalling ? ManageExtensionAction.Class : ManageExtensionAction.HideManageExtensionClass;
944 945 946 947 948
			this.tooltip = state === ExtensionState.Uninstalling ? localize('ManageExtensionAction.uninstallingTooltip', "Uninstalling") : '';
		}
	}
}

S
Sandeep Somavarapu 已提交
949 950 951
export class ExtensionEditorManageExtensionAction extends ExtensionDropDownAction {

	constructor(
952
		@IInstantiationService instantiationService: IInstantiationService
S
Sandeep Somavarapu 已提交
953
	) {
954
		super('extensionEditor.manageExtension', '', `${ExtensionAction.ICON_ACTION_CLASS} manage codicon-gear`, true, true, instantiationService);
S
Sandeep Somavarapu 已提交
955 956 957
		this.tooltip = localize('manage', "Manage");
	}

958
	update(): void { }
S
Sandeep Somavarapu 已提交
959

960 961 962 963
	run(): Promise<any> {
		const actionGroups: IAction[][] = [];
		getContextMenuActions(this.extension, true, this.instantiationService).forEach(actions => actionGroups.push(actions));
		return super.run({ actionGroups, disposeActionsOnHide: true });
S
Sandeep Somavarapu 已提交
964 965 966 967
	}

}

968 969
export class MenuItemExtensionAction extends ExtensionAction {

S
Sandeep Somavarapu 已提交
970 971
	constructor(
		private readonly action: IAction,
972
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
Sandeep Somavarapu 已提交
973
	) {
974 975 976
		super(action.id, action.label);
	}

S
Sandeep Somavarapu 已提交
977 978 979 980 981
	update() {
		if (!this.extension) {
			return;
		}
		if (this.action.id === TOGGLE_IGNORE_EXTENSION_ACTION_ID) {
982
			this.checked = !this.extensionsWorkbenchService.isExtensionIgnoredToSync(this.extension);
S
Sandeep Somavarapu 已提交
983 984
		}
	}
985 986 987

	async run(): Promise<void> {
		if (this.extension) {
S
Sandeep Somavarapu 已提交
988
			return this.action.run(this.extension.identifier.id);
989 990 991 992
		}
	}
}

S
Sandeep Somavarapu 已提交
993
export class InstallAnotherVersionAction extends ExtensionAction {
994

995
	static readonly ID = 'workbench.extensions.action.install.anotherVersion';
996
	static readonly LABEL = localize('install another version', "Install Another Version...");
997

S
Sandeep Somavarapu 已提交
998
	constructor(
999 1000 1001 1002
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
		@IExtensionGalleryService private readonly extensionGalleryService: IExtensionGalleryService,
		@IQuickInputService private readonly quickInputService: IQuickInputService,
		@IInstantiationService private readonly instantiationService: IInstantiationService,
1003
	) {
S
Sandeep Somavarapu 已提交
1004
		super(InstallAnotherVersionAction.ID, InstallAnotherVersionAction.LABEL, ExtensionAction.LABEL_ACTION_CLASS);
S
Sandeep Somavarapu 已提交
1005 1006 1007 1008
		this.update();
	}

	update(): void {
1009
		this.enabled = !!this.extension && !this.extension.isBuiltin && !!this.extension.gallery && this.extension.state === ExtensionState.Installed;
1010 1011
	}

J
Johannes Rieken 已提交
1012
	run(): Promise<any> {
1013 1014 1015
		if (!this.enabled) {
			return Promise.resolve();
		}
S
Sandeep Somavarapu 已提交
1016
		return this.quickInputService.pick(this.getVersionEntries(), { placeHolder: localize('selectVersion', "Select Version to Install"), matchOnDetail: true })
S
Sandeep Somavarapu 已提交
1017
			.then(async pick => {
1018
				if (pick) {
S
Sandeep Somavarapu 已提交
1019
					if (this.extension!.version === pick.id) {
S
Sandeep Somavarapu 已提交
1020 1021
						return Promise.resolve();
					}
S
Sandeep Somavarapu 已提交
1022 1023 1024 1025 1026 1027 1028 1029 1030
					try {
						if (pick.latest) {
							await this.extensionsWorkbenchService.install(this.extension!);
						} else {
							await this.extensionsWorkbenchService.installVersion(this.extension!, pick.id);
						}
					} catch (error) {
						this.instantiationService.createInstance(PromptExtensionInstallFailureAction, this.extension!, InstallOperation.Install, error).run();
					}
1031 1032 1033 1034
				}
				return null;
			});
	}
S
Sandeep Somavarapu 已提交
1035

1036
	private getVersionEntries(): Promise<(IQuickPickItem & { latest: boolean, id: string })[]> {
S
Sandeep Somavarapu 已提交
1037 1038
		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 已提交
1039
	}
1040 1041
}

S
Sandeep Somavarapu 已提交
1042
export class EnableForWorkspaceAction extends ExtensionAction {
1043

1044
	static readonly ID = 'extensions.enableForWorkspace';
1045
	static readonly LABEL = localize('enableForWorkspaceAction', "Enable (Workspace)");
1046

S
Sandeep Somavarapu 已提交
1047
	constructor(
1048
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
rename  
Sandeep Somavarapu 已提交
1049
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService
1050
	) {
1051
		super(EnableForWorkspaceAction.ID, EnableForWorkspaceAction.LABEL, ExtensionAction.LABEL_ACTION_CLASS);
1052 1053 1054
		this.update();
	}

S
Sandeep Somavarapu 已提交
1055
	update(): void {
1056
		this.enabled = false;
1057 1058
		if (this.extension && this.extension.local) {
			this.enabled = this.extension.state === ExtensionState.Installed
1059
				&& !this.extensionEnablementService.isEnabled(this.extension.local)
S
Sandeep Somavarapu 已提交
1060
				&& this.extensionEnablementService.canChangeWorkspaceEnablement(this.extension.local);
1061 1062 1063
		}
	}

S
Sandeep Somavarapu 已提交
1064 1065 1066 1067
	async run(): Promise<any> {
		if (!this.extension) {
			return;
		}
1068
		return this.extensionsWorkbenchService.setEnablement(this.extension, EnablementState.EnabledWorkspace);
1069 1070 1071
	}
}

S
Sandeep Somavarapu 已提交
1072
export class EnableGloballyAction extends ExtensionAction {
1073

1074
	static readonly ID = 'extensions.enableGlobally';
1075
	static readonly LABEL = localize('enableGloballyAction', "Enable");
1076

S
Sandeep Somavarapu 已提交
1077
	constructor(
1078
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
rename  
Sandeep Somavarapu 已提交
1079
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService
1080
	) {
1081
		super(EnableGloballyAction.ID, EnableGloballyAction.LABEL, ExtensionAction.LABEL_ACTION_CLASS);
1082 1083 1084
		this.update();
	}

S
Sandeep Somavarapu 已提交
1085
	update(): void {
1086
		this.enabled = false;
1087
		if (this.extension && this.extension.local) {
1088
			this.enabled = this.extension.state === ExtensionState.Installed
S
Sandeep Somavarapu 已提交
1089
				&& this.extensionEnablementService.isDisabledGlobally(this.extension.local)
1090
				&& this.extensionEnablementService.canChangeEnablement(this.extension.local);
1091 1092 1093
		}
	}

S
Sandeep Somavarapu 已提交
1094 1095 1096 1097
	async run(): Promise<any> {
		if (!this.extension) {
			return;
		}
1098
		return this.extensionsWorkbenchService.setEnablement(this.extension, EnablementState.EnabledGlobally);
1099 1100 1101
	}
}

S
Sandeep Somavarapu 已提交
1102
export class DisableForWorkspaceAction extends ExtensionAction {
1103

1104
	static readonly ID = 'extensions.disableForWorkspace';
1105
	static readonly LABEL = localize('disableForWorkspaceAction', "Disable (Workspace)");
1106

S
Sandeep Somavarapu 已提交
1107
	constructor(readonly runningExtensions: IExtensionDescription[],
1108 1109
		@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService,
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
rename  
Sandeep Somavarapu 已提交
1110
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService
1111
	) {
1112
		super(DisableForWorkspaceAction.ID, DisableForWorkspaceAction.LABEL, ExtensionAction.LABEL_ACTION_CLASS);
1113 1114 1115
		this.update();
	}

S
Sandeep Somavarapu 已提交
1116
	update(): void {
1117
		this.enabled = false;
S
Sandeep Somavarapu 已提交
1118
		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)) {
1119
			this.enabled = this.extension.state === ExtensionState.Installed
1120
				&& (this.extension.enablementState === EnablementState.EnabledGlobally || this.extension.enablementState === EnablementState.EnabledWorkspace)
S
Sandeep Somavarapu 已提交
1121
				&& this.extensionEnablementService.canChangeWorkspaceEnablement(this.extension.local);
1122 1123 1124
		}
	}

S
Sandeep Somavarapu 已提交
1125 1126 1127 1128
	async run(): Promise<any> {
		if (!this.extension) {
			return;
		}
1129
		return this.extensionsWorkbenchService.setEnablement(this.extension, EnablementState.DisabledWorkspace);
1130 1131 1132
	}
}

S
Sandeep Somavarapu 已提交
1133
export class DisableGloballyAction extends ExtensionAction {
1134

1135
	static readonly ID = 'extensions.disableGlobally';
1136
	static readonly LABEL = localize('disableGloballyAction', "Disable");
1137

S
Sandeep Somavarapu 已提交
1138
	constructor(readonly runningExtensions: IExtensionDescription[],
1139
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
rename  
Sandeep Somavarapu 已提交
1140
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService
1141
	) {
1142
		super(DisableGloballyAction.ID, DisableGloballyAction.LABEL, ExtensionAction.LABEL_ACTION_CLASS);
1143 1144 1145
		this.update();
	}

S
Sandeep Somavarapu 已提交
1146
	update(): void {
1147
		this.enabled = false;
S
Sandeep Somavarapu 已提交
1148
		if (this.extension && this.extension.local && this.runningExtensions.some(e => areSameExtensions({ id: e.identifier.value, uuid: e.uuid }, this.extension!.identifier))) {
1149
			this.enabled = this.extension.state === ExtensionState.Installed
1150
				&& (this.extension.enablementState === EnablementState.EnabledGlobally || this.extension.enablementState === EnablementState.EnabledWorkspace)
1151
				&& this.extensionEnablementService.canChangeEnablement(this.extension.local);
1152 1153 1154
		}
	}

S
Sandeep Somavarapu 已提交
1155 1156 1157 1158
	async run(): Promise<any> {
		if (!this.extension) {
			return;
		}
1159
		return this.extensionsWorkbenchService.setEnablement(this.extension, EnablementState.DisabledGlobally);
1160 1161 1162
	}
}

S
Sandeep Somavarapu 已提交
1163
export class EnableDropDownAction extends ActionWithDropDownAction {
S
Sandeep Somavarapu 已提交
1164 1165

	constructor(
S
Sandeep Somavarapu 已提交
1166
		@IInstantiationService instantiationService: IInstantiationService
S
Sandeep Somavarapu 已提交
1167
	) {
S
Sandeep Somavarapu 已提交
1168 1169
		super('extensions.enable', localize('enableAction', "Enable"), [
			instantiationService.createInstance(EnableGloballyAction),
1170
			instantiationService.createInstance(EnableForWorkspaceAction)
S
Sandeep Somavarapu 已提交
1171
		]);
S
Sandeep Somavarapu 已提交
1172 1173 1174
	}
}

S
Sandeep Somavarapu 已提交
1175
export class DisableDropDownAction extends ActionWithDropDownAction {
S
Sandeep Somavarapu 已提交
1176 1177

	constructor(
S
Sandeep Somavarapu 已提交
1178 1179
		runningExtensions: IExtensionDescription[],
		@IInstantiationService instantiationService: IInstantiationService
S
Sandeep Somavarapu 已提交
1180
	) {
S
Sandeep Somavarapu 已提交
1181 1182 1183
		super('extensions.disable', localize('disableAction', "Disable"), [
			instantiationService.createInstance(DisableGloballyAction, runningExtensions),
			instantiationService.createInstance(DisableForWorkspaceAction, runningExtensions)
S
Sandeep Somavarapu 已提交
1184
		]);
1185
	}
S
Sandeep Somavarapu 已提交
1186

1187 1188
}

J
Joao Moreno 已提交
1189 1190
export class CheckForUpdatesAction extends Action {

1191
	static readonly ID = 'workbench.extensions.action.checkForUpdates';
1192
	static readonly LABEL = localize('checkForUpdates', "Check for Extension Updates");
J
Joao Moreno 已提交
1193 1194

	constructor(
1195 1196
		id = CheckForUpdatesAction.ID,
		label = CheckForUpdatesAction.LABEL,
1197
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
rename  
Sandeep Somavarapu 已提交
1198
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService,
1199 1200
		@IViewletService private readonly viewletService: IViewletService,
		@INotificationService private readonly notificationService: INotificationService
J
Joao Moreno 已提交
1201 1202 1203 1204
	) {
		super(id, label, '', true);
	}

1205
	private checkUpdatesAndNotify(): void {
1206 1207
		const outdated = this.extensionsWorkbenchService.outdated;
		if (!outdated.length) {
1208
			this.notificationService.info(localize('noUpdatesAvailable', "All extensions are up to date."));
1209 1210
			return;
		}
1211

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

1214
		const disabledExtensionsCount = outdated.filter(ext => ext.local && !this.extensionEnablementService.isEnabled(ext.local)).length;
1215 1216 1217 1218 1219 1220 1221 1222 1223
		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);
1224
			}
1225 1226 1227
		}

		this.viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
1228
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
1229 1230 1231
			.then(viewlet => viewlet.search(''));

		this.notificationService.info(msgAvailableExtensions);
1232 1233
	}

S
Sandeep Somavarapu 已提交
1234
	run(): Promise<any> {
1235
		return this.extensionsWorkbenchService.checkForUpdates().then(() => this.checkUpdatesAndNotify());
J
Joao Moreno 已提交
1236 1237 1238
	}
}

S
Sandeep Somavarapu 已提交
1239 1240 1241 1242 1243 1244
export class ToggleAutoUpdateAction extends Action {

	constructor(
		id: string,
		label: string,
		private autoUpdateValue: boolean,
1245
		@IConfigurationService private readonly configurationService: IConfigurationService
S
Sandeep Somavarapu 已提交
1246 1247 1248
	) {
		super(id, label, '', true);
		this.updateEnablement();
1249
		configurationService.onDidChangeConfiguration(() => this.updateEnablement());
S
Sandeep Somavarapu 已提交
1250 1251 1252
	}

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

S
Sandeep Somavarapu 已提交
1256
	run(): Promise<any> {
1257
		return this.configurationService.updateValue(AutoUpdateConfigurationKey, this.autoUpdateValue);
S
Sandeep Somavarapu 已提交
1258 1259 1260 1261 1262
	}
}

export class EnableAutoUpdateAction extends ToggleAutoUpdateAction {

1263
	static readonly ID = 'workbench.extensions.action.enableAutoUpdate';
1264
	static readonly LABEL = localize('enableAutoUpdate', "Enable Auto Updating Extensions");
S
Sandeep Somavarapu 已提交
1265 1266 1267 1268

	constructor(
		id = EnableAutoUpdateAction.ID,
		label = EnableAutoUpdateAction.LABEL,
1269
		@IConfigurationService configurationService: IConfigurationService
S
Sandeep Somavarapu 已提交
1270
	) {
1271
		super(id, label, true, configurationService);
S
Sandeep Somavarapu 已提交
1272 1273 1274 1275 1276
	}
}

export class DisableAutoUpdateAction extends ToggleAutoUpdateAction {

1277
	static readonly ID = 'workbench.extensions.action.disableAutoUpdate';
1278
	static readonly LABEL = localize('disableAutoUpdate', "Disable Auto Updating Extensions");
S
Sandeep Somavarapu 已提交
1279 1280 1281 1282

	constructor(
		id = EnableAutoUpdateAction.ID,
		label = EnableAutoUpdateAction.LABEL,
1283
		@IConfigurationService configurationService: IConfigurationService
S
Sandeep Somavarapu 已提交
1284
	) {
1285
		super(id, label, false, configurationService);
S
Sandeep Somavarapu 已提交
1286 1287 1288
	}
}

1289 1290
export class UpdateAllAction extends Action {

1291
	static readonly ID = 'workbench.extensions.action.updateAllExtensions';
1292
	static readonly LABEL = localize('updateAll', "Update All Extensions");
1293 1294

	constructor(
S
Sandeep Somavarapu 已提交
1295
		id: string, label: string, isPrimary: boolean,
1296 1297
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
		@IInstantiationService private readonly instantiationService: IInstantiationService,
1298 1299 1300
	) {
		super(id, label, '', false);

S
Sandeep Somavarapu 已提交
1301 1302 1303
		if (isPrimary) {
			this._register(this.extensionsWorkbenchService.onChange(() => this._onDidChange.fire({ enabled: this.enabled })));
		}
1304 1305
	}

S
Sandeep Somavarapu 已提交
1306 1307
	get enabled(): boolean {
		return this.extensionsWorkbenchService.outdated.length > 0;
1308 1309
	}

S
Sandeep Somavarapu 已提交
1310
	run(): Promise<any> {
1311
		return Promise.all(this.extensionsWorkbenchService.outdated.map(e => this.install(e)));
J
Joao Moreno 已提交
1312 1313
	}

S
Sandeep Somavarapu 已提交
1314 1315 1316 1317 1318 1319
	private async install(extension: IExtension): Promise<void> {
		try {
			await this.extensionsWorkbenchService.install(extension);
		} catch (err) {
			this.instantiationService.createInstance(PromptExtensionInstallFailureAction, extension, InstallOperation.Update, err).run();
		}
1320 1321 1322
	}
}

S
Sandeep Somavarapu 已提交
1323
export class ReloadAction extends ExtensionAction {
1324

S
Sandeep Somavarapu 已提交
1325
	private static readonly EnabledClass = `${ExtensionAction.LABEL_ACTION_CLASS} reload`;
1326
	private static readonly DisabledClass = `${ReloadAction.EnabledClass} disabled`;
1327

1328
	updateWhenCounterExtensionChanges: boolean = true;
1329
	private _runningExtensions: IExtensionDescription[] | null = null;
1330 1331

	constructor(
1332
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
1333
		@IHostService private readonly hostService: IHostService,
1334
		@IExtensionService private readonly extensionService: IExtensionService,
S
rename  
Sandeep Somavarapu 已提交
1335
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService,
1336 1337 1338
		@IExtensionManagementServerService private readonly extensionManagementServerService: IExtensionManagementServerService,
		@IProductService private readonly productService: IProductService,
		@IConfigurationService private readonly configurationService: IConfigurationService,
1339 1340
	) {
		super('extensions.reload', localize('reloadAction', "Reload"), ReloadAction.DisabledClass, false);
M
Matt Bierner 已提交
1341
		this._register(this.extensionService.onDidChangeExtensions(this.updateRunningExtensions, this));
1342
		this.updateRunningExtensions();
1343 1344
	}

1345
	private updateRunningExtensions(): void {
1346
		this.extensionService.getExtensions().then(runningExtensions => { this._runningExtensions = runningExtensions; this.update(); });
1347 1348 1349 1350 1351
	}

	update(): void {
		this.enabled = false;
		this.tooltip = '';
1352
		if (!this.extension || !this._runningExtensions) {
1353 1354 1355 1356 1357 1358
			return;
		}
		const state = this.extension.state;
		if (state === ExtensionState.Installing || state === ExtensionState.Uninstalling) {
			return;
		}
1359
		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) {
1360 1361
			return;
		}
1362
		this.computeReloadState();
1363
		this.class = this.enabled ? ReloadAction.EnabledClass : ReloadAction.DisabledClass;
1364 1365
	}

1366
	private computeReloadState(): void {
S
Sandeep Somavarapu 已提交
1367
		if (!this._runningExtensions || !this.extension) {
1368 1369
			return;
		}
S
Sandeep Somavarapu 已提交
1370

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

1375
		if (isUninstalled) {
S
Sandeep Somavarapu 已提交
1376
			if (isSameExtensionRunning && !this.extensionService.canRemoveExtension(runningExtension)) {
1377 1378 1379 1380 1381 1382 1383
				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;
		}
1384 1385
		if (this.extension.local) {
			const isEnabled = this.extensionEnablementService.isEnabled(this.extension.local);
S
Sandeep Somavarapu 已提交
1386

1387
			// Extension is running
1388
			if (runningExtension) {
1389
				if (isEnabled) {
1390 1391 1392 1393
					// No Reload is required if extension can run without reload
					if (this.extensionService.canAddExtension(toExtensionDescription(this.extension.local))) {
						return;
					}
1394
					const runningExtensionServer = this.extensionManagementServerService.getExtensionManagementServer(toExtension(runningExtension));
S
Sandeep Somavarapu 已提交
1395

1396 1397 1398 1399 1400 1401
					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 已提交
1402
							return;
1403
						}
S
Sandeep Somavarapu 已提交
1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423

						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;
							}
						}

1424
					} else {
S
Sandeep Somavarapu 已提交
1425

1426 1427 1428
						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)) {
1429 1430
								this.enabled = true;
								this.label = localize('reloadRequired', "Reload Required");
1431 1432 1433 1434 1435 1436 1437 1438 1439
								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.");
1440 1441
							}
						}
1442
					}
1443
					return;
1444 1445 1446 1447 1448
				} 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 已提交
1449
					}
1450
				}
1451
				return;
S
Sandeep Somavarapu 已提交
1452 1453 1454 1455
			}

			// Extension is not running
			else {
1456
				if (isEnabled && !this.extensionService.canAddExtension(toExtensionDescription(this.extension.local))) {
1457
					this.enabled = true;
S
Sandeep Somavarapu 已提交
1458
					this.label = localize('reloadRequired', "Reload Required");
1459
					this.tooltip = localize('postEnableTooltip', "Please reload Visual Studio Code to enable this extension.");
1460
					return;
1461
				}
S
Sandeep Somavarapu 已提交
1462 1463 1464

				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 已提交
1465
					const extensionInOtherServer = this.extensionsWorkbenchService.local.filter(e => areSameExtensions(e.identifier, this.extension!.identifier) && e.server === otherServer)[0];
S
Sandeep Somavarapu 已提交
1466 1467 1468 1469 1470
					// 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.");
1471
						alert(localize('installExtensionCompletedAndReloadRequired', "Installing extension {0} is completed. Please reload Visual Studio Code to enable it.", this.extension.displayName));
S
Sandeep Somavarapu 已提交
1472
						return;
S
Explore  
Sandeep Somavarapu 已提交
1473
					}
1474
				}
1475 1476 1477 1478
			}
		}
	}

S
Sandeep Somavarapu 已提交
1479
	run(): Promise<any> {
1480
		return Promise.resolve(this.hostService.reload());
1481 1482 1483
	}
}

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

1488 1489 1490 1491 1492 1493 1494 1495 1496 1497
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 });
1498
	}
1499 1500 1501 1502 1503
	return picks;
}


export class SetColorThemeAction extends ExtensionAction {
1504

S
Sandeep Somavarapu 已提交
1505
	private static readonly EnabledClass = `${ExtensionAction.LABEL_ACTION_CLASS} theme`;
S
Sandeep Somavarapu 已提交
1506 1507
	private static readonly DisabledClass = `${SetColorThemeAction.EnabledClass} disabled`;

1508 1509 1510 1511 1512 1513 1514 1515 1516 1517
	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 已提交
1518
	constructor(
1519
		private colorThemes: IWorkbenchColorTheme[],
S
Sandeep Somavarapu 已提交
1520 1521 1522 1523 1524
		@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 已提交
1525
		this._register(Event.any<any>(extensionService.onDidChangeExtensions, workbenchThemeService.onDidColorThemeChange)(() => this.update(), this));
S
Sandeep Somavarapu 已提交
1526 1527 1528
		this.update();
	}

1529
	update(): void {
1530
		this.enabled = !!this.extension && (this.extension.state === ExtensionState.Installed) && this.colorThemes.some(th => isThemeFromExtension(th, this.extension));
S
Sandeep Somavarapu 已提交
1531 1532 1533
		this.class = this.enabled ? SetColorThemeAction.EnabledClass : SetColorThemeAction.DisabledClass;
	}

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

1537
		this.update();
S
Sandeep Somavarapu 已提交
1538 1539 1540
		if (!this.enabled) {
			return;
		}
1541
		const currentTheme = this.workbenchThemeService.getColorTheme();
S
Sandeep Somavarapu 已提交
1542 1543

		const delayer = new Delayer<any>(100);
1544
		const picks = getQuickPickEntries(this.colorThemes, currentTheme, this.extension, showCurrentTheme);
S
Sandeep Somavarapu 已提交
1545 1546 1547 1548
		const pickedTheme = await this.quickInputService.pick(
			picks,
			{
				placeHolder: localize('select color theme', "Select Color Theme"),
S
Sandeep Somavarapu 已提交
1549 1550
				onDidFocus: item => delayer.trigger(() => this.workbenchThemeService.setColorTheme(item.id, undefined)),
				ignoreFocusLost
S
Sandeep Somavarapu 已提交
1551
			});
1552
		return this.workbenchThemeService.setColorTheme(pickedTheme ? pickedTheme.id : currentTheme.id, 'auto');
S
Sandeep Somavarapu 已提交
1553 1554 1555 1556 1557
	}
}

export class SetFileIconThemeAction extends ExtensionAction {

S
Sandeep Somavarapu 已提交
1558
	private static readonly EnabledClass = `${ExtensionAction.LABEL_ACTION_CLASS} theme`;
S
Sandeep Somavarapu 已提交
1559 1560
	private static readonly DisabledClass = `${SetFileIconThemeAction.EnabledClass} disabled`;

1561 1562 1563 1564 1565 1566 1567 1568
	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;
1569 1570
	}

S
Sandeep Somavarapu 已提交
1571
	constructor(
1572
		private fileIconThemes: IWorkbenchFileIconTheme[],
S
Sandeep Somavarapu 已提交
1573 1574
		@IExtensionService extensionService: IExtensionService,
		@IWorkbenchThemeService private readonly workbenchThemeService: IWorkbenchThemeService,
1575
		@IQuickInputService private readonly quickInputService: IQuickInputService
S
Sandeep Somavarapu 已提交
1576 1577
	) {
		super(`extensions.fileIconTheme`, localize('file icon theme', "Set File Icon Theme"), SetFileIconThemeAction.DisabledClass, false);
M
Matt Bierner 已提交
1578
		this._register(Event.any<any>(extensionService.onDidChangeExtensions, workbenchThemeService.onDidFileIconThemeChange)(() => this.update(), this));
S
Sandeep Somavarapu 已提交
1579 1580 1581
		this.update();
	}

1582
	update(): void {
1583
		this.enabled = !!this.extension && (this.extension.state === ExtensionState.Installed) && this.fileIconThemes.some(th => isThemeFromExtension(th, this.extension));
S
Sandeep Somavarapu 已提交
1584 1585 1586
		this.class = this.enabled ? SetFileIconThemeAction.EnabledClass : SetFileIconThemeAction.DisabledClass;
	}

S
Sandeep Somavarapu 已提交
1587
	async run({ showCurrentTheme, ignoreFocusLost }: { showCurrentTheme: boolean, ignoreFocusLost: boolean } = { showCurrentTheme: false, ignoreFocusLost: false }): Promise<any> {
1588 1589
		this.fileIconThemes = await this.workbenchThemeService.getFileIconThemes();
		this.update();
S
Sandeep Somavarapu 已提交
1590 1591 1592
		if (!this.enabled) {
			return;
		}
1593
		const currentTheme = this.workbenchThemeService.getFileIconTheme();
S
Sandeep Somavarapu 已提交
1594 1595

		const delayer = new Delayer<any>(100);
1596
		const picks = getQuickPickEntries(this.fileIconThemes, currentTheme, this.extension, showCurrentTheme);
S
Sandeep Somavarapu 已提交
1597 1598 1599 1600
		const pickedTheme = await this.quickInputService.pick(
			picks,
			{
				placeHolder: localize('select file icon theme', "Select File Icon Theme"),
S
Sandeep Somavarapu 已提交
1601 1602
				onDidFocus: item => delayer.trigger(() => this.workbenchThemeService.setFileIconTheme(item.id, undefined)),
				ignoreFocusLost
S
Sandeep Somavarapu 已提交
1603
			});
1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659
		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 已提交
1660 1661 1662
	}
}

B
Benjamin Pasero 已提交
1663
export class OpenExtensionsViewletAction extends ShowViewletAction {
1664 1665 1666 1667 1668 1669 1670 1671

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

	constructor(
		id: string,
		label: string,
		@IViewletService viewletService: IViewletService,
B
Benjamin Pasero 已提交
1672
		@IEditorGroupsService editorGroupService: IEditorGroupsService,
1673
		@IWorkbenchLayoutService layoutService: IWorkbenchLayoutService
1674
	) {
1675
		super(id, label, VIEWLET_ID, viewletService, editorGroupService, layoutService);
1676 1677 1678 1679 1680 1681 1682 1683
	}
}

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

1684 1685
export class ShowEnabledExtensionsAction extends Action {

1686
	static readonly ID = 'workbench.extensions.action.showEnabledExtensions';
1687
	static readonly LABEL = localize('showEnabledExtensions', "Show Enabled Extensions");
1688 1689 1690 1691

	constructor(
		id: string,
		label: string,
1692
		@IViewletService private readonly viewletService: IViewletService
1693
	) {
R
Rob Lourens 已提交
1694
		super(id, label, undefined, true);
1695 1696
	}

J
Johannes Rieken 已提交
1697
	run(): Promise<void> {
1698
		return this.viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
1699
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
1700
			.then(viewlet => {
1701
				viewlet.search('@enabled ');
1702 1703 1704 1705 1706
				viewlet.focus();
			});
	}
}

1707 1708
export class ShowInstalledExtensionsAction extends Action {

1709
	static readonly ID = 'workbench.extensions.action.showInstalledExtensions';
1710
	static readonly LABEL = localize('showInstalledExtensions', "Show Installed Extensions");
1711 1712 1713 1714

	constructor(
		id: string,
		label: string,
1715
		@IViewletService private readonly viewletService: IViewletService
1716
	) {
R
Rob Lourens 已提交
1717
		super(id, label, undefined, true);
1718 1719
	}

S
Sandeep Somavarapu 已提交
1720
	run(): Promise<void> {
1721
		return this.viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
1722
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
1723
			.then(viewlet => {
S
Sandeep Somavarapu 已提交
1724
				viewlet.search('@installed ');
1725 1726 1727 1728 1729 1730 1731
				viewlet.focus();
			});
	}
}

export class ShowDisabledExtensionsAction extends Action {

1732
	static readonly ID = 'workbench.extensions.action.showDisabledExtensions';
1733
	static readonly LABEL = localize('showDisabledExtensions', "Show Disabled Extensions");
1734 1735 1736 1737

	constructor(
		id: string,
		label: string,
1738
		@IViewletService private readonly viewletService: IViewletService
1739 1740 1741 1742
	) {
		super(id, label, 'null', true);
	}

J
Johannes Rieken 已提交
1743
	run(): Promise<void> {
1744
		return this.viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
1745
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
1746 1747 1748 1749 1750 1751 1752
			.then(viewlet => {
				viewlet.search('@disabled ');
				viewlet.focus();
			});
	}
}

S
Sandeep Somavarapu 已提交
1753
export class ClearExtensionsSearchResultsAction extends Action {
1754

S
Sandeep Somavarapu 已提交
1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776
	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 {
1777 1778 1779 1780 1781

	constructor(
		id: string,
		label: string,
		onSearchChange: Event<string>,
1782
		value: string,
S
Sandeep Somavarapu 已提交
1783
		@IViewsService viewsService: IViewsService
1784
	) {
S
Sandeep Somavarapu 已提交
1785
		super(id, label, viewsService);
1786
		this.onSearchChange(value);
M
Matt Bierner 已提交
1787
		this._register(onSearchChange(this.onSearchChange, this));
1788 1789 1790 1791 1792 1793 1794 1795
	}

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

}

S
Sandeep Somavarapu 已提交
1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817
export class RefreshExtensionsAction extends Action {

	static readonly ID = 'workbench.extensions.action.refreshExtension';
	static readonly LABEL = localize('refreshExtension', "Refresh");

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

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

S
Sandeep Somavarapu 已提交
1818 1819 1820
export class ShowBuiltInExtensionsAction extends Action {

	static readonly ID = 'workbench.extensions.action.listBuiltInExtensions';
1821
	static readonly LABEL = localize('showBuiltInExtensions', "Show Built-in Extensions");
S
Sandeep Somavarapu 已提交
1822 1823 1824 1825

	constructor(
		id: string,
		label: string,
1826
		@IViewletService private readonly viewletService: IViewletService
S
Sandeep Somavarapu 已提交
1827
	) {
R
Rob Lourens 已提交
1828
		super(id, label, undefined, true);
S
Sandeep Somavarapu 已提交
1829 1830
	}

J
Johannes Rieken 已提交
1831
	run(): Promise<void> {
S
Sandeep Somavarapu 已提交
1832
		return this.viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
1833
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
S
Sandeep Somavarapu 已提交
1834 1835 1836 1837 1838 1839 1840
			.then(viewlet => {
				viewlet.search('@builtin ');
				viewlet.focus();
			});
	}
}

1841 1842
export class ShowOutdatedExtensionsAction extends Action {

1843
	static readonly ID = 'workbench.extensions.action.listOutdatedExtensions';
1844
	static readonly LABEL = localize('showOutdatedExtensions', "Show Outdated Extensions");
1845 1846 1847 1848

	constructor(
		id: string,
		label: string,
1849
		@IViewletService private readonly viewletService: IViewletService
1850
	) {
R
Rob Lourens 已提交
1851
		super(id, label, undefined, true);
1852 1853
	}

J
Johannes Rieken 已提交
1854
	run(): Promise<void> {
1855
		return this.viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
1856
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
1857 1858 1859 1860 1861 1862 1863 1864 1865
			.then(viewlet => {
				viewlet.search('@outdated ');
				viewlet.focus();
			});
	}
}

export class ShowPopularExtensionsAction extends Action {

1866
	static readonly ID = 'workbench.extensions.action.showPopularExtensions';
1867
	static readonly LABEL = localize('showPopularExtensions', "Show Popular Extensions");
1868 1869 1870 1871

	constructor(
		id: string,
		label: string,
1872
		@IViewletService private readonly viewletService: IViewletService
1873
	) {
R
Rob Lourens 已提交
1874
		super(id, label, undefined, true);
1875 1876
	}

J
Johannes Rieken 已提交
1877
	run(): Promise<void> {
1878
		return this.viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
1879
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
1880
			.then(viewlet => {
S
Sandeep Somavarapu 已提交
1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902
				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} `);
1903 1904 1905 1906 1907
				viewlet.focus();
			});
	}
}

S
Sandeep Somavarapu 已提交
1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930
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();
			});
	}
}

1931 1932
export class ShowRecommendedExtensionsAction extends Action {

1933
	static readonly ID = 'workbench.extensions.action.showRecommendedExtensions';
1934
	static readonly LABEL = localize('showRecommendedExtensions', "Show Recommended Extensions");
1935 1936 1937 1938

	constructor(
		id: string,
		label: string,
1939
		@IViewletService private readonly viewletService: IViewletService
1940
	) {
R
Rob Lourens 已提交
1941
		super(id, label, undefined, true);
1942 1943
	}

J
Johannes Rieken 已提交
1944
	run(): Promise<void> {
1945
		return this.viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
1946
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
1947
			.then(viewlet => {
S
Sandeep Somavarapu 已提交
1948
				viewlet.search('@recommended ');
1949 1950 1951 1952 1953
				viewlet.focus();
			});
	}
}

1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965
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,
	) {
1966
		super(ShowRecommendedExtensionAction.ID, ShowRecommendedExtensionAction.LABEL, undefined, false);
1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987
		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;
					});
			});
	}
}

1988
export class InstallRecommendedExtensionAction extends Action {
1989

1990
	static readonly ID = 'workbench.extensions.action.installRecommendedExtension';
1991
	static readonly LABEL = localize('installRecommendedExtension', "Install Recommended Extension");
1992 1993 1994 1995

	private extensionId: string;

	constructor(
1996
		extensionId: string,
1997 1998
		@IViewletService private readonly viewletService: IViewletService,
		@IInstantiationService private readonly instantiationService: IInstantiationService,
1999
		@IExtensionsWorkbenchService private readonly extensionWorkbenchService: IExtensionsWorkbenchService,
2000
	) {
R
Rob Lourens 已提交
2001
		super(InstallRecommendedExtensionAction.ID, InstallRecommendedExtensionAction.LABEL, undefined, false);
2002 2003 2004
		this.extensionId = extensionId;
	}

S
Sandeep Somavarapu 已提交
2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019
	async run(): Promise<any> {
		const viewlet = await this.viewletService.openViewlet(VIEWLET_ID, true);
		const viewPaneContainer = viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer;
		viewPaneContainer.search(`@id:${this.extensionId}`);
		viewPaneContainer.focus();
		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];
			await this.extensionWorkbenchService.open(extension);
			try {
				await this.extensionWorkbenchService.install(extension);
			} catch (err) {
				this.instantiationService.createInstance(PromptExtensionInstallFailureAction, extension, InstallOperation.Install, err).run();
			}
		}
2020 2021 2022
	}
}

2023 2024 2025 2026
export class IgnoreExtensionRecommendationAction extends Action {

	static readonly ID = 'extensions.ignore';

S
Sandeep Somavarapu 已提交
2027
	private static readonly Class = `${ExtensionAction.LABEL_ACTION_CLASS} ignore`;
2028 2029

	constructor(
S
Sandeep Somavarapu 已提交
2030
		private readonly extension: IExtension,
2031
		@IExtensionIgnoredRecommendationsService private readonly extensionRecommendationsManagementService: IExtensionIgnoredRecommendationsService,
2032
	) {
2033
		super(IgnoreExtensionRecommendationAction.ID, 'Ignore Recommendation');
2034 2035 2036 2037 2038 2039

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

S
Sandeep Somavarapu 已提交
2040
	public run(): Promise<any> {
2041
		this.extensionRecommendationsManagementService.toggleGlobalIgnoredRecommendation(this.extension.identifier.id, true);
2042
		return Promise.resolve();
2043 2044 2045 2046 2047 2048 2049
	}
}

export class UndoIgnoreExtensionRecommendationAction extends Action {

	static readonly ID = 'extensions.ignore';

S
Sandeep Somavarapu 已提交
2050
	private static readonly Class = `${ExtensionAction.LABEL_ACTION_CLASS} undo-ignore`;
2051 2052

	constructor(
S
Sandeep Somavarapu 已提交
2053
		private readonly extension: IExtension,
2054
		@IExtensionIgnoredRecommendationsService private readonly extensionRecommendationsManagementService: IExtensionIgnoredRecommendationsService,
2055 2056 2057 2058 2059 2060 2061 2062
	) {
		super(UndoIgnoreExtensionRecommendationAction.ID, 'Undo');

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

S
Sandeep Somavarapu 已提交
2063
	public run(): Promise<any> {
2064
		this.extensionRecommendationsManagementService.toggleGlobalIgnoredRecommendation(this.extension.identifier.id, false);
2065
		return Promise.resolve();
2066 2067 2068
	}
}

2069 2070
export class ShowRecommendedKeymapExtensionsAction extends Action {

2071
	static readonly ID = 'workbench.extensions.action.showRecommendedKeymapExtensions';
2072
	static readonly LABEL = localize('showRecommendedKeymapExtensionsShort', "Keymaps");
2073 2074 2075 2076

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

J
Johannes Rieken 已提交
2082
	run(): Promise<void> {
2083
		return this.viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
2084
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
2085 2086 2087 2088 2089 2090 2091
			.then(viewlet => {
				viewlet.search('@recommended:keymaps ');
				viewlet.focus();
			});
	}
}

2092
export class ShowLanguageExtensionsAction extends Action {
2093

2094
	static readonly ID = 'workbench.extensions.action.showLanguageExtensions';
2095
	static readonly LABEL = localize('showLanguageExtensionsShort', "Language Extensions");
2096 2097 2098 2099

	constructor(
		id: string,
		label: string,
2100
		@IViewletService private readonly viewletService: IViewletService
2101
	) {
R
Rob Lourens 已提交
2102
		super(id, label, undefined, true);
2103 2104
	}

J
Johannes Rieken 已提交
2105
	run(): Promise<void> {
2106
		return this.viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
2107
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
2108
			.then(viewlet => {
C
Christof Marti 已提交
2109
				viewlet.search('@category:"programming languages" @sort:installs ');
2110 2111 2112 2113 2114
				viewlet.focus();
			});
	}
}

S
Sandeep Somavarapu 已提交
2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126
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> {
2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143
		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 已提交
2144 2145 2146
	}
}

2147 2148 2149 2150 2151 2152 2153 2154 2155
export class ChangeSortAction extends Action {

	private query: Query;

	constructor(
		id: string,
		label: string,
		onSearchChange: Event<string>,
		private sortBy: string,
2156
		@IViewletService private readonly viewletService: IViewletService
2157
	) {
R
Rob Lourens 已提交
2158
		super(id, label, undefined, true);
2159

J
Joao Moreno 已提交
2160
		if (sortBy === undefined) {
2161 2162 2163 2164 2165
			throw new Error('bad arguments');
		}

		this.query = Query.parse('');
		this.enabled = false;
S
Sandeep Somavarapu 已提交
2166
		this.checked = false;
M
Matt Bierner 已提交
2167
		this._register(onSearchChange(this.onSearchChange, this));
2168 2169 2170 2171
	}

	private onSearchChange(value: string): void {
		const query = Query.parse(value);
2172
		this.query = new Query(query.value, this.sortBy || query.sortBy, query.groupBy);
S
Sandeep Somavarapu 已提交
2173 2174
		this.enabled = !!value && this.query.isValid();
		this.checked = this.enabled && this.query.equals(query);
2175 2176
	}

J
Johannes Rieken 已提交
2177
	run(): Promise<void> {
2178
		return this.viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
2179
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
2180 2181 2182 2183 2184 2185 2186
			.then(viewlet => {
				viewlet.search(this.query.toString());
				viewlet.focus();
			});
	}
}

2187 2188 2189 2190 2191 2192
export abstract class AbstractConfigureRecommendedExtensionsAction extends Action {

	constructor(
		id: string,
		label: string,
		@IWorkspaceContextService protected contextService: IWorkspaceContextService,
2193
		@IFileService private readonly fileService: IFileService,
2194
		@ITextFileService private readonly textFileService: ITextFileService,
2195
		@IEditorService protected editorService: IEditorService,
2196 2197
		@IJSONEditingService private readonly jsonEditingService: IJSONEditingService,
		@ITextModelService private readonly textModelResolverService: ITextModelService
2198
	) {
2199
		super(id, label);
2200 2201
	}

S
Sandeep Somavarapu 已提交
2202
	protected openExtensionsFile(extensionsFileResource: URI): Promise<any> {
2203
		return this.getOrCreateExtensionsFile(extensionsFileResource)
S
Sandeep Somavarapu 已提交
2204 2205 2206 2207 2208 2209 2210 2211 2212
			.then(({ created, content }) =>
				this.getSelectionPosition(content, extensionsFileResource, ['recommendations'])
					.then(selection => this.editorService.openEditor({
						resource: extensionsFileResource,
						options: {
							pinned: created,
							selection
						}
					})),
S
Sandeep Somavarapu 已提交
2213
				error => Promise.reject(new Error(localize('OpenExtensionsFile.failed', "Unable to create 'extensions.json' file inside the '.vscode' folder ({0}).", error))));
2214 2215
	}

S
Sandeep Somavarapu 已提交
2216
	protected openWorkspaceConfigurationFile(workspaceConfigurationFile: URI): Promise<any> {
2217
		return this.getOrUpdateWorkspaceConfigurationFile(workspaceConfigurationFile)
B
Benjamin Pasero 已提交
2218
			.then(content => this.getSelectionPosition(content.value.toString(), content.resource, ['extensions', 'recommendations']))
2219 2220 2221
			.then(selection => this.editorService.openEditor({
				resource: workspaceConfigurationFile,
				options: {
B
Benjamin Pasero 已提交
2222 2223
					selection,
					forceReload: true // because content has changed
2224 2225 2226 2227
				}
			}));
	}

B
Benjamin Pasero 已提交
2228 2229
	private getOrUpdateWorkspaceConfigurationFile(workspaceConfigurationFile: URI): Promise<IFileContent> {
		return Promise.resolve(this.fileService.readFile(workspaceConfigurationFile))
2230
			.then(content => {
B
Benjamin Pasero 已提交
2231
				const workspaceRecommendations = <IExtensionsConfigContent>json.parse(content.value.toString())['extensions'];
2232
				if (!workspaceRecommendations || !workspaceRecommendations.recommendations) {
S
Sandeep Somavarapu 已提交
2233
					return this.jsonEditingService.write(workspaceConfigurationFile, [{ path: ['extensions'], value: { recommendations: [] } }], true)
B
Benjamin Pasero 已提交
2234
						.then(() => this.fileService.readFile(workspaceConfigurationFile));
2235 2236 2237 2238 2239
				}
				return content;
			});
	}

J
Johannes Rieken 已提交
2240
	private getSelectionPosition(content: string, resource: URI, path: json.JSONPath): Promise<ITextEditorSelection | undefined> {
S
Sandeep Somavarapu 已提交
2241 2242
		const tree = json.parseTree(content);
		const node = json.findNodeAtLocation(tree, path);
2243
		if (node && node.parent && node.parent.children) {
S
Sandeep Somavarapu 已提交
2244 2245 2246
			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 已提交
2247
			return Promise.resolve(this.textModelResolverService.createModelReference(resource))
2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258
				.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 已提交
2259
		return Promise.resolve(undefined);
2260 2261
	}

S
Sandeep Somavarapu 已提交
2262
	private getOrCreateExtensionsFile(extensionsFileResource: URI): Promise<{ created: boolean, extensionsFileResource: URI, content: string }> {
B
Benjamin Pasero 已提交
2263 2264
		return Promise.resolve(this.fileService.readFile(extensionsFileResource)).then(content => {
			return { created: false, extensionsFileResource, content: content.value.toString() };
2265
		}, err => {
B
Benjamin Pasero 已提交
2266
			return this.textFileService.write(extensionsFileResource, ExtensionsConfigurationInitialContent).then(() => {
S
Sandeep Somavarapu 已提交
2267
				return { created: true, extensionsFileResource, content: ExtensionsConfigurationInitialContent };
2268 2269 2270 2271 2272 2273
			});
		});
	}
}

export class ConfigureWorkspaceRecommendedExtensionsAction extends AbstractConfigureRecommendedExtensionsAction {
2274

2275
	static readonly ID = 'workbench.extensions.action.configureWorkspaceRecommendedExtensions';
2276
	static readonly LABEL = localize('configureWorkspaceRecommendedExtensions', "Configure Recommended Extensions (Workspace)");
2277 2278 2279 2280

	constructor(
		id: string,
		label: string,
2281
		@IFileService fileService: IFileService,
2282
		@ITextFileService textFileService: ITextFileService,
2283
		@IWorkspaceContextService contextService: IWorkspaceContextService,
2284
		@IEditorService editorService: IEditorService,
2285 2286
		@IJSONEditingService jsonEditingService: IJSONEditingService,
		@ITextModelService textModelResolverService: ITextModelService
2287
	) {
2288
		super(id, label, contextService, fileService, textFileService, editorService, jsonEditingService, textModelResolverService);
M
Matt Bierner 已提交
2289
		this._register(this.contextService.onDidChangeWorkbenchState(() => this.update(), this));
2290 2291 2292 2293 2294
		this.update();
	}

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

2297
	public run(): Promise<void> {
2298 2299
		switch (this.contextService.getWorkbenchState()) {
			case WorkbenchState.FOLDER:
2300
				return this.openExtensionsFile(this.contextService.getWorkspace().folders[0].toResource(EXTENSIONS_CONFIG));
2301
			case WorkbenchState.WORKSPACE:
2302
				return this.openWorkspaceConfigurationFile(this.contextService.getWorkspace().configuration!);
2303
		}
2304
		return Promise.resolve();
2305
	}
2306
}
2307

2308 2309
export class ConfigureWorkspaceFolderRecommendedExtensionsAction extends AbstractConfigureRecommendedExtensionsAction {

2310
	static readonly ID = 'workbench.extensions.action.configureWorkspaceFolderRecommendedExtensions';
2311
	static readonly LABEL = localize('configureWorkspaceFolderRecommendedExtensions', "Configure Recommended Extensions (Workspace Folder)");
2312 2313 2314 2315 2316

	constructor(
		id: string,
		label: string,
		@IFileService fileService: IFileService,
2317
		@ITextFileService textFileService: ITextFileService,
2318
		@IWorkspaceContextService contextService: IWorkspaceContextService,
2319
		@IEditorService editorService: IEditorService,
2320
		@IJSONEditingService jsonEditingService: IJSONEditingService,
S
Sandeep Somavarapu 已提交
2321
		@ITextModelService textModelResolverService: ITextModelService,
2322
		@ICommandService private readonly commandService: ICommandService
2323
	) {
2324
		super(id, label, contextService, fileService, textFileService, editorService, jsonEditingService, textModelResolverService);
M
Matt Bierner 已提交
2325
		this._register(this.contextService.onDidChangeWorkspaceFolders(() => this.update(), this));
2326
		this.update();
2327 2328
	}

2329 2330 2331
	private update(): void {
		this.enabled = this.contextService.getWorkspace().folders.length > 0;
	}
2332

S
Sandeep Somavarapu 已提交
2333
	public run(): Promise<any> {
2334
		const folderCount = this.contextService.getWorkspace().folders.length;
S
Sandeep Somavarapu 已提交
2335 2336
		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 已提交
2337 2338
			.then(workspaceFolder => {
				if (workspaceFolder) {
2339
					return this.openExtensionsFile(workspaceFolder.toResource(EXTENSIONS_CONFIG));
2340
				}
S
Sandeep Somavarapu 已提交
2341
				return null;
2342
			});
2343 2344 2345
	}
}

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

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

S
Sandeep Somavarapu 已提交
2351
	private initialStatus: ExtensionState | null = null;
S
#66931  
Sandeep Somavarapu 已提交
2352 2353 2354
	private status: ExtensionState | null = null;
	private enablementState: EnablementState | null = null;

S
Sandeep Somavarapu 已提交
2355 2356 2357
	private _extension: IExtension | null = null;
	get extension(): IExtension | null { return this._extension; }
	set extension(extension: IExtension | null) {
S
Sandeep Somavarapu 已提交
2358
		if (!(this._extension && extension && areSameExtensions(this._extension.identifier, extension.identifier))) {
S
#66931  
Sandeep Somavarapu 已提交
2359
			// Different extension. Reset
S
Sandeep Somavarapu 已提交
2360
			this.initialStatus = null;
S
#66931  
Sandeep Somavarapu 已提交
2361 2362 2363 2364 2365 2366 2367 2368
			this.status = null;
			this.enablementState = null;
		}
		this._extension = extension;
		this.update();
	}

	constructor(
2369 2370
		@IExtensionService private readonly extensionService: IExtensionService,
		@IExtensionManagementServerService private readonly extensionManagementServerService: IExtensionManagementServerService
S
#66931  
Sandeep Somavarapu 已提交
2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390
	) {
		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 已提交
2391 2392 2393
		if (this.initialStatus === null) {
			this.initialStatus = this.status;
		}
S
#66931  
Sandeep Somavarapu 已提交
2394 2395 2396
		this.enablementState = this.extension.enablementState;

		const runningExtensions = await this.extensionService.getExtensions();
S
Sandeep Somavarapu 已提交
2397
		const canAddExtension = () => {
S
Sandeep Somavarapu 已提交
2398 2399 2400
			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 已提交
2401 2402
					return true;
				}
S
Sandeep Somavarapu 已提交
2403
				return this.extensionService.canAddExtension(toExtensionDescription(this.extension!.local));
S
Sandeep Somavarapu 已提交
2404 2405 2406 2407
			}
			return false;
		};
		const canRemoveExtension = () => {
S
Sandeep Somavarapu 已提交
2408
			if (this.extension!.local) {
2409
				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 已提交
2410 2411
					return true;
				}
S
Sandeep Somavarapu 已提交
2412
				return this.extensionService.canRemoveExtension(toExtensionDescription(this.extension!.local));
S
Sandeep Somavarapu 已提交
2413 2414 2415
			}
			return false;
		};
S
#66931  
Sandeep Somavarapu 已提交
2416 2417 2418

		if (currentStatus !== null) {
			if (currentStatus === ExtensionState.Installing && this.status === ExtensionState.Installed) {
S
Sandeep Somavarapu 已提交
2419
				return canAddExtension() ? this.initialStatus === ExtensionState.Installed ? localize('updated', "Updated") : localize('installed', "Installed") : null;
S
#66931  
Sandeep Somavarapu 已提交
2420 2421
			}
			if (currentStatus === ExtensionState.Uninstalling && this.status === ExtensionState.Uninstalled) {
S
Sandeep Somavarapu 已提交
2422
				this.initialStatus = this.status;
S
#66931  
Sandeep Somavarapu 已提交
2423 2424 2425 2426 2427
				return canRemoveExtension() ? localize('uninstalled', "Uninstalled") : null;
			}
		}

		if (currentEnablementState !== null) {
2428 2429
			const currentlyEnabled = currentEnablementState === EnablementState.EnabledGlobally || currentEnablementState === EnablementState.EnabledWorkspace;
			const enabled = this.enablementState === EnablementState.EnabledGlobally || this.enablementState === EnablementState.EnabledWorkspace;
S
#66931  
Sandeep Somavarapu 已提交
2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442
			if (!currentlyEnabled && enabled) {
				return canAddExtension() ? localize('enabled', "Enabled") : null;
			}
			if (currentlyEnabled && !enabled) {
				return canRemoveExtension() ? localize('disabled', "Disabled") : null;
			}

		}

		return null;
	}

	run(): Promise<any> {
2443
		return Promise.resolve();
S
#66931  
Sandeep Somavarapu 已提交
2444 2445 2446 2447
	}

}

S
Sandeep Somavarapu 已提交
2448
export class MaliciousStatusLabelAction extends ExtensionAction {
J
Joao Moreno 已提交
2449

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

	constructor(long: boolean) {
J
Joao Moreno 已提交
2453
		const tooltip = localize('malicious tooltip', "This extension was reported to be problematic.");
2454
		const label = long ? tooltip : localize({ key: 'malicious', comment: ['Refers to a malicious extension'] }, "Malicious");
J
Joao Moreno 已提交
2455
		super('extensions.install', label, '', false);
J
Joao Moreno 已提交
2456
		this.tooltip = localize('malicious tooltip', "This extension was reported to be problematic.");
J
Joao Moreno 已提交
2457 2458
	}

S
Sandeep Somavarapu 已提交
2459
	update(): void {
J
Joao Moreno 已提交
2460 2461 2462 2463 2464 2465 2466
		if (this.extension && this.extension.isMalicious) {
			this.class = `${MaliciousStatusLabelAction.Class} malicious`;
		} else {
			this.class = `${MaliciousStatusLabelAction.Class} not-malicious`;
		}
	}

S
Sandeep Somavarapu 已提交
2467
	run(): Promise<any> {
2468
		return Promise.resolve();
J
Joao Moreno 已提交
2469 2470 2471
	}
}

S
Sandeep Somavarapu 已提交
2472
export class ToggleSyncExtensionAction extends ExtensionDropDownAction {
S
Sandeep Somavarapu 已提交
2473

S
Sandeep Somavarapu 已提交
2474 2475
	private static readonly IGNORED_SYNC_CLASS = `${ExtensionAction.ICON_ACTION_CLASS} extension-sync codicon-sync-ignored`;
	private static readonly SYNC_CLASS = `${ToggleSyncExtensionAction.ICON_ACTION_CLASS} extension-sync codicon-sync`;
S
Sandeep Somavarapu 已提交
2476 2477

	constructor(
2478 2479
		@IConfigurationService private readonly configurationService: IConfigurationService,
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
Sandeep Somavarapu 已提交
2480 2481
		@IUserDataAutoSyncEnablementService private readonly userDataAutoSyncEnablementService: IUserDataAutoSyncEnablementService,
		@IInstantiationService instantiationService: IInstantiationService,
S
Sandeep Somavarapu 已提交
2482
	) {
S
Sandeep Somavarapu 已提交
2483
		super('extensions.sync', '', ToggleSyncExtensionAction.SYNC_CLASS, false, true, instantiationService);
S
Sandeep Somavarapu 已提交
2484
		this._register(Event.filter(this.configurationService.onDidChangeConfiguration, e => e.affectedKeys.includes('settingsSync.ignoredExtensions'))(() => this.update()));
S
Sandeep Somavarapu 已提交
2485
		this._register(userDataAutoSyncEnablementService.onDidChangeEnablement(() => this.update()));
S
Sandeep Somavarapu 已提交
2486 2487 2488 2489
		this.update();
	}

	update(): void {
2490
		this.enabled = !!this.extension && this.userDataAutoSyncEnablementService.isEnabled() && this.extension.state === ExtensionState.Installed;
S
Sandeep Somavarapu 已提交
2491 2492 2493 2494
		if (this.extension) {
			const isIgnored = this.extensionsWorkbenchService.isExtensionIgnoredToSync(this.extension);
			this.class = isIgnored ? ToggleSyncExtensionAction.IGNORED_SYNC_CLASS : ToggleSyncExtensionAction.SYNC_CLASS;
			this.tooltip = isIgnored ? localize('ignored', "This extension is ignored during sync") : localize('synced', "This extension is synced");
2495
		}
S
Sandeep Somavarapu 已提交
2496 2497
	}

S
Sandeep Somavarapu 已提交
2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508
	async run(): Promise<any> {
		return super.run({
			actionGroups: [
				[
					new Action(
						'extensions.syncignore',
						this.extensionsWorkbenchService.isExtensionIgnoredToSync(this.extension!) ? localize('sync', "Sync this extension") : localize('do not sync', "Do not sync this extension")
						, undefined, true, () => this.extensionsWorkbenchService.toggleExtensionIgnoredToSync(this.extension!))
				]
			], disposeActionsOnHide: true
		});
S
Sandeep Somavarapu 已提交
2509 2510 2511
	}
}

S
Sandeep Somavarapu 已提交
2512
export class ExtensionToolTipAction extends ExtensionAction {
2513

S
Sandeep Somavarapu 已提交
2514
	private static readonly Class = `${ExtensionAction.TEXT_ACTION_CLASS} disable-status`;
2515 2516

	updateWhenCounterExtensionChanges: boolean = true;
2517
	private _runningExtensions: IExtensionDescription[] | null = null;
2518

2519 2520
	constructor(
		private readonly warningAction: SystemDisabledWarningAction,
S
Sandeep Somavarapu 已提交
2521
		private readonly reloadAction: ReloadAction,
S
rename  
Sandeep Somavarapu 已提交
2522
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService,
2523
		@IExtensionService private readonly extensionService: IExtensionService,
S
Sandeep Somavarapu 已提交
2524
		@IExtensionManagementServerService private readonly extensionManagementServerService: IExtensionManagementServerService
2525
	) {
S
Sandeep Somavarapu 已提交
2526
		super('extensions.tooltip', warningAction.tooltip, `${ExtensionToolTipAction.Class} hide`, false);
M
Matt Bierner 已提交
2527 2528
		this._register(warningAction.onDidChange(() => this.update(), this));
		this._register(this.extensionService.onDidChangeExtensions(this.updateRunningExtensions, this));
2529 2530 2531 2532 2533
		this.updateRunningExtensions();
	}

	private updateRunningExtensions(): void {
		this.extensionService.getExtensions().then(runningExtensions => { this._runningExtensions = runningExtensions; this.update(); });
2534 2535 2536
	}

	update(): void {
S
Sandeep Somavarapu 已提交
2537 2538 2539 2540
		this.label = this.getTooltip();
		this.class = ExtensionToolTipAction.Class;
		if (!this.label) {
			this.class = `${ExtensionToolTipAction.Class} hide`;
2541
		}
S
Sandeep Somavarapu 已提交
2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552
	}

	private getTooltip(): string {
		if (!this.extension) {
			return '';
		}
		if (this.reloadAction.enabled) {
			return this.reloadAction.tooltip;
		}
		if (this.warningAction.tooltip) {
			return this.warningAction.tooltip;
2553
		}
S
Sandeep Somavarapu 已提交
2554
		if (this.extension && this.extension.local && this.extension.state === ExtensionState.Installed && this._runningExtensions) {
S
Sandeep Somavarapu 已提交
2555
			const isRunning = this._runningExtensions.some(e => areSameExtensions({ id: e.identifier.value, uuid: e.uuid }, this.extension!.identifier));
2556
			const isEnabled = this.extensionEnablementService.isEnabled(this.extension.local);
S
Sandeep Somavarapu 已提交
2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578

			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.");
				}
2579
			}
2580
		}
S
Sandeep Somavarapu 已提交
2581
		return '';
2582 2583 2584 2585 2586 2587 2588 2589 2590
	}

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

export class SystemDisabledWarningAction extends ExtensionAction {

S
Sandeep Somavarapu 已提交
2591
	private static readonly CLASS = `${ExtensionAction.ICON_ACTION_CLASS} system-disable`;
2592 2593
	private static readonly WARNING_CLASS = `${SystemDisabledWarningAction.CLASS} ${Codicon.warning.classNames}`;
	private static readonly INFO_CLASS = `${SystemDisabledWarningAction.CLASS} ${Codicon.info.classNames}`;
2594 2595

	updateWhenCounterExtensionChanges: boolean = true;
2596
	private _runningExtensions: IExtensionDescription[] | null = null;
2597

2598 2599 2600
	constructor(
		@IExtensionManagementServerService private readonly extensionManagementServerService: IExtensionManagementServerService,
		@ILabelService private readonly labelService: ILabelService,
2601
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
2602 2603 2604
		@IExtensionService private readonly extensionService: IExtensionService,
		@IProductService private readonly productService: IProductService,
		@IConfigurationService private readonly configurationService: IConfigurationService,
2605
	) {
2606
		super('extensions.install', '', `${SystemDisabledWarningAction.CLASS} hide`, false);
M
Matt Bierner 已提交
2607 2608
		this._register(this.labelService.onDidChangeFormatters(() => this.update(), this));
		this._register(this.extensionService.onDidChangeExtensions(this.updateRunningExtensions, this));
2609
		this.updateRunningExtensions();
2610 2611 2612
		this.update();
	}

2613 2614 2615 2616
	private updateRunningExtensions(): void {
		this.extensionService.getExtensions().then(runningExtensions => { this._runningExtensions = runningExtensions; this.update(); });
	}

2617
	update(): void {
2618
		this.class = `${SystemDisabledWarningAction.CLASS} hide`;
2619
		this.tooltip = '';
2620 2621 2622 2623 2624
		if (
			!this.extension ||
			!this.extension.local ||
			!this.extension.server ||
			!this._runningExtensions ||
2625
			this.extension.state !== ExtensionState.Installed
2626
		) {
2627 2628
			return;
		}
2629 2630 2631 2632 2633
		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 已提交
2634 2635
						? 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.");
2636 2637
				}
				return;
2638 2639
			}
		}
S
Sandeep Somavarapu 已提交
2640
		if (this.extension.enablementState === EnablementState.DisabledByExtensionKind) {
S
Sandeep Somavarapu 已提交
2641
			if (!this.extensionsWorkbenchService.installed.some(e => areSameExtensions(e.identifier, this.extension!.identifier) && e.server !== this.extension!.server)) {
S
Sandeep Somavarapu 已提交
2642
				const server = this.extensionManagementServerService.localExtensionManagementServer === this.extension.server ? this.extensionManagementServerService.remoteExtensionManagementServer : this.extensionManagementServerService.localExtensionManagementServer;
2643
				this.class = `${SystemDisabledWarningAction.WARNING_CLASS}`;
2644 2645 2646
				if (server) {
					this.tooltip = localize('Install in other server to enable', "Install the extension on '{0}' to enable.", server.label);
				} else {
S
Sandeep Somavarapu 已提交
2647
					this.tooltip = localize('disabled because of extension kind', "This extension has defined that it cannot run on the remote server");
2648
				}
S
Sandeep Somavarapu 已提交
2649 2650
				return;
			}
2651
		}
2652 2653
		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];
2654
			const runningExtensionServer = runningExtension ? this.extensionManagementServerService.getExtensionManagementServer(toExtension(runningExtension)) : null;
2655 2656 2657 2658 2659 2660
			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;
2661
			}
2662 2663 2664 2665 2666 2667
			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;
2668
			}
2669 2670 2671 2672 2673 2674 2675 2676
		}
	}

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

2677 2678
export class DisableAllAction extends Action {

2679
	static readonly ID = 'workbench.extensions.action.disableAll';
2680
	static readonly LABEL = localize('disableAll', "Disable All Installed Extensions");
2681 2682

	constructor(
S
Sandeep Somavarapu 已提交
2683
		id: string, label: string, isPrimary: boolean,
2684
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
rename  
Sandeep Somavarapu 已提交
2685
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService
2686 2687
	) {
		super(id, label);
S
Sandeep Somavarapu 已提交
2688 2689 2690
		if (isPrimary) {
			this._register(this.extensionsWorkbenchService.onChange(() => this._onDidChange.fire({ enabled: this.enabled })));
		}
2691 2692
	}

S
Sandeep Somavarapu 已提交
2693
	private getExtensionsToDisable(): IExtension[] {
2694
		return this.extensionsWorkbenchService.local.filter(e => !e.isBuiltin && !!e.local && this.extensionEnablementService.isEnabled(e.local) && this.extensionEnablementService.canChangeEnablement(e.local));
S
Sandeep Somavarapu 已提交
2695 2696
	}

S
Sandeep Somavarapu 已提交
2697 2698
	get enabled(): boolean {
		return this.getExtensionsToDisable().length > 0;
2699 2700
	}

S
Sandeep Somavarapu 已提交
2701
	run(): Promise<any> {
S
Sandeep Somavarapu 已提交
2702
		return this.extensionsWorkbenchService.setEnablement(this.getExtensionsToDisable(), EnablementState.DisabledGlobally);
2703 2704 2705
	}
}

2706
export class DisableAllWorkspaceAction extends Action {
2707

2708
	static readonly ID = 'workbench.extensions.action.disableAllWorkspace';
2709
	static readonly LABEL = localize('disableAllWorkspace', "Disable All Installed Extensions for this Workspace");
2710 2711

	constructor(
S
Sandeep Somavarapu 已提交
2712
		id: string, label: string, isPrimary: boolean,
2713
		@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService,
2714
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
rename  
Sandeep Somavarapu 已提交
2715
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService
2716 2717
	) {
		super(id, label);
S
Sandeep Somavarapu 已提交
2718 2719 2720
		if (isPrimary) {
			this._register(Event.any(this.workspaceContextService.onDidChangeWorkbenchState, this.extensionsWorkbenchService.onChange)(() => this._onDidChange.fire({ enabled: this.enabled })));
		}
2721 2722
	}

S
Sandeep Somavarapu 已提交
2723
	private getExtensionsToDisable(): IExtension[] {
2724
		return this.extensionsWorkbenchService.local.filter(e => !e.isBuiltin && !!e.local && this.extensionEnablementService.isEnabled(e.local) && this.extensionEnablementService.canChangeEnablement(e.local));
S
Sandeep Somavarapu 已提交
2725 2726
	}

S
Sandeep Somavarapu 已提交
2727 2728
	get enabled(): boolean {
		return this.getExtensionsToDisable().length > 0;
2729 2730
	}

S
Sandeep Somavarapu 已提交
2731
	run(): Promise<any> {
S
Sandeep Somavarapu 已提交
2732
		return this.extensionsWorkbenchService.setEnablement(this.getExtensionsToDisable(), EnablementState.DisabledWorkspace);
2733 2734 2735 2736 2737
	}
}

export class EnableAllAction extends Action {

2738
	static readonly ID = 'workbench.extensions.action.enableAll';
2739
	static readonly LABEL = localize('enableAll', "Enable All Extensions");
2740 2741

	constructor(
S
Sandeep Somavarapu 已提交
2742
		id: string, label: string, isPrimary: boolean,
2743
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
rename  
Sandeep Somavarapu 已提交
2744
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService
2745 2746
	) {
		super(id, label);
S
Sandeep Somavarapu 已提交
2747 2748 2749
		if (isPrimary) {
			this._register(this.extensionsWorkbenchService.onChange(() => this._onDidChange.fire({ enabled: this.enabled })));
		}
2750 2751
	}

S
Sandeep Somavarapu 已提交
2752 2753 2754 2755
	private getExtensionsToEnable(): IExtension[] {
		return this.extensionsWorkbenchService.local.filter(e => !!e.local && this.extensionEnablementService.canChangeEnablement(e.local) && !this.extensionEnablementService.isEnabled(e.local));
	}

S
Sandeep Somavarapu 已提交
2756 2757
	get enabled(): boolean {
		return this.getExtensionsToEnable().length > 0;
2758 2759
	}

S
Sandeep Somavarapu 已提交
2760
	run(): Promise<any> {
S
Sandeep Somavarapu 已提交
2761
		return this.extensionsWorkbenchService.setEnablement(this.getExtensionsToEnable(), EnablementState.EnabledGlobally);
2762 2763 2764
	}
}

2765
export class EnableAllWorkspaceAction extends Action {
2766

2767
	static readonly ID = 'workbench.extensions.action.enableAllWorkspace';
2768
	static readonly LABEL = localize('enableAllWorkspace', "Enable All Extensions for this Workspace");
2769 2770

	constructor(
S
Sandeep Somavarapu 已提交
2771
		id: string, label: string, isPrimary: boolean,
2772 2773
		@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService,
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
rename  
Sandeep Somavarapu 已提交
2774
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService
2775 2776
	) {
		super(id, label);
S
Sandeep Somavarapu 已提交
2777 2778 2779
		if (isPrimary) {
			this._register(Event.any(this.workspaceContextService.onDidChangeWorkbenchState, this.extensionsWorkbenchService.onChange)(() => this._onDidChange.fire({ enabled: this.enabled })));
		}
2780 2781
	}

S
Sandeep Somavarapu 已提交
2782 2783 2784 2785
	private getExtensionsToEnable(): IExtension[] {
		return this.extensionsWorkbenchService.local.filter(e => !!e.local && this.extensionEnablementService.canChangeEnablement(e.local) && !this.extensionEnablementService.isEnabled(e.local));
	}

S
Sandeep Somavarapu 已提交
2786 2787
	get enabled(): boolean {
		return this.getExtensionsToEnable().length > 0;
2788 2789
	}

S
Sandeep Somavarapu 已提交
2790
	run(): Promise<any> {
S
Sandeep Somavarapu 已提交
2791
		return this.extensionsWorkbenchService.setEnablement(this.getExtensionsToEnable(), EnablementState.EnabledWorkspace);
2792
	}
2793 2794
}

J
Joao Moreno 已提交
2795 2796 2797
export class InstallVSIXAction extends Action {

	static readonly ID = 'workbench.extensions.action.installVSIX';
2798
	static readonly LABEL = localize('installVSIX', "Install from VSIX...");
J
Joao Moreno 已提交
2799 2800 2801 2802

	constructor(
		id = InstallVSIXAction.ID,
		label = InstallVSIXAction.LABEL,
2803
		@IFileDialogService private readonly fileDialogService: IFileDialogService,
2804
		@ICommandService private readonly commandService: ICommandService
J
Joao Moreno 已提交
2805
	) {
S
Sandeep Somavarapu 已提交
2806
		super(id, label, 'extension-action install-vsix', true);
J
Joao Moreno 已提交
2807 2808
	}

2809 2810 2811 2812 2813
	async run(): Promise<void> {
		const vsixPaths = await this.fileDialogService.showOpenDialog({
			title: localize('installFromVSIX', "Install from VSIX"),
			filters: [{ name: 'VSIX Extensions', extensions: ['vsix'] }],
			canSelectFiles: true,
S
Sandeep Somavarapu 已提交
2814
			canSelectMany: true,
2815 2816
			openLabel: mnemonicButtonLabel(localize({ key: 'installButton', comment: ['&& denotes a mnemonic'] }, "&&Install"))
		});
2817

2818 2819
		if (!vsixPaths) {
			return;
2820
		}
J
Joao Moreno 已提交
2821

2822
		// Install extension(s), display notification(s), display @installed extensions
2823
		await this.commandService.executeCommand(INSTALL_EXTENSION_FROM_VSIX_COMMAND_ID, vsixPaths);
J
Joao Moreno 已提交
2824 2825 2826 2827 2828 2829
	}
}

export class ReinstallAction extends Action {

	static readonly ID = 'workbench.extensions.action.reinstall';
2830
	static readonly LABEL = localize('reinstall', "Reinstall Extension...");
J
Joao Moreno 已提交
2831 2832 2833

	constructor(
		id: string = ReinstallAction.ID, label: string = ReinstallAction.LABEL,
2834 2835 2836
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
		@IQuickInputService private readonly quickInputService: IQuickInputService,
		@INotificationService private readonly notificationService: INotificationService,
2837
		@IHostService private readonly hostService: IHostService,
S
Sandeep Somavarapu 已提交
2838 2839
		@IInstantiationService private readonly instantiationService: IInstantiationService,
		@IExtensionService private readonly extensionService: IExtensionService
J
Joao Moreno 已提交
2840 2841 2842 2843 2844
	) {
		super(id, label);
	}

	get enabled(): boolean {
2845
		return this.extensionsWorkbenchService.local.filter(l => !l.isBuiltin && l.local).length > 0;
J
Joao Moreno 已提交
2846 2847
	}

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

J
Johannes Rieken 已提交
2853
	private getEntries(): Promise<(IQuickPickItem & { extension: IExtension })[]> {
J
Joao Moreno 已提交
2854 2855
		return this.extensionsWorkbenchService.queryLocal()
			.then(local => {
C
Christof Marti 已提交
2856
				const entries = local
2857
					.filter(extension => !extension.isBuiltin)
J
Joao Moreno 已提交
2858
					.map(extension => {
C
Christof Marti 已提交
2859
						return {
S
Sandeep Somavarapu 已提交
2860
							id: extension.identifier.id,
J
Joao Moreno 已提交
2861
							label: extension.displayName,
S
Sandeep Somavarapu 已提交
2862
							description: extension.identifier.id,
C
Christof Marti 已提交
2863 2864
							extension,
						} as (IQuickPickItem & { extension: IExtension });
J
Joao Moreno 已提交
2865 2866 2867 2868 2869
					});
				return entries;
			});
	}

J
Johannes Rieken 已提交
2870
	private reinstallExtension(extension: IExtension): Promise<void> {
S
Sandeep Somavarapu 已提交
2871 2872
		return this.instantiationService.createInstance(ShowInstalledExtensionsAction, ShowInstalledExtensionsAction.ID, ShowInstalledExtensionsAction.LABEL).run()
			.then(() => {
2873
				return this.extensionsWorkbenchService.reinstall(extension)
S
Sandeep Somavarapu 已提交
2874 2875 2876 2877 2878 2879
					.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"),
2880
							run: () => this.hostService.reload()
S
Sandeep Somavarapu 已提交
2881
						}] : [];
2882 2883
						this.notificationService.prompt(
							Severity.Info,
S
Sandeep Somavarapu 已提交
2884 2885
							message,
							actions,
2886 2887 2888 2889
							{ sticky: true }
						);
					}, error => this.notificationService.error(error));
			});
J
Joao Moreno 已提交
2890 2891 2892
	}
}

S
Sandeep Somavarapu 已提交
2893
export class InstallSpecificVersionOfExtensionAction extends Action {
2894

S
Sandeep Somavarapu 已提交
2895
	static readonly ID = 'workbench.extensions.action.install.specificVersion';
2896
	static readonly LABEL = localize('install previous version', "Install Specific Version of Extension...");
2897 2898

	constructor(
S
Sandeep Somavarapu 已提交
2899
		id: string = InstallSpecificVersionOfExtensionAction.ID, label: string = InstallSpecificVersionOfExtensionAction.LABEL,
2900 2901 2902 2903
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
		@IExtensionGalleryService private readonly extensionGalleryService: IExtensionGalleryService,
		@IQuickInputService private readonly quickInputService: IQuickInputService,
		@INotificationService private readonly notificationService: INotificationService,
2904
		@IHostService private readonly hostService: IHostService,
S
Sandeep Somavarapu 已提交
2905
		@IInstantiationService private readonly instantiationService: IInstantiationService,
2906
		@IExtensionService private readonly extensionService: IExtensionService,
S
rename  
Sandeep Somavarapu 已提交
2907
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService,
2908 2909 2910 2911 2912
	) {
		super(id, label);
	}

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

S
Sandeep Somavarapu 已提交
2916 2917 2918
	async run(): Promise<any> {
		const extensionPick = await this.quickInputService.pick(this.getExtensionEntries(), { placeHolder: localize('selectExtension', "Select Extension"), matchOnDetail: true });
		if (extensionPick && extensionPick.extension) {
2919
			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 已提交
2920 2921
			if (versionPick) {
				if (extensionPick.extension.version !== versionPick.id) {
2922
					await this.install(extensionPick.extension, versionPick.id);
S
Sandeep Somavarapu 已提交
2923 2924
				}
			}
S
Sandeep Somavarapu 已提交
2925 2926 2927 2928
		}
	}

	private isEnabled(extension: IExtension): boolean {
2929
		return !!extension.gallery && !!extension.local && this.extensionEnablementService.isEnabled(extension.local);
2930 2931
	}

S
Sandeep Somavarapu 已提交
2932
	private async getExtensionEntries(): Promise<(IQuickPickItem & { extension: IExtension, versions: IGalleryExtensionVersion[] })[]> {
2933
		const installed = await this.extensionsWorkbenchService.queryLocal();
2934
		const versionsPromises: Promise<{ extension: IExtension, versions: IGalleryExtensionVersion[] } | null>[] = [];
2935
		for (const extension of installed) {
S
Sandeep Somavarapu 已提交
2936
			if (this.isEnabled(extension)) {
2937
				versionsPromises.push(this.extensionGalleryService.getAllVersions(extension.gallery!, true)
S
Sandeep Somavarapu 已提交
2938
					.then(versions => (versions.length ? { extension, versions } : null)));
2939 2940 2941
			}
		}

S
Sandeep Somavarapu 已提交
2942
		const extensions = await Promise.all(versionsPromises);
M
Matt Bierner 已提交
2943
		return coalesce(extensions)
2944
			.sort((e1, e2) => e1.extension.displayName.localeCompare(e2.extension.displayName))
S
Sandeep Somavarapu 已提交
2945
			.map(({ extension, versions }) => {
2946
				return {
S
Sandeep Somavarapu 已提交
2947 2948 2949
					id: extension.identifier.id,
					label: extension.displayName || extension.identifier.id,
					description: extension.identifier.id,
2950
					extension,
S
Sandeep Somavarapu 已提交
2951 2952
					versions
				} as (IQuickPickItem & { extension: IExtension, versions: IGalleryExtensionVersion[] });
2953 2954 2955
			});
	}

J
Johannes Rieken 已提交
2956
	private install(extension: IExtension, version: string): Promise<void> {
S
Sandeep Somavarapu 已提交
2957 2958
		return this.instantiationService.createInstance(ShowInstalledExtensionsAction, ShowInstalledExtensionsAction.ID, ShowInstalledExtensionsAction.LABEL).run()
			.then(() => {
2959
				return this.extensionsWorkbenchService.installVersion(extension, version)
S
Sandeep Somavarapu 已提交
2960 2961 2962 2963 2964 2965
					.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"),
2966
							run: () => this.hostService.reload()
S
Sandeep Somavarapu 已提交
2967
						}] : [];
2968 2969
						this.notificationService.prompt(
							Severity.Info,
S
Sandeep Somavarapu 已提交
2970 2971
							message,
							actions,
2972 2973 2974 2975
							{ sticky: true }
						);
					}, error => this.notificationService.error(error));
			});
J
Joao Moreno 已提交
2976 2977 2978
	}
}

2979 2980 2981 2982
interface IExtensionPickItem extends IQuickPickItem {
	extension?: IExtension;
}

S
Sandeep Somavarapu 已提交
2983
export abstract class AbstractInstallExtensionsInServerAction extends Action {
2984

2985 2986
	private extensions: IExtension[] | undefined = undefined;

2987
	constructor(
S
Sandeep Somavarapu 已提交
2988 2989
		id: string,
		@IExtensionsWorkbenchService protected readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
2990 2991
		@IQuickInputService private readonly quickInputService: IQuickInputService,
		@INotificationService private readonly notificationService: INotificationService,
2992
		@IProgressService private readonly progressService: IProgressService,
2993
	) {
S
Sandeep Somavarapu 已提交
2994
		super(id);
2995
		this.update();
2996 2997 2998 2999 3000 3001
		this.extensionsWorkbenchService.queryLocal().then(() => this.updateExtensions());
		this._register(this.extensionsWorkbenchService.onChange(() => {
			if (this.extensions) {
				this.updateExtensions();
			}
		}));
3002 3003
	}

3004 3005 3006 3007 3008
	private updateExtensions(): void {
		this.extensions = this.extensionsWorkbenchService.local;
		this.update();
	}

3009
	private update(): void {
3010
		this.enabled = !!this.extensions && this.getExtensionsToInstall(this.extensions).length > 0;
S
Sandeep Somavarapu 已提交
3011
		this.tooltip = this.label;
3012 3013
	}

3014
	async run(): Promise<void> {
S
Sandeep Somavarapu 已提交
3015
		return this.selectAndInstallExtensions();
3016 3017 3018 3019 3020 3021 3022
	}

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

S
Sandeep Somavarapu 已提交
3023
	private async selectAndInstallExtensions(): Promise<void> {
3024 3025 3026 3027 3028 3029 3030 3031 3032
		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();
3033
		const localExtensionsToInstall = await this.queryExtensionsToInstall();
3034 3035
		quickPick.busy = false;
		if (localExtensionsToInstall.length) {
S
Sandeep Somavarapu 已提交
3036
			quickPick.title = this.getQuickPickTitle();
3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047
			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.")
			});
3048 3049 3050
		}
	}

S
Sandeep Somavarapu 已提交
3051
	private async onDidAccept(selectedItems: ReadonlyArray<IExtensionPickItem>): Promise<void> {
3052 3053
		if (selectedItems.length) {
			const localExtensionsToInstall = selectedItems.filter(r => !!r.extension).map(r => r.extension!);
3054
			if (localExtensionsToInstall.length) {
S
Sandeep Somavarapu 已提交
3055
				await this.progressService.withProgress(
3056 3057 3058 3059
					{
						location: ProgressLocation.Notification,
						title: localize('installing extensions', "Installing Extensions...")
					},
S
Sandeep Somavarapu 已提交
3060 3061
					() => this.installExtensions(localExtensionsToInstall));
				this.notificationService.info(localize('finished installing', "Successfully installed extensions."));
3062 3063 3064 3065
			}
		}
	}

S
Sandeep Somavarapu 已提交
3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104
	protected abstract getQuickPickTitle(): string;
	protected abstract getExtensionsToInstall(local: IExtension[]): IExtension[];
	protected abstract installExtensions(extensions: IExtension[]): Promise<void>;
}

export class InstallLocalExtensionsInRemoteAction extends AbstractInstallExtensionsInServerAction {

	constructor(
		@IExtensionsWorkbenchService extensionsWorkbenchService: IExtensionsWorkbenchService,
		@IQuickInputService quickInputService: IQuickInputService,
		@IProgressService progressService: IProgressService,
		@INotificationService notificationService: INotificationService,
		@IExtensionManagementServerService private readonly extensionManagementServerService: IExtensionManagementServerService,
		@IExtensionGalleryService private readonly extensionGalleryService: IExtensionGalleryService,
		@IInstantiationService private readonly instantiationService: IInstantiationService
	) {
		super('workbench.extensions.actions.installLocalExtensionsInRemote', extensionsWorkbenchService, quickInputService, notificationService, progressService);
	}

	get label(): string {
		if (this.extensionManagementServerService && this.extensionManagementServerService.remoteExtensionManagementServer) {
			return localize('select and install local extensions', "Install Local Extensions in '{0}'...", this.extensionManagementServerService.remoteExtensionManagementServer.label);
		}
		return '';
	}

	protected getQuickPickTitle(): string {
		return localize('install local extensions title', "Install Local Extensions in '{0}'", this.extensionManagementServerService.remoteExtensionManagementServer!.label);
	}

	protected getExtensionsToInstall(local: IExtension[]): IExtension[] {
		return local.filter(extension => {
			const action = this.instantiationService.createInstance(RemoteInstallAction, true);
			action.extension = extension;
			return action.enabled;
		});
	}

	protected async installExtensions(localExtensionsToInstall: IExtension[]): Promise<void> {
3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120
		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)));
S
Sandeep Somavarapu 已提交
3121 3122 3123 3124
	}
}

export class InstallRemoteExtensionsInLocalAction extends AbstractInstallExtensionsInServerAction {
3125

S
Sandeep Somavarapu 已提交
3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161
	constructor(
		id: string,
		@IExtensionsWorkbenchService extensionsWorkbenchService: IExtensionsWorkbenchService,
		@IQuickInputService quickInputService: IQuickInputService,
		@IProgressService progressService: IProgressService,
		@INotificationService notificationService: INotificationService,
		@IExtensionManagementServerService private readonly extensionManagementServerService: IExtensionManagementServerService,
		@IExtensionGalleryService private readonly extensionGalleryService: IExtensionGalleryService,
	) {
		super(id, extensionsWorkbenchService, quickInputService, notificationService, progressService);
	}

	get label(): string {
		return localize('select and install remote extensions', "Install Remote Extensions Locally...");
	}

	protected getQuickPickTitle(): string {
		return localize('install remote extensions', "Install Remote Extensions Locally");
	}

	protected getExtensionsToInstall(local: IExtension[]): IExtension[] {
		return local.filter(extension =>
			extension.type === ExtensionType.User && extension.server !== this.extensionManagementServerService.localExtensionManagementServer
			&& !this.extensionsWorkbenchService.installed.some(e => e.server === this.extensionManagementServerService.localExtensionManagementServer && areSameExtensions(e.identifier, extension.identifier)));
	}

	protected async installExtensions(extensions: IExtension[]): Promise<void> {
		const galleryExtensions: IGalleryExtension[] = [];
		const vsixs: URI[] = [];
		await Promise.all(extensions.map(async extension => {
			if (this.extensionGalleryService.isEnabled()) {
				const gallery = await this.extensionGalleryService.getCompatibleExtension(extension.identifier, extension.version);
				if (gallery) {
					galleryExtensions.push(gallery);
					return;
				}
3162
			}
S
Sandeep Somavarapu 已提交
3163 3164 3165 3166 3167 3168
			const vsix = await this.extensionManagementServerService.remoteExtensionManagementServer!.extensionManagementService.zip(extension.local!);
			vsixs.push(vsix);
		}));

		await Promise.all(galleryExtensions.map(gallery => this.extensionManagementServerService.localExtensionManagementServer!.extensionManagementService.installFromGallery(gallery)));
		await Promise.all(vsixs.map(vsix => this.extensionManagementServerService.localExtensionManagementServer!.extensionManagementService.install(vsix)));
3169 3170 3171
	}
}

S
Sandeep Somavarapu 已提交
3172
CommandsRegistry.registerCommand('workbench.extensions.action.showExtensionsForLanguage', function (accessor: ServicesAccessor, fileExtension: string) {
3173 3174 3175
	const viewletService = accessor.get(IViewletService);

	return viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
3176
		.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
3177 3178 3179 3180 3181
		.then(viewlet => {
			viewlet.search(`ext:${fileExtension.replace(/^\./, '')}`);
			viewlet.focus();
		});
});
B
Benjamin Pasero 已提交
3182

3183
CommandsRegistry.registerCommand('workbench.extensions.action.showExtensionsWithIds', function (accessor: ServicesAccessor, extensionIds: string[]) {
3184 3185 3186
	const viewletService = accessor.get(IViewletService);

	return viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
3187
		.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
3188
		.then(viewlet => {
3189 3190 3191 3192
			const query = extensionIds
				.map(id => `@id:${id}`)
				.join(' ');
			viewlet.search(query);
3193 3194 3195 3196
			viewlet.focus();
		});
});

B
Benjamin Pasero 已提交
3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214
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 已提交
3215
registerThemingParticipant((theme: IColorTheme, collector: ICssStyleCollector) => {
B
Benjamin Pasero 已提交
3216 3217
	const foregroundColor = theme.getColor(foreground);
	if (foregroundColor) {
3218
		collector.addRule(`.extension-list-item .monaco-action-bar .action-item .action-label.extension-action.built-in-status { border-color: ${foregroundColor}; }`);
3219
		collector.addRule(`.extension-editor .monaco-action-bar .action-item .action-label.extension-action.built-in-status { border-color: ${foregroundColor}; }`);
B
Benjamin Pasero 已提交
3220 3221
	}

B
Benjamin Pasero 已提交
3222 3223
	const buttonBackgroundColor = theme.getColor(buttonBackground);
	if (buttonBackgroundColor) {
S
Sandeep Somavarapu 已提交
3224 3225
		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 已提交
3226 3227 3228 3229
	}

	const buttonForegroundColor = theme.getColor(buttonForeground);
	if (buttonForegroundColor) {
S
Sandeep Somavarapu 已提交
3230 3231
		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 已提交
3232 3233 3234 3235
	}

	const buttonHoverBackgroundColor = theme.getColor(buttonHoverBackground);
	if (buttonHoverBackgroundColor) {
S
Sandeep Somavarapu 已提交
3236 3237
		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 已提交
3238 3239 3240 3241
	}

	const extensionButtonProminentBackgroundColor = theme.getColor(extensionButtonProminentBackground);
	if (extensionButtonProminentBackground) {
S
Sandeep Somavarapu 已提交
3242 3243
		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 已提交
3244 3245 3246 3247
	}

	const extensionButtonProminentForegroundColor = theme.getColor(extensionButtonProminentForeground);
	if (extensionButtonProminentForeground) {
S
Sandeep Somavarapu 已提交
3248 3249
		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 已提交
3250 3251 3252 3253
	}

	const extensionButtonProminentHoverBackgroundColor = theme.getColor(extensionButtonProminentHoverBackground);
	if (extensionButtonProminentHoverBackground) {
S
Sandeep Somavarapu 已提交
3254 3255 3256 3257 3258 3259
		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) {
S
Sandeep Somavarapu 已提交
3260 3261
		collector.addRule(`.extension-list-item .monaco-action-bar .action-item .action-label.extension-action:not(.disabled) { border: 1px solid ${contrastBorderColor}; }`);
		collector.addRule(`.extension-editor .monaco-action-bar .action-item .action-label.extension-action:not(.disabled) { border: 1px solid ${contrastBorderColor}; }`);
B
Benjamin Pasero 已提交
3262
	}
A
Alex Dima 已提交
3263
});