Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 authored Dec 26, 2022
1 parent aaad9dd commit 4205170
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
abstract installFromLocation(location: URI, profileLocation: URI): Promise<ILocalExtension>;
abstract getInstalled(type?: ExtensionType, profileLocation?: URI): Promise<ILocalExtension[]>;
abstract download(extension: IGalleryExtension, operation: InstallOperation): Promise<URI>;
abstract reinstallFromGallery(extension: ILocalExtension): Promise<void>;
abstract reinstallFromGallery(extension: ILocalExtension): Promise<ILocalExtension>;

abstract getMetadata(extension: ILocalExtension): Promise<Metadata | undefined>;
abstract updateMetadata(local: ILocalExtension, metadata: IGalleryMetadata): Promise<ILocalExtension>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ export interface IExtensionManagementService {
installFromGallery(extension: IGalleryExtension, options?: InstallOptions): Promise<ILocalExtension>;
installFromLocation(location: URI, profileLocation: URI): Promise<ILocalExtension>;
uninstall(extension: ILocalExtension, options?: UninstallOptions): Promise<void>;
reinstallFromGallery(extension: ILocalExtension): Promise<void>;
reinstallFromGallery(extension: ILocalExtension): Promise<ILocalExtension>;
getInstalled(type?: ExtensionType, profileLocation?: URI): Promise<ILocalExtension[]>;
getExtensionsControlManifest(): Promise<IExtensionsControlManifest>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ export class ExtensionManagementChannelClient extends Disposable implements IExt
return Promise.resolve(this.channel.call<void>('uninstall', [extension!, options]));
}

reinstallFromGallery(extension: ILocalExtension): Promise<void> {
return Promise.resolve(this.channel.call<void>('reinstallFromGallery', [extension]));
reinstallFromGallery(extension: ILocalExtension): Promise<ILocalExtension> {
return Promise.resolve(this.channel.call<ILocalExtension>('reinstallFromGallery', [extension])).then(local => transformIncomingExtension(local, null));
}

getInstalled(type: ExtensionType | null = null, extensionsProfileResource?: URI): Promise<ILocalExtension[]> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class ExtensionManagementService extends AbstractExtensionManagementServi
return local;
}

