Skip to content

Commit

Permalink
microsoft#85036 Support multiple extension kinds
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 authored and Chitoge Tomoyo committed Nov 27, 2019
1 parent cb9ef7d commit 5e47837
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 20 deletions.
60 changes: 43 additions & 17 deletions src/vs/workbench/contrib/extensions/browser/extensionsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import { alert } from 'vs/base/browser/ui/aria/aria';
import { coalesce } from 'vs/base/common/arrays';
import { IWorkbenchThemeService, COLOR_THEME_SETTING, ICON_THEME_SETTING, IFileIconTheme, IColorTheme } from 'vs/workbench/services/themes/common/workbenchThemeService';
import { ILabelService } from 'vs/platform/label/common/label';
import { prefersExecuteOnUI } from 'vs/workbench/services/extensions/common/extensionsUtil';
import { prefersExecuteOnUI, prefersExecuteOnWorkspace } from 'vs/workbench/services/extensions/common/extensionsUtil';
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IProductService } from 'vs/platform/product/common/productService';
Expand Down Expand Up @@ -1195,7 +1195,9 @@ export class ReloadAction extends ExtensionAction {
@IHostService private readonly hostService: IHostService,
@IExtensionService private readonly extensionService: IExtensionService,
@IExtensionEnablementService private readonly extensionEnablementService: IExtensionEnablementService,
@IExtensionManagementServerService private readonly extensionManagementServerService: IExtensionManagementServerService
@IExtensionManagementServerService private readonly extensionManagementServerService: IExtensionManagementServerService,
@IProductService private readonly productService: IProductService,
@IConfigurationService private readonly configurationService: IConfigurationService,
) {
super('extensions.reload', localize('reloadAction', "Reload"), ReloadAction.DisabledClass, false);
this._register(this.extensionService.onDidChangeExtensions(this.updateRunningExtensions, this));
Expand Down Expand Up @@ -1246,19 +1248,37 @@ export class ReloadAction extends ExtensionAction {
// Extension is running
if (runningExtension) {
if (isEnabled) {
if (!this.extensionService.canAddExtension(toExtensionDescription(this.extension.local))) {
if (isSameExtensionRunning) {
if (this.extension.version !== runningExtension.version) {
// No Reload is required if extension can run without reload
if (this.extensionService.canAddExtension(toExtensionDescription(this.extension.local))) {
return;
}
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.");
}
} else {
const runningExtensionServer = this.extensionManagementServerService.getExtensionManagementServer(runningExtension.extensionLocation);
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)) {
this.enabled = true;
this.label = localize('reloadRequired', "Reload Required");
this.tooltip = localize('postUpdateTooltip', "Please reload Visual Studio Code to enable the updated extension.");
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.");
}
} else {
this.enabled = true;
this.label = localize('reloadRequired', "Reload Required");
this.tooltip = localize('postEnableTooltip', "Please reload Visual Studio Code to enable this extension.");
}
}
return;
} else {
if (isSameExtensionRunning) {
this.enabled = true;
Expand Down Expand Up @@ -2632,7 +2652,9 @@ export class SystemDisabledWarningAction extends ExtensionAction {
@IExtensionManagementServerService private readonly extensionManagementServerService: IExtensionManagementServerService,
@ILabelService private readonly labelService: ILabelService,
@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
@IExtensionService private readonly extensionService: IExtensionService
@IExtensionService private readonly extensionService: IExtensionService,
@IProductService private readonly productService: IProductService,
@IConfigurationService private readonly configurationService: IConfigurationService,
) {
super('extensions.install', '', `${SystemDisabledWarningAction.CLASS} hide`, false);
this._register(this.labelService.onDidChangeFormatters(() => this.update(), this));
Expand Down Expand Up @@ -2674,18 +2696,22 @@ export class SystemDisabledWarningAction extends ExtensionAction {
this.tooltip = localize('Install in other server to enable', "Install the extension on '{0}' to enable.", server.label);
return;
}
const runningExtension = this._runningExtensions.filter(e => areSameExtensions({ id: e.identifier.value, uuid: e.uuid }, this.extension!.identifier))[0];
const runningExtensionServer = runningExtension ? this.extensionManagementServerService.getExtensionManagementServer(runningExtension.extensionLocation) : null;
if (this.extension.server === this.extensionManagementServerService.localExtensionManagementServer && runningExtensionServer === this.extensionManagementServerService.remoteExtensionManagementServer) {
}
const runningExtension = this._runningExtensions.filter(e => areSameExtensions({ id: e.identifier.value, uuid: e.uuid }, this.extension!.identifier))[0];
const runningExtensionServer = runningExtension ? this.extensionManagementServerService.getExtensionManagementServer(runningExtension.extensionLocation) : null;
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;
}
if (this.extension.server === this.extensionManagementServerService.remoteExtensionManagementServer && runningExtensionServer === this.extensionManagementServerService.localExtensionManagementServer) {
return;
}
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;
}
return;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,20 @@ export class ExtensionEnablementService extends Disposable implements IExtension

private _isDisabledByExtensionKind(extension: IExtension): boolean {
if (this.extensionManagementServerService.localExtensionManagementServer && this.extensionManagementServerService.remoteExtensionManagementServer) {
const extensionKind = getExtensionKind(extension.manifest, this.productService, this.configurationService);
const server = extensionKind[0] === 'ui' ? this.extensionManagementServerService.localExtensionManagementServer : this.extensionManagementServerService.remoteExtensionManagementServer;
return this.extensionManagementServerService.getExtensionManagementServer(extension.location) !== server;
const server = this.extensionManagementServerService.getExtensionManagementServer(extension.location);
for (const extensionKind of getExtensionKind(extension.manifest, this.productService, this.configurationService)) {
if (extensionKind === 'ui') {
if (server === this.extensionManagementServerService.localExtensionManagementServer) {
return false;
}
}
if (extensionKind === 'workspace') {
if (server === this.extensionManagementServerService.remoteExtensionManagementServer) {
return false;
}
}
}
return true;
}
return false;
}
Expand Down
10 changes: 10 additions & 0 deletions src/vs/workbench/services/extensions/common/extensionsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,21 @@ export function prefersExecuteOnUI(manifest: IExtensionManifest, productService:
return (extensionKind.length > 0 && extensionKind[0] === 'ui');
}

export function prefersExecuteOnWorkspace(manifest: IExtensionManifest, productService: IProductService, configurationService: IConfigurationService): boolean {
const extensionKind = getExtensionKind(manifest, productService, configurationService);
return (extensionKind.length > 0 && extensionKind[0] === 'workspace');
}

export function canExecuteOnUI(manifest: IExtensionManifest, productService: IProductService, configurationService: IConfigurationService): boolean {
const extensionKind = getExtensionKind(manifest, productService, configurationService);
return extensionKind.some(kind => kind === 'ui');
}

export function canExecuteOnWorkspace(manifest: IExtensionManifest, productService: IProductService, configurationService: IConfigurationService): boolean {
const extensionKind = getExtensionKind(manifest, productService, configurationService);
return extensionKind.some(kind => kind === 'workspace');
}

export function canExecuteOnWeb(manifest: IExtensionManifest, productService: IProductService, configurationService: IConfigurationService): boolean {
const extensionKind = getExtensionKind(manifest, productService, configurationService);
return extensionKind.some(kind => kind === 'web');
Expand Down

0 comments on commit 5e47837

Please sign in to comment.