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

6
import '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
	}

1720
	run(refresh?: boolean): Promise<void> {
1721
		return this.viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
1722
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
1723
			.then(viewlet => {
1724
				viewlet.search('@installed ', refresh);
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
export class ShowBuiltInExtensionsAction extends Action {

	static readonly ID = 'workbench.extensions.action.listBuiltInExtensions';
1799
	static readonly LABEL = localize('showBuiltInExtensions', "Show Built-in Extensions");
S
Sandeep Somavarapu 已提交
1800 1801 1802 1803

	constructor(
		id: string,
		label: string,
1804
		@IViewletService private readonly viewletService: IViewletService
S
Sandeep Somavarapu 已提交
1805
	) {
R
Rob Lourens 已提交
1806
		super(id, label, undefined, true);
S
Sandeep Somavarapu 已提交
1807 1808
	}

J
Johannes Rieken 已提交
1809
	run(): Promise<void> {
S
Sandeep Somavarapu 已提交
1810
		return this.viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
1811
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
S
Sandeep Somavarapu 已提交
1812 1813 1814 1815 1816 1817 1818
			.then(viewlet => {
				viewlet.search('@builtin ');
				viewlet.focus();
			});
	}
}

1819 1820
export class ShowOutdatedExtensionsAction extends Action {

1821
	static readonly ID = 'workbench.extensions.action.listOutdatedExtensions';
1822
	static readonly LABEL = localize('showOutdatedExtensions', "Show Outdated Extensions");
1823 1824 1825 1826

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

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

export class ShowPopularExtensionsAction extends Action {

1844
	static readonly ID = 'workbench.extensions.action.showPopularExtensions';
1845
	static readonly LABEL = localize('showPopularExtensions', "Show Popular Extensions");
1846 1847 1848 1849

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

J
Johannes Rieken 已提交
1855
	run(): Promise<void> {
1856
		return this.viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
1857
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
1858
			.then(viewlet => {
S
Sandeep Somavarapu 已提交
1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880
				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} `);
1881 1882 1883 1884 1885
				viewlet.focus();
			});
	}
}

S
Sandeep Somavarapu 已提交
1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908
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();
			});
	}
}

1909 1910
export class ShowRecommendedExtensionsAction extends Action {

1911
	static readonly ID = 'workbench.extensions.action.showRecommendedExtensions';
1912
	static readonly LABEL = localize('showRecommendedExtensions', "Show Recommended Extensions");
1913 1914 1915 1916

	constructor(
		id: string,
		label: string,
1917
		@IViewletService private readonly viewletService: IViewletService
1918
	) {
R
Rob Lourens 已提交
1919
		super(id, label, undefined, true);
1920 1921
	}

J
Johannes Rieken 已提交
1922
	run(): Promise<void> {
1923
		return this.viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
1924
			.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
1925
			.then(viewlet => {
S
Sandeep Somavarapu 已提交
1926
				viewlet.search('@recommended ', true);
1927 1928 1929 1930 1931
				viewlet.focus();
			});
	}
}

1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943
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,
	) {
1944
		super(ShowRecommendedExtensionAction.ID, ShowRecommendedExtensionAction.LABEL, undefined, false);
1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965
		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;
					});
			});
	}
}

1966
export class InstallRecommendedExtensionAction extends Action {
1967

1968
	static readonly ID = 'workbench.extensions.action.installRecommendedExtension';
1969
	static readonly LABEL = localize('installRecommendedExtension', "Install Recommended Extension");
1970 1971 1972 1973

	private extensionId: string;

	constructor(
1974
		extensionId: string,
1975 1976
		@IViewletService private readonly viewletService: IViewletService,
		@IInstantiationService private readonly instantiationService: IInstantiationService,
1977
		@IExtensionsWorkbenchService private readonly extensionWorkbenchService: IExtensionsWorkbenchService,
1978
	) {
R
Rob Lourens 已提交
1979
		super(InstallRecommendedExtensionAction.ID, InstallRecommendedExtensionAction.LABEL, undefined, false);
1980 1981 1982
		this.extensionId = extensionId;
	}

S
Sandeep Somavarapu 已提交
1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997
	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();
			}
		}
1998 1999 2000
	}
}

2001 2002 2003 2004
export class IgnoreExtensionRecommendationAction extends Action {

	static readonly ID = 'extensions.ignore';

S
Sandeep Somavarapu 已提交
2005
	private static readonly Class = `${ExtensionAction.LABEL_ACTION_CLASS} ignore`;
2006 2007

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

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

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

export class UndoIgnoreExtensionRecommendationAction extends Action {

	static readonly ID = 'extensions.ignore';

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

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

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

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

2047 2048
export class ShowRecommendedKeymapExtensionsAction extends Action {

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

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

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

2070
export class ShowLanguageExtensionsAction extends Action {
2071

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

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

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

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

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

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

export class SearchExtensionsAction extends Action {

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

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

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

	private query: Query;

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

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

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

	private onSearchChange(value: string): void {
		const query = Query.parse(value);
2150
		this.query = new Query(query.value, this.sortBy || query.sortBy, query.groupBy);
S
Sandeep Somavarapu 已提交
2151 2152
		this.enabled = !!value && this.query.isValid();
		this.checked = this.enabled && this.query.equals(query);
2153 2154
	}

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

2165 2166 2167 2168 2169 2170
export abstract class AbstractConfigureRecommendedExtensionsAction extends Action {

	constructor(
		id: string,
		label: string,
		@IWorkspaceContextService protected contextService: IWorkspaceContextService,
2171
		@IFileService private readonly fileService: IFileService,
2172
		@ITextFileService private readonly textFileService: ITextFileService,
2173
		@IEditorService protected editorService: IEditorService,
2174 2175
		@IJSONEditingService private readonly jsonEditingService: IJSONEditingService,
		@ITextModelService private readonly textModelResolverService: ITextModelService
2176
	) {
2177
		super(id, label);
2178 2179
	}

S
Sandeep Somavarapu 已提交
2180
	protected openExtensionsFile(extensionsFileResource: URI): Promise<any> {
2181
		return this.getOrCreateExtensionsFile(extensionsFileResource)
S
Sandeep Somavarapu 已提交
2182 2183 2184 2185 2186 2187 2188 2189 2190
			.then(({ created, content }) =>
				this.getSelectionPosition(content, extensionsFileResource, ['recommendations'])
					.then(selection => this.editorService.openEditor({
						resource: extensionsFileResource,
						options: {
							pinned: created,
							selection
						}
					})),
S
Sandeep Somavarapu 已提交
2191
				error => Promise.reject(new Error(localize('OpenExtensionsFile.failed', "Unable to create 'extensions.json' file inside the '.vscode' folder ({0}).", error))));
2192 2193
	}

S
Sandeep Somavarapu 已提交
2194
	protected openWorkspaceConfigurationFile(workspaceConfigurationFile: URI): Promise<any> {
2195
		return this.getOrUpdateWorkspaceConfigurationFile(workspaceConfigurationFile)
B
Benjamin Pasero 已提交
2196
			.then(content => this.getSelectionPosition(content.value.toString(), content.resource, ['extensions', 'recommendations']))
2197 2198 2199
			.then(selection => this.editorService.openEditor({
				resource: workspaceConfigurationFile,
				options: {
B
Benjamin Pasero 已提交
2200 2201
					selection,
					forceReload: true // because content has changed
2202 2203 2204 2205
				}
			}));
	}

B
Benjamin Pasero 已提交
2206 2207
	private getOrUpdateWorkspaceConfigurationFile(workspaceConfigurationFile: URI): Promise<IFileContent> {
		return Promise.resolve(this.fileService.readFile(workspaceConfigurationFile))
2208
			.then(content => {
B
Benjamin Pasero 已提交
2209
				const workspaceRecommendations = <IExtensionsConfigContent>json.parse(content.value.toString())['extensions'];
2210
				if (!workspaceRecommendations || !workspaceRecommendations.recommendations) {
S
Sandeep Somavarapu 已提交
2211
					return this.jsonEditingService.write(workspaceConfigurationFile, [{ path: ['extensions'], value: { recommendations: [] } }], true)
B
Benjamin Pasero 已提交
2212
						.then(() => this.fileService.readFile(workspaceConfigurationFile));
2213 2214 2215 2216 2217
				}
				return content;
			});
	}

J
Johannes Rieken 已提交
2218
	private getSelectionPosition(content: string, resource: URI, path: json.JSONPath): Promise<ITextEditorSelection | undefined> {
S
Sandeep Somavarapu 已提交
2219 2220
		const tree = json.parseTree(content);
		const node = json.findNodeAtLocation(tree, path);
2221
		if (node && node.parent && node.parent.children) {
S
Sandeep Somavarapu 已提交
2222 2223 2224
			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 已提交
2225
			return Promise.resolve(this.textModelResolverService.createModelReference(resource))
2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236
				.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 已提交
2237
		return Promise.resolve(undefined);
2238 2239
	}

S
Sandeep Somavarapu 已提交
2240
	private getOrCreateExtensionsFile(extensionsFileResource: URI): Promise<{ created: boolean, extensionsFileResource: URI, content: string }> {
B
Benjamin Pasero 已提交
2241 2242
		return Promise.resolve(this.fileService.readFile(extensionsFileResource)).then(content => {
			return { created: false, extensionsFileResource, content: content.value.toString() };
2243
		}, err => {
B
Benjamin Pasero 已提交
2244
			return this.textFileService.write(extensionsFileResource, ExtensionsConfigurationInitialContent).then(() => {
S
Sandeep Somavarapu 已提交
2245
				return { created: true, extensionsFileResource, content: ExtensionsConfigurationInitialContent };
2246 2247 2248 2249 2250 2251
			});
		});
	}
}

export class ConfigureWorkspaceRecommendedExtensionsAction extends AbstractConfigureRecommendedExtensionsAction {
2252

2253
	static readonly ID = 'workbench.extensions.action.configureWorkspaceRecommendedExtensions';
2254
	static readonly LABEL = localize('configureWorkspaceRecommendedExtensions', "Configure Recommended Extensions (Workspace)");
2255 2256 2257 2258

	constructor(
		id: string,
		label: string,
2259
		@IFileService fileService: IFileService,
2260
		@ITextFileService textFileService: ITextFileService,
2261
		@IWorkspaceContextService contextService: IWorkspaceContextService,
2262
		@IEditorService editorService: IEditorService,
2263 2264
		@IJSONEditingService jsonEditingService: IJSONEditingService,
		@ITextModelService textModelResolverService: ITextModelService
2265
	) {
2266
		super(id, label, contextService, fileService, textFileService, editorService, jsonEditingService, textModelResolverService);
M
Matt Bierner 已提交
2267
		this._register(this.contextService.onDidChangeWorkbenchState(() => this.update(), this));
2268 2269 2270 2271 2272
		this.update();
	}

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

2275
	public run(): Promise<void> {
2276 2277
		switch (this.contextService.getWorkbenchState()) {
			case WorkbenchState.FOLDER:
2278
				return this.openExtensionsFile(this.contextService.getWorkspace().folders[0].toResource(EXTENSIONS_CONFIG));
2279
			case WorkbenchState.WORKSPACE:
2280
				return this.openWorkspaceConfigurationFile(this.contextService.getWorkspace().configuration!);
2281
		}
2282
		return Promise.resolve();
2283
	}
2284
}
2285

2286 2287
export class ConfigureWorkspaceFolderRecommendedExtensionsAction extends AbstractConfigureRecommendedExtensionsAction {

2288
	static readonly ID = 'workbench.extensions.action.configureWorkspaceFolderRecommendedExtensions';
2289
	static readonly LABEL = localize('configureWorkspaceFolderRecommendedExtensions', "Configure Recommended Extensions (Workspace Folder)");
2290 2291 2292 2293 2294

	constructor(
		id: string,
		label: string,
		@IFileService fileService: IFileService,
2295
		@ITextFileService textFileService: ITextFileService,
2296
		@IWorkspaceContextService contextService: IWorkspaceContextService,
2297
		@IEditorService editorService: IEditorService,
2298
		@IJSONEditingService jsonEditingService: IJSONEditingService,
S
Sandeep Somavarapu 已提交
2299
		@ITextModelService textModelResolverService: ITextModelService,
2300
		@ICommandService private readonly commandService: ICommandService
2301
	) {
2302
		super(id, label, contextService, fileService, textFileService, editorService, jsonEditingService, textModelResolverService);
M
Matt Bierner 已提交
2303
		this._register(this.contextService.onDidChangeWorkspaceFolders(() => this.update(), this));
2304
		this.update();
2305 2306
	}

2307 2308 2309
	private update(): void {
		this.enabled = this.contextService.getWorkspace().folders.length > 0;
	}
2310

S
Sandeep Somavarapu 已提交
2311
	public run(): Promise<any> {
2312
		const folderCount = this.contextService.getWorkspace().folders.length;
S
Sandeep Somavarapu 已提交
2313 2314
		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 已提交
2315 2316
			.then(workspaceFolder => {
				if (workspaceFolder) {
2317
					return this.openExtensionsFile(workspaceFolder.toResource(EXTENSIONS_CONFIG));
2318
				}
S
Sandeep Somavarapu 已提交
2319
				return null;
2320
			});
2321 2322 2323
	}
}

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

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

S
Sandeep Somavarapu 已提交
2329
	private initialStatus: ExtensionState | null = null;
S
#66931  
Sandeep Somavarapu 已提交
2330 2331 2332
	private status: ExtensionState | null = null;
	private enablementState: EnablementState | null = null;

S
Sandeep Somavarapu 已提交
2333 2334 2335
	private _extension: IExtension | null = null;
	get extension(): IExtension | null { return this._extension; }
	set extension(extension: IExtension | null) {
S
Sandeep Somavarapu 已提交
2336
		if (!(this._extension && extension && areSameExtensions(this._extension.identifier, extension.identifier))) {
S
#66931  
Sandeep Somavarapu 已提交
2337
			// Different extension. Reset
S
Sandeep Somavarapu 已提交
2338
			this.initialStatus = null;
S
#66931  
Sandeep Somavarapu 已提交
2339 2340 2341 2342 2343 2344 2345 2346
			this.status = null;
			this.enablementState = null;
		}
		this._extension = extension;
		this.update();
	}

	constructor(
2347 2348
		@IExtensionService private readonly extensionService: IExtensionService,
		@IExtensionManagementServerService private readonly extensionManagementServerService: IExtensionManagementServerService
S
#66931  
Sandeep Somavarapu 已提交
2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368
	) {
		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 已提交
2369 2370 2371
		if (this.initialStatus === null) {
			this.initialStatus = this.status;
		}
S
#66931  
Sandeep Somavarapu 已提交
2372 2373 2374
		this.enablementState = this.extension.enablementState;

		const runningExtensions = await this.extensionService.getExtensions();
S
Sandeep Somavarapu 已提交
2375
		const canAddExtension = () => {
S
Sandeep Somavarapu 已提交
2376 2377 2378
			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 已提交
2379 2380
					return true;
				}
S
Sandeep Somavarapu 已提交
2381
				return this.extensionService.canAddExtension(toExtensionDescription(this.extension!.local));
S
Sandeep Somavarapu 已提交
2382 2383 2384 2385
			}
			return false;
		};
		const canRemoveExtension = () => {
S
Sandeep Somavarapu 已提交
2386
			if (this.extension!.local) {
2387
				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 已提交
2388 2389
					return true;
				}
S
Sandeep Somavarapu 已提交
2390
				return this.extensionService.canRemoveExtension(toExtensionDescription(this.extension!.local));
S
Sandeep Somavarapu 已提交
2391 2392 2393
			}
			return false;
		};
S
#66931  
Sandeep Somavarapu 已提交
2394 2395 2396

		if (currentStatus !== null) {
			if (currentStatus === ExtensionState.Installing && this.status === ExtensionState.Installed) {
S
Sandeep Somavarapu 已提交
2397
				return canAddExtension() ? this.initialStatus === ExtensionState.Installed ? localize('updated', "Updated") : localize('installed', "Installed") : null;
S
#66931  
Sandeep Somavarapu 已提交
2398 2399
			}
			if (currentStatus === ExtensionState.Uninstalling && this.status === ExtensionState.Uninstalled) {
S
Sandeep Somavarapu 已提交
2400
				this.initialStatus = this.status;
S
#66931  
Sandeep Somavarapu 已提交
2401 2402 2403 2404 2405
				return canRemoveExtension() ? localize('uninstalled', "Uninstalled") : null;
			}
		}

		if (currentEnablementState !== null) {
2406 2407
			const currentlyEnabled = currentEnablementState === EnablementState.EnabledGlobally || currentEnablementState === EnablementState.EnabledWorkspace;
			const enabled = this.enablementState === EnablementState.EnabledGlobally || this.enablementState === EnablementState.EnabledWorkspace;
S
#66931  
Sandeep Somavarapu 已提交
2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420
			if (!currentlyEnabled && enabled) {
				return canAddExtension() ? localize('enabled', "Enabled") : null;
			}
			if (currentlyEnabled && !enabled) {
				return canRemoveExtension() ? localize('disabled', "Disabled") : null;
			}

		}

		return null;
	}

	run(): Promise<any> {
2421
		return Promise.resolve();
S
#66931  
Sandeep Somavarapu 已提交
2422 2423 2424 2425
	}

}

S
Sandeep Somavarapu 已提交
2426
export class MaliciousStatusLabelAction extends ExtensionAction {
J
Joao Moreno 已提交
2427

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

	constructor(long: boolean) {
J
Joao Moreno 已提交
2431
		const tooltip = localize('malicious tooltip', "This extension was reported to be problematic.");
2432
		const label = long ? tooltip : localize({ key: 'malicious', comment: ['Refers to a malicious extension'] }, "Malicious");
J
Joao Moreno 已提交
2433
		super('extensions.install', label, '', false);
J
Joao Moreno 已提交
2434
		this.tooltip = localize('malicious tooltip', "This extension was reported to be problematic.");
J
Joao Moreno 已提交
2435 2436
	}

S
Sandeep Somavarapu 已提交
2437
	update(): void {
J
Joao Moreno 已提交
2438 2439 2440 2441 2442 2443 2444
		if (this.extension && this.extension.isMalicious) {
			this.class = `${MaliciousStatusLabelAction.Class} malicious`;
		} else {
			this.class = `${MaliciousStatusLabelAction.Class} not-malicious`;
		}
	}

S
Sandeep Somavarapu 已提交
2445
	run(): Promise<any> {
2446
		return Promise.resolve();
J
Joao Moreno 已提交
2447 2448 2449
	}
}

S
Sandeep Somavarapu 已提交
2450
export class ToggleSyncExtensionAction extends ExtensionDropDownAction {
S
Sandeep Somavarapu 已提交
2451

S
Sandeep Somavarapu 已提交
2452 2453
	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 已提交
2454 2455

	constructor(
2456 2457
		@IConfigurationService private readonly configurationService: IConfigurationService,
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
Sandeep Somavarapu 已提交
2458 2459
		@IUserDataAutoSyncEnablementService private readonly userDataAutoSyncEnablementService: IUserDataAutoSyncEnablementService,
		@IInstantiationService instantiationService: IInstantiationService,
S
Sandeep Somavarapu 已提交
2460
	) {
S
Sandeep Somavarapu 已提交
2461
		super('extensions.sync', '', ToggleSyncExtensionAction.SYNC_CLASS, false, true, instantiationService);
S
Sandeep Somavarapu 已提交
2462
		this._register(Event.filter(this.configurationService.onDidChangeConfiguration, e => e.affectedKeys.includes('settingsSync.ignoredExtensions'))(() => this.update()));
S
Sandeep Somavarapu 已提交
2463
		this._register(userDataAutoSyncEnablementService.onDidChangeEnablement(() => this.update()));
S
Sandeep Somavarapu 已提交
2464 2465 2466 2467
		this.update();
	}

	update(): void {
2468
		this.enabled = !!this.extension && this.userDataAutoSyncEnablementService.isEnabled() && this.extension.state === ExtensionState.Installed;
S
Sandeep Somavarapu 已提交
2469 2470 2471 2472
		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");
2473
		}
S
Sandeep Somavarapu 已提交
2474 2475
	}

S
Sandeep Somavarapu 已提交
2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486
	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 已提交
2487 2488 2489
	}
}

S
Sandeep Somavarapu 已提交
2490
export class ExtensionToolTipAction extends ExtensionAction {
2491

S
Sandeep Somavarapu 已提交
2492
	private static readonly Class = `${ExtensionAction.TEXT_ACTION_CLASS} disable-status`;
2493 2494

	updateWhenCounterExtensionChanges: boolean = true;
2495
	private _runningExtensions: IExtensionDescription[] | null = null;
2496

2497 2498
	constructor(
		private readonly warningAction: SystemDisabledWarningAction,
S
Sandeep Somavarapu 已提交
2499
		private readonly reloadAction: ReloadAction,
S
rename  
Sandeep Somavarapu 已提交
2500
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService,
2501
		@IExtensionService private readonly extensionService: IExtensionService,
S
Sandeep Somavarapu 已提交
2502
		@IExtensionManagementServerService private readonly extensionManagementServerService: IExtensionManagementServerService
2503
	) {
S
Sandeep Somavarapu 已提交
2504
		super('extensions.tooltip', warningAction.tooltip, `${ExtensionToolTipAction.Class} hide`, false);
M
Matt Bierner 已提交
2505 2506
		this._register(warningAction.onDidChange(() => this.update(), this));
		this._register(this.extensionService.onDidChangeExtensions(this.updateRunningExtensions, this));
2507 2508 2509 2510 2511
		this.updateRunningExtensions();
	}

	private updateRunningExtensions(): void {
		this.extensionService.getExtensions().then(runningExtensions => { this._runningExtensions = runningExtensions; this.update(); });
2512 2513 2514
	}

	update(): void {
S
Sandeep Somavarapu 已提交
2515 2516 2517 2518
		this.label = this.getTooltip();
		this.class = ExtensionToolTipAction.Class;
		if (!this.label) {
			this.class = `${ExtensionToolTipAction.Class} hide`;
2519
		}
S
Sandeep Somavarapu 已提交
2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530
	}

	private getTooltip(): string {
		if (!this.extension) {
			return '';
		}
		if (this.reloadAction.enabled) {
			return this.reloadAction.tooltip;
		}
		if (this.warningAction.tooltip) {
			return this.warningAction.tooltip;
2531
		}
S
Sandeep Somavarapu 已提交
2532
		if (this.extension && this.extension.local && this.extension.state === ExtensionState.Installed && this._runningExtensions) {
S
Sandeep Somavarapu 已提交
2533
			const isRunning = this._runningExtensions.some(e => areSameExtensions({ id: e.identifier.value, uuid: e.uuid }, this.extension!.identifier));
2534
			const isEnabled = this.extensionEnablementService.isEnabled(this.extension.local);
S
Sandeep Somavarapu 已提交
2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556

			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.");
				}
2557
			}
2558
		}
S
Sandeep Somavarapu 已提交
2559
		return '';
2560 2561 2562 2563 2564 2565 2566 2567 2568
	}

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

export class SystemDisabledWarningAction extends ExtensionAction {

S
Sandeep Somavarapu 已提交
2569
	private static readonly CLASS = `${ExtensionAction.ICON_ACTION_CLASS} system-disable`;
2570 2571
	private static readonly WARNING_CLASS = `${SystemDisabledWarningAction.CLASS} ${Codicon.warning.classNames}`;
	private static readonly INFO_CLASS = `${SystemDisabledWarningAction.CLASS} ${Codicon.info.classNames}`;
2572 2573

	updateWhenCounterExtensionChanges: boolean = true;
2574
	private _runningExtensions: IExtensionDescription[] | null = null;
2575

2576 2577 2578
	constructor(
		@IExtensionManagementServerService private readonly extensionManagementServerService: IExtensionManagementServerService,
		@ILabelService private readonly labelService: ILabelService,
2579
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
2580 2581 2582
		@IExtensionService private readonly extensionService: IExtensionService,
		@IProductService private readonly productService: IProductService,
		@IConfigurationService private readonly configurationService: IConfigurationService,
2583
	) {
2584
		super('extensions.install', '', `${SystemDisabledWarningAction.CLASS} hide`, false);
M
Matt Bierner 已提交
2585 2586
		this._register(this.labelService.onDidChangeFormatters(() => this.update(), this));
		this._register(this.extensionService.onDidChangeExtensions(this.updateRunningExtensions, this));
2587
		this.updateRunningExtensions();
2588 2589 2590
		this.update();
	}

2591 2592 2593 2594
	private updateRunningExtensions(): void {
		this.extensionService.getExtensions().then(runningExtensions => { this._runningExtensions = runningExtensions; this.update(); });
	}

2595
	update(): void {
2596
		this.class = `${SystemDisabledWarningAction.CLASS} hide`;
2597
		this.tooltip = '';
2598 2599 2600 2601 2602
		if (
			!this.extension ||
			!this.extension.local ||
			!this.extension.server ||
			!this._runningExtensions ||
2603
			this.extension.state !== ExtensionState.Installed
2604
		) {
2605 2606
			return;
		}
2607 2608 2609 2610 2611
		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 已提交
2612 2613
						? 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.");
2614 2615
				}
				return;
2616 2617
			}
		}
S
Sandeep Somavarapu 已提交
2618
		if (this.extension.enablementState === EnablementState.DisabledByExtensionKind) {
S
Sandeep Somavarapu 已提交
2619
			if (!this.extensionsWorkbenchService.installed.some(e => areSameExtensions(e.identifier, this.extension!.identifier) && e.server !== this.extension!.server)) {
S
Sandeep Somavarapu 已提交
2620
				const server = this.extensionManagementServerService.localExtensionManagementServer === this.extension.server ? this.extensionManagementServerService.remoteExtensionManagementServer : this.extensionManagementServerService.localExtensionManagementServer;
2621
				this.class = `${SystemDisabledWarningAction.WARNING_CLASS}`;
2622 2623 2624
				if (server) {
					this.tooltip = localize('Install in other server to enable', "Install the extension on '{0}' to enable.", server.label);
				} else {
S
Sandeep Somavarapu 已提交
2625
					this.tooltip = localize('disabled because of extension kind', "This extension has defined that it cannot run on the remote server");
2626
				}
S
Sandeep Somavarapu 已提交
2627 2628
				return;
			}
2629
		}
2630 2631
		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];
2632
			const runningExtensionServer = runningExtension ? this.extensionManagementServerService.getExtensionManagementServer(toExtension(runningExtension)) : null;
2633 2634 2635 2636 2637 2638
			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;
2639
			}
2640 2641 2642 2643 2644 2645
			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;
2646
			}
2647 2648 2649 2650 2651 2652 2653 2654
		}
	}

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

2655 2656
export class DisableAllAction extends Action {

2657
	static readonly ID = 'workbench.extensions.action.disableAll';
2658
	static readonly LABEL = localize('disableAll', "Disable All Installed Extensions");
2659 2660

	constructor(
S
Sandeep Somavarapu 已提交
2661
		id: string, label: string, isPrimary: boolean,
2662
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
rename  
Sandeep Somavarapu 已提交
2663
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService
2664 2665
	) {
		super(id, label);
S
Sandeep Somavarapu 已提交
2666 2667 2668
		if (isPrimary) {
			this._register(this.extensionsWorkbenchService.onChange(() => this._onDidChange.fire({ enabled: this.enabled })));
		}
2669 2670
	}

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

S
Sandeep Somavarapu 已提交
2675 2676
	get enabled(): boolean {
		return this.getExtensionsToDisable().length > 0;
2677 2678
	}

S
Sandeep Somavarapu 已提交
2679
	run(): Promise<any> {
S
Sandeep Somavarapu 已提交
2680
		return this.extensionsWorkbenchService.setEnablement(this.getExtensionsToDisable(), EnablementState.DisabledGlobally);
2681 2682 2683
	}
}

2684
export class DisableAllWorkspaceAction extends Action {
2685

2686
	static readonly ID = 'workbench.extensions.action.disableAllWorkspace';
2687
	static readonly LABEL = localize('disableAllWorkspace', "Disable All Installed Extensions for this Workspace");
2688 2689

	constructor(
S
Sandeep Somavarapu 已提交
2690
		id: string, label: string, isPrimary: boolean,
2691
		@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService,
2692
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
rename  
Sandeep Somavarapu 已提交
2693
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService
2694 2695
	) {
		super(id, label);
S
Sandeep Somavarapu 已提交
2696 2697 2698
		if (isPrimary) {
			this._register(Event.any(this.workspaceContextService.onDidChangeWorkbenchState, this.extensionsWorkbenchService.onChange)(() => this._onDidChange.fire({ enabled: this.enabled })));
		}
2699 2700
	}

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

S
Sandeep Somavarapu 已提交
2705 2706
	get enabled(): boolean {
		return this.getExtensionsToDisable().length > 0;
2707 2708
	}

S
Sandeep Somavarapu 已提交
2709
	run(): Promise<any> {
S
Sandeep Somavarapu 已提交
2710
		return this.extensionsWorkbenchService.setEnablement(this.getExtensionsToDisable(), EnablementState.DisabledWorkspace);
2711 2712 2713 2714 2715
	}
}

export class EnableAllAction extends Action {

2716
	static readonly ID = 'workbench.extensions.action.enableAll';
2717
	static readonly LABEL = localize('enableAll', "Enable All Extensions");
2718 2719

	constructor(
S
Sandeep Somavarapu 已提交
2720
		id: string, label: string, isPrimary: boolean,
2721
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
rename  
Sandeep Somavarapu 已提交
2722
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService
2723 2724
	) {
		super(id, label);
S
Sandeep Somavarapu 已提交
2725 2726 2727
		if (isPrimary) {
			this._register(this.extensionsWorkbenchService.onChange(() => this._onDidChange.fire({ enabled: this.enabled })));
		}
2728 2729
	}

S
Sandeep Somavarapu 已提交
2730 2731 2732 2733
	private getExtensionsToEnable(): IExtension[] {
		return this.extensionsWorkbenchService.local.filter(e => !!e.local && this.extensionEnablementService.canChangeEnablement(e.local) && !this.extensionEnablementService.isEnabled(e.local));
	}

S
Sandeep Somavarapu 已提交
2734 2735
	get enabled(): boolean {
		return this.getExtensionsToEnable().length > 0;
2736 2737
	}

S
Sandeep Somavarapu 已提交
2738
	run(): Promise<any> {
S
Sandeep Somavarapu 已提交
2739
		return this.extensionsWorkbenchService.setEnablement(this.getExtensionsToEnable(), EnablementState.EnabledGlobally);
2740 2741 2742
	}
}

2743
export class EnableAllWorkspaceAction extends Action {
2744

2745
	static readonly ID = 'workbench.extensions.action.enableAllWorkspace';
2746
	static readonly LABEL = localize('enableAllWorkspace', "Enable All Extensions for this Workspace");
2747 2748

	constructor(
S
Sandeep Somavarapu 已提交
2749
		id: string, label: string, isPrimary: boolean,
2750 2751
		@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService,
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
S
rename  
Sandeep Somavarapu 已提交
2752
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService
2753 2754
	) {
		super(id, label);
S
Sandeep Somavarapu 已提交
2755 2756 2757
		if (isPrimary) {
			this._register(Event.any(this.workspaceContextService.onDidChangeWorkbenchState, this.extensionsWorkbenchService.onChange)(() => this._onDidChange.fire({ enabled: this.enabled })));
		}
2758 2759
	}

S
Sandeep Somavarapu 已提交
2760 2761 2762 2763
	private getExtensionsToEnable(): IExtension[] {
		return this.extensionsWorkbenchService.local.filter(e => !!e.local && this.extensionEnablementService.canChangeEnablement(e.local) && !this.extensionEnablementService.isEnabled(e.local));
	}

S
Sandeep Somavarapu 已提交
2764 2765
	get enabled(): boolean {
		return this.getExtensionsToEnable().length > 0;
2766 2767
	}

S
Sandeep Somavarapu 已提交
2768
	run(): Promise<any> {
S
Sandeep Somavarapu 已提交
2769
		return this.extensionsWorkbenchService.setEnablement(this.getExtensionsToEnable(), EnablementState.EnabledWorkspace);
2770
	}
2771 2772
}

J
Joao Moreno 已提交
2773 2774 2775
export class InstallVSIXAction extends Action {

	static readonly ID = 'workbench.extensions.action.installVSIX';
2776
	static readonly LABEL = localize('installVSIX', "Install from VSIX...");
J
Joao Moreno 已提交
2777 2778 2779 2780

	constructor(
		id = InstallVSIXAction.ID,
		label = InstallVSIXAction.LABEL,
2781
		@IFileDialogService private readonly fileDialogService: IFileDialogService,
2782
		@ICommandService private readonly commandService: ICommandService
J
Joao Moreno 已提交
2783
	) {
S
Sandeep Somavarapu 已提交
2784
		super(id, label, 'extension-action install-vsix', true);
J
Joao Moreno 已提交
2785 2786
	}

2787 2788 2789 2790 2791
	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 已提交
2792
			canSelectMany: true,
2793 2794
			openLabel: mnemonicButtonLabel(localize({ key: 'installButton', comment: ['&& denotes a mnemonic'] }, "&&Install"))
		});
2795

2796 2797
		if (!vsixPaths) {
			return;
2798
		}
J
Joao Moreno 已提交
2799

2800
		// Install extension(s), display notification(s), display @installed extensions
2801
		await this.commandService.executeCommand(INSTALL_EXTENSION_FROM_VSIX_COMMAND_ID, vsixPaths);
J
Joao Moreno 已提交
2802 2803 2804 2805 2806 2807
	}
}

export class ReinstallAction extends Action {

	static readonly ID = 'workbench.extensions.action.reinstall';
2808
	static readonly LABEL = localize('reinstall', "Reinstall Extension...");
J
Joao Moreno 已提交
2809 2810 2811

	constructor(
		id: string = ReinstallAction.ID, label: string = ReinstallAction.LABEL,
2812 2813 2814
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
		@IQuickInputService private readonly quickInputService: IQuickInputService,
		@INotificationService private readonly notificationService: INotificationService,
2815
		@IHostService private readonly hostService: IHostService,
S
Sandeep Somavarapu 已提交
2816 2817
		@IInstantiationService private readonly instantiationService: IInstantiationService,
		@IExtensionService private readonly extensionService: IExtensionService
J
Joao Moreno 已提交
2818 2819 2820 2821 2822
	) {
		super(id, label);
	}

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

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

J
Johannes Rieken 已提交
2831
	private getEntries(): Promise<(IQuickPickItem & { extension: IExtension })[]> {
J
Joao Moreno 已提交
2832 2833
		return this.extensionsWorkbenchService.queryLocal()
			.then(local => {
C
Christof Marti 已提交
2834
				const entries = local
2835
					.filter(extension => !extension.isBuiltin)
J
Joao Moreno 已提交
2836
					.map(extension => {
C
Christof Marti 已提交
2837
						return {
S
Sandeep Somavarapu 已提交
2838
							id: extension.identifier.id,
J
Joao Moreno 已提交
2839
							label: extension.displayName,
S
Sandeep Somavarapu 已提交
2840
							description: extension.identifier.id,
C
Christof Marti 已提交
2841 2842
							extension,
						} as (IQuickPickItem & { extension: IExtension });
J
Joao Moreno 已提交
2843 2844 2845 2846 2847
					});
				return entries;
			});
	}

J
Johannes Rieken 已提交
2848
	private reinstallExtension(extension: IExtension): Promise<void> {
S
Sandeep Somavarapu 已提交
2849 2850
		return this.instantiationService.createInstance(ShowInstalledExtensionsAction, ShowInstalledExtensionsAction.ID, ShowInstalledExtensionsAction.LABEL).run()
			.then(() => {
2851
				return this.extensionsWorkbenchService.reinstall(extension)
S
Sandeep Somavarapu 已提交
2852 2853 2854 2855 2856 2857
					.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"),
2858
							run: () => this.hostService.reload()
S
Sandeep Somavarapu 已提交
2859
						}] : [];
2860 2861
						this.notificationService.prompt(
							Severity.Info,
S
Sandeep Somavarapu 已提交
2862 2863
							message,
							actions,
2864 2865 2866 2867
							{ sticky: true }
						);
					}, error => this.notificationService.error(error));
			});
J
Joao Moreno 已提交
2868 2869 2870
	}
}

S
Sandeep Somavarapu 已提交
2871
export class InstallSpecificVersionOfExtensionAction extends Action {
2872

S
Sandeep Somavarapu 已提交
2873
	static readonly ID = 'workbench.extensions.action.install.specificVersion';
2874
	static readonly LABEL = localize('install previous version', "Install Specific Version of Extension...");
2875 2876

	constructor(
S
Sandeep Somavarapu 已提交
2877
		id: string = InstallSpecificVersionOfExtensionAction.ID, label: string = InstallSpecificVersionOfExtensionAction.LABEL,
2878 2879 2880 2881
		@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
		@IExtensionGalleryService private readonly extensionGalleryService: IExtensionGalleryService,
		@IQuickInputService private readonly quickInputService: IQuickInputService,
		@INotificationService private readonly notificationService: INotificationService,
2882
		@IHostService private readonly hostService: IHostService,
S
Sandeep Somavarapu 已提交
2883
		@IInstantiationService private readonly instantiationService: IInstantiationService,
2884
		@IExtensionService private readonly extensionService: IExtensionService,
S
rename  
Sandeep Somavarapu 已提交
2885
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService,
2886 2887 2888 2889 2890
	) {
		super(id, label);
	}

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

S
Sandeep Somavarapu 已提交
2894 2895 2896
	async run(): Promise<any> {
		const extensionPick = await this.quickInputService.pick(this.getExtensionEntries(), { placeHolder: localize('selectExtension', "Select Extension"), matchOnDetail: true });
		if (extensionPick && extensionPick.extension) {
2897
			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 已提交
2898 2899
			if (versionPick) {
				if (extensionPick.extension.version !== versionPick.id) {
2900
					await this.install(extensionPick.extension, versionPick.id);
S
Sandeep Somavarapu 已提交
2901 2902
				}
			}
S
Sandeep Somavarapu 已提交
2903 2904 2905 2906
		}
	}

	private isEnabled(extension: IExtension): boolean {
2907
		return !!extension.gallery && !!extension.local && this.extensionEnablementService.isEnabled(extension.local);
2908 2909
	}

S
Sandeep Somavarapu 已提交
2910
	private async getExtensionEntries(): Promise<(IQuickPickItem & { extension: IExtension, versions: IGalleryExtensionVersion[] })[]> {
2911
		const installed = await this.extensionsWorkbenchService.queryLocal();
2912
		const versionsPromises: Promise<{ extension: IExtension, versions: IGalleryExtensionVersion[] } | null>[] = [];
2913
		for (const extension of installed) {
S
Sandeep Somavarapu 已提交
2914
			if (this.isEnabled(extension)) {
2915
				versionsPromises.push(this.extensionGalleryService.getAllVersions(extension.gallery!, true)
S
Sandeep Somavarapu 已提交
2916
					.then(versions => (versions.length ? { extension, versions } : null)));
2917 2918 2919
			}
		}

S
Sandeep Somavarapu 已提交
2920
		const extensions = await Promise.all(versionsPromises);
M
Matt Bierner 已提交
2921
		return coalesce(extensions)
2922
			.sort((e1, e2) => e1.extension.displayName.localeCompare(e2.extension.displayName))
S
Sandeep Somavarapu 已提交
2923
			.map(({ extension, versions }) => {
2924
				return {
S
Sandeep Somavarapu 已提交
2925 2926 2927
					id: extension.identifier.id,
					label: extension.displayName || extension.identifier.id,
					description: extension.identifier.id,
2928
					extension,
S
Sandeep Somavarapu 已提交
2929 2930
					versions
				} as (IQuickPickItem & { extension: IExtension, versions: IGalleryExtensionVersion[] });
2931 2932 2933
			});
	}

J
Johannes Rieken 已提交
2934
	private install(extension: IExtension, version: string): Promise<void> {
S
Sandeep Somavarapu 已提交
2935 2936
		return this.instantiationService.createInstance(ShowInstalledExtensionsAction, ShowInstalledExtensionsAction.ID, ShowInstalledExtensionsAction.LABEL).run()
			.then(() => {
2937
				return this.extensionsWorkbenchService.installVersion(extension, version)
S
Sandeep Somavarapu 已提交
2938 2939 2940 2941 2942 2943
					.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"),
2944
							run: () => this.hostService.reload()
S
Sandeep Somavarapu 已提交
2945
						}] : [];
2946 2947
						this.notificationService.prompt(
							Severity.Info,
S
Sandeep Somavarapu 已提交
2948 2949
							message,
							actions,
2950 2951 2952 2953
							{ sticky: true }
						);
					}, error => this.notificationService.error(error));
			});
J
Joao Moreno 已提交
2954 2955 2956
	}
}

2957 2958 2959 2960
interface IExtensionPickItem extends IQuickPickItem {
	extension?: IExtension;
}

S
Sandeep Somavarapu 已提交
2961
export abstract class AbstractInstallExtensionsInServerAction extends Action {
2962

2963 2964
	private extensions: IExtension[] | undefined = undefined;

2965
	constructor(
S
Sandeep Somavarapu 已提交
2966 2967
		id: string,
		@IExtensionsWorkbenchService protected readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
2968 2969
		@IQuickInputService private readonly quickInputService: IQuickInputService,
		@INotificationService private readonly notificationService: INotificationService,
2970
		@IProgressService private readonly progressService: IProgressService,
2971
	) {
S
Sandeep Somavarapu 已提交
2972
		super(id);
2973
		this.update();
2974 2975 2976 2977 2978 2979
		this.extensionsWorkbenchService.queryLocal().then(() => this.updateExtensions());
		this._register(this.extensionsWorkbenchService.onChange(() => {
			if (this.extensions) {
				this.updateExtensions();
			}
		}));
2980 2981
	}

2982 2983 2984 2985 2986
	private updateExtensions(): void {
		this.extensions = this.extensionsWorkbenchService.local;
		this.update();
	}

2987
	private update(): void {
2988
		this.enabled = !!this.extensions && this.getExtensionsToInstall(this.extensions).length > 0;
S
Sandeep Somavarapu 已提交
2989
		this.tooltip = this.label;
2990 2991
	}

2992
	async run(): Promise<void> {
S
Sandeep Somavarapu 已提交
2993
		return this.selectAndInstallExtensions();
2994 2995 2996 2997 2998 2999 3000
	}

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

S
Sandeep Somavarapu 已提交
3001
	private async selectAndInstallExtensions(): Promise<void> {
3002 3003 3004 3005 3006 3007 3008 3009 3010
		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();
3011
		const localExtensionsToInstall = await this.queryExtensionsToInstall();
3012 3013
		quickPick.busy = false;
		if (localExtensionsToInstall.length) {
S
Sandeep Somavarapu 已提交
3014
			quickPick.title = this.getQuickPickTitle();
3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025
			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.")
			});
3026 3027 3028
		}
	}

S
Sandeep Somavarapu 已提交
3029
	private async onDidAccept(selectedItems: ReadonlyArray<IExtensionPickItem>): Promise<void> {
3030 3031
		if (selectedItems.length) {
			const localExtensionsToInstall = selectedItems.filter(r => !!r.extension).map(r => r.extension!);
3032
			if (localExtensionsToInstall.length) {
S
Sandeep Somavarapu 已提交
3033
				await this.progressService.withProgress(
3034 3035 3036 3037
					{
						location: ProgressLocation.Notification,
						title: localize('installing extensions', "Installing Extensions...")
					},
S
Sandeep Somavarapu 已提交
3038 3039
					() => this.installExtensions(localExtensionsToInstall));
				this.notificationService.info(localize('finished installing', "Successfully installed extensions."));
3040 3041 3042 3043
			}
		}
	}

S
Sandeep Somavarapu 已提交
3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082
	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> {
3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098
		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 已提交
3099 3100 3101 3102
	}
}

export class InstallRemoteExtensionsInLocalAction extends AbstractInstallExtensionsInServerAction {
3103

S
Sandeep Somavarapu 已提交
3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139
	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;
				}
3140
			}
S
Sandeep Somavarapu 已提交
3141 3142 3143 3144 3145 3146
			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)));
3147 3148 3149
	}
}

S
Sandeep Somavarapu 已提交
3150
CommandsRegistry.registerCommand('workbench.extensions.action.showExtensionsForLanguage', function (accessor: ServicesAccessor, fileExtension: string) {
3151 3152 3153
	const viewletService = accessor.get(IViewletService);

	return viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
3154
		.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
3155 3156 3157 3158 3159
		.then(viewlet => {
			viewlet.search(`ext:${fileExtension.replace(/^\./, '')}`);
			viewlet.focus();
		});
});
B
Benjamin Pasero 已提交
3160

3161
CommandsRegistry.registerCommand('workbench.extensions.action.showExtensionsWithIds', function (accessor: ServicesAccessor, extensionIds: string[]) {
3162 3163 3164
	const viewletService = accessor.get(IViewletService);

	return viewletService.openViewlet(VIEWLET_ID, true)
S
SteVen Batten 已提交
3165
		.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
3166
		.then(viewlet => {
3167 3168 3169 3170
			const query = extensionIds
				.map(id => `@id:${id}`)
				.join(' ');
			viewlet.search(query);
3171 3172 3173 3174
			viewlet.focus();
		});
});

B
Benjamin Pasero 已提交
3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192
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 已提交
3193
registerThemingParticipant((theme: IColorTheme, collector: ICssStyleCollector) => {
B
Benjamin Pasero 已提交
3194 3195
	const foregroundColor = theme.getColor(foreground);
	if (foregroundColor) {
3196
		collector.addRule(`.extension-list-item .monaco-action-bar .action-item .action-label.extension-action.built-in-status { border-color: ${foregroundColor}; }`);
3197
		collector.addRule(`.extension-editor .monaco-action-bar .action-item .action-label.extension-action.built-in-status { border-color: ${foregroundColor}; }`);
B
Benjamin Pasero 已提交
3198 3199
	}

B
Benjamin Pasero 已提交
3200 3201
	const buttonBackgroundColor = theme.getColor(buttonBackground);
	if (buttonBackgroundColor) {
S
Sandeep Somavarapu 已提交
3202 3203
		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 已提交
3204 3205 3206 3207
	}

	const buttonForegroundColor = theme.getColor(buttonForeground);
	if (buttonForegroundColor) {
S
Sandeep Somavarapu 已提交
3208 3209
		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 已提交
3210 3211 3212 3213
	}

	const buttonHoverBackgroundColor = theme.getColor(buttonHoverBackground);
	if (buttonHoverBackgroundColor) {
S
Sandeep Somavarapu 已提交
3214 3215
		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 已提交
3216 3217 3218 3219
	}

	const extensionButtonProminentBackgroundColor = theme.getColor(extensionButtonProminentBackground);
	if (extensionButtonProminentBackground) {
S
Sandeep Somavarapu 已提交
3220 3221
		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 已提交
3222 3223 3224 3225
	}

	const extensionButtonProminentForegroundColor = theme.getColor(extensionButtonProminentForeground);
	if (extensionButtonProminentForeground) {
S
Sandeep Somavarapu 已提交
3226 3227
		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 已提交
3228 3229 3230 3231
	}

	const extensionButtonProminentHoverBackgroundColor = theme.getColor(extensionButtonProminentHoverBackground);
	if (extensionButtonProminentHoverBackground) {
S
Sandeep Somavarapu 已提交
3232 3233 3234 3235 3236 3237
		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 已提交
3238 3239
		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 已提交
3240
	}
A
Alex Dima 已提交
3241
});