async reinstallFromGallery(extension: ILocalExtension): Promise<void> {
async reinstallFromGallery(extension: ILocalExtension): Promise<ILocalExtension> {
this.logService.trace('ExtensionManagementService#reinstallFromGallery', extension.identifier.id);
if (!this.galleryService.isEnabled()) {
throw new Error(nls.localize('MarketPlaceDisabled', "Marketplace is not enabled"));
Expand All @@ -201,7 +201,7 @@ export class ExtensionManagementService extends AbstractExtensionManagementServi
} catch (e) {
throw new Error(nls.localize('removeError', "Error while removing the extension: {0}. Please Quit and Start VS Code before trying again.", toErrorMessage(e)));
}
await this.installFromGallery(galleryExtension);
return this.installFromGallery(galleryExtension);
}

markAsUninstalled(...extensions: IExtension[]): Promise<void> {
Expand Down
46 changes: 9 additions & 37 deletions src/vs/workbench/contrib/extensions/browser/extensionsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView
import { disposeIfDisposable } from 'vs/base/common/lifecycle';
import { IExtension, ExtensionState, IExtensionsWorkbenchService, VIEWLET_ID, IExtensionsViewPaneContainer, IExtensionContainer, TOGGLE_IGNORE_EXTENSION_ACTION_ID, SELECT_INSTALL_VSIX_EXTENSION_COMMAND_ID, THEME_ACTIONS_GROUP, INSTALL_ACTIONS_GROUP } from 'vs/workbench/contrib/extensions/common/extensions';
import { ExtensionsConfigurationInitialContent } from 'vs/workbench/contrib/extensions/common/extensionsFileTemplate';
import { IGalleryExtension, IExtensionGalleryService, ILocalExtension, InstallOptions, InstallOperation, TargetPlatformToString, ExtensionManagementErrorCode, isTargetPlatformCompatible } from 'vs/platform/extensionManagement/common/extensionManagement';
import { IGalleryExtension, IExtensionGalleryService, ILocalExtension, InstallOptions, InstallOperation, TargetPlatformToString, ExtensionManagementErrorCode } from 'vs/platform/extensionManagement/common/extensionManagement';
import { IWorkbenchExtensionEnablementService, EnablementState, IExtensionManagementServerService, IExtensionManagementServer, IWorkbenchExtensionManagementService } from 'vs/workbench/services/extensionManagement/common/extensionManagement';
import { ExtensionRecommendationReason, IExtensionIgnoredRecommendationsService, IExtensionRecommendationsService } from 'vs/workbench/services/extensionRecommendations/common/extensionRecommendations';
import { areSameExtensions, getExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
Expand Down Expand Up @@ -567,12 +567,9 @@ export abstract class InstallInOtherServerAction extends ExtensionAction {
id: string,
private readonly server: IExtensionManagementServer | null,
private readonly canInstallAnyWhere: boolean,
@IFileService private readonly fileService: IFileService,
@ILogService private readonly logService: ILogService,
@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
@IExtensionManagementServerService protected readonly extensionManagementServerService: IExtensionManagementServerService,
@IExtensionManifestPropertiesService private readonly extensionManifestPropertiesService: IExtensionManifestPropertiesService,
@IExtensionGalleryService private readonly extensionGalleryService: IExtensionGalleryService,
) {
super(id, InstallInOtherServerAction.INSTALL_LABEL, InstallInOtherServerAction.Class, false);
this.update();
Expand Down Expand Up @@ -658,26 +655,7 @@ export abstract class InstallInOtherServerAction extends ExtensionAction {
}
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));

const gallery = this.extension.gallery ?? (this.extensionGalleryService.isEnabled() && (await this.extensionGalleryService.getExtensions([this.extension.identifier], CancellationToken.None))[0]);
if (gallery) {
await this.server.extensionManagementService.installFromGallery(gallery, { installPreReleaseVersion: this.extension.local.preRelease });
return;
}
const targetPlatform = await this.server.extensionManagementService.getTargetPlatform();
if (!isTargetPlatformCompatible(this.extension.local.targetPlatform, [this.extension.local.targetPlatform], targetPlatform)) {
throw new Error(localize('incompatible', "Can't install '{0}' extension because it is not compatible.", this.extension.identifier.id));
}
const vsix = await this.extension.server.extensionManagementService.zip(this.extension.local);
try {
await this.server.extensionManagementService.install(vsix);
} finally {
try {
await this.fileService.del(vsix);
} catch (error) {
this.logService.error(error);
}
}
return this.extensionsWorkbenchService.installInServer(this.extension, this.server);
}

protected abstract getInstallLabel(): string;
Expand All @@ -687,14 +665,11 @@ export class RemoteInstallAction extends InstallInOtherServerAction {

constructor(
canInstallAnyWhere: boolean,
@IFileService fileService: IFileService,
@ILogService logService: ILogService,
@IExtensionsWorkbenchService extensionsWorkbenchService: IExtensionsWorkbenchService,
@IExtensionManagementServerService extensionManagementServerService: IExtensionManagementServerService,
@IExtensionManifestPropertiesService extensionManifestPropertiesService: IExtensionManifestPropertiesService,
@IExtensionGalleryService extensionGalleryService: IExtensionGalleryService,
) {
super(`extensions.remoteinstall`, extensionManagementServerService.remoteExtensionManagementServer, canInstallAnyWhere, fileService, logService, extensionsWorkbenchService, extensionManagementServerService, extensionManifestPropertiesService, extensionGalleryService);
super(`extensions.remoteinstall`, extensionManagementServerService.remoteExtensionManagementServer, canInstallAnyWhere, extensionsWorkbenchService, extensionManagementServerService, extensionManifestPropertiesService);
}

protected getInstallLabel(): string {
Expand All @@ -708,14 +683,11 @@ export class RemoteInstallAction extends InstallInOtherServerAction {
export class LocalInstallAction extends InstallInOtherServerAction {

constructor(
@IFileService fileService: IFileService,
@ILogService logService: ILogService,
@IExtensionsWorkbenchService extensionsWorkbenchService: IExtensionsWorkbenchService,
@IExtensionManagementServerService extensionManagementServerService: IExtensionManagementServerService,
@IExtensionManifestPropertiesService extensionManifestPropertiesService: IExtensionManifestPropertiesService,
@IExtensionGalleryService extensionGalleryService: IExtensionGalleryService,
) {
super(`extensions.localinstall`, extensionManagementServerService.localExtensionManagementServer, false, fileService, logService, extensionsWorkbenchService, extensionManagementServerService, extensionManifestPropertiesService, extensionGalleryService);
super(`extensions.localinstall`, extensionManagementServerService.localExtensionManagementServer, false, extensionsWorkbenchService, extensionManagementServerService, extensionManifestPropertiesService);
}

protected getInstallLabel(): string {
Expand All @@ -727,14 +699,11 @@ export class LocalInstallAction extends InstallInOtherServerAction {
export class WebInstallAction extends InstallInOtherServerAction {

constructor(
@IFileService fileService: IFileService,
@ILogService logService: ILogService,
@IExtensionsWorkbenchService extensionsWorkbenchService: IExtensionsWorkbenchService,
@IExtensionManagementServerService extensionManagementServerService: IExtensionManagementServerService,
@IExtensionManifestPropertiesService extensionManifestPropertiesService: IExtensionManifestPropertiesService,
@IExtensionGalleryService extensionGalleryService: IExtensionGalleryService,
) {
super(`extensions.webInstall`, extensionManagementServerService.webExtensionManagementServer, false, fileService, logService, extensionsWorkbenchService, extensionManagementServerService, extensionManifestPropertiesService, extensionGalleryService);
super(`extensions.webInstall`, extensionManagementServerService.webExtensionManagementServer, false, extensionsWorkbenchService, extensionManagementServerService, extensionManifestPropertiesService);
}

protected getInstallLabel(): string {
Expand Down Expand Up @@ -2067,6 +2036,7 @@ export class ExtensionStatusLabelAction extends Action implements IExtensionCont

private initialStatus: ExtensionState | null = null;
private status: ExtensionState | null = null;
private version: string | null = null;
private enablementState: EnablementState | null = null;

private _extension: IExtension | null = null;
Expand Down Expand Up @@ -2102,8 +2072,10 @@ export class ExtensionStatusLabelAction extends Action implements IExtensionCont
}

const currentStatus = this.status;
const currentVersion = this.version;
const currentEnablementState = this.enablementState;
this.status = this.extension.state;
this.version = this.extension.version;
if (this.initialStatus === null) {
this.initialStatus = this.status;
}
Expand Down Expand Up @@ -2131,7 +2103,7 @@ export class ExtensionStatusLabelAction extends Action implements IExtensionCont

if (currentStatus !== null) {
if (currentStatus === ExtensionState.Installing && this.status === ExtensionState.Installed) {
return canAddExtension() ? this.initialStatus === ExtensionState.Installed ? localize('updated', "Updated") : localize('installed', "Installed") : null;
return canAddExtension() ? this.initialStatus === ExtensionState.Installed && this.version !== currentVersion ? localize('updated', "Updated") : localize('installed', "Installed") : null;
}
if (currentStatus === ExtensionState.Uninstalling && this.status === ExtensionState.Uninstalled) {
this.initialStatus = this.status;
Expand Down
Loading

0 comments on commit 4205170

Please sign in to comment.