Skip to content

Commit

Permalink
Complete implementation of 'Install another version' command
Browse files Browse the repository at this point in the history
Signed-off-by: Colin Grant <[email protected]>
  • Loading branch information
Colin Grant committed Nov 4, 2021
1 parent a8dbe89 commit bdc4fac
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export namespace VSXExtensionsCommands {
};
export const INSTALL_ANOTHER_VERSION: Command = {
id: 'vsxExtensions.installAnotherVersion'
}
};
export const COPY: Command = {
id: 'vsxExtensions.copy'
};
Expand Down
25 changes: 15 additions & 10 deletions packages/vsx-registry/src/browser/vsx-extensions-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ import { ClipboardService } from '@theia/core/lib/browser/clipboard-service';
import { BUILTIN_QUERY, INSTALLED_QUERY, RECOMMENDED_QUERY } from './vsx-extensions-search-model';
import { IGNORE_RECOMMENDATIONS_ID } from './recommended-extensions/recommended-extensions-preference-contribution';
import { VSXExtensionsCommands } from './vsx-extension-commands';
import { VSXExtensionRaw, OVSXClient } from '@theia/ovsx-client';
import { VSXExtensionRaw } from '@theia/ovsx-client';
import { PluginServer } from '@theia/plugin-ext';
import { OVSXAsyncClient } from './ovsx-async-client';

/**
* @deprecated since 1.17.0. - Moved to `vsx-extension-commands.ts` to avoid circular dependencies. Import from there, instead.
Expand All @@ -52,9 +53,9 @@ export class VSXExtensionsContribution extends AbstractViewContribution<VSXExten
@inject(LabelProvider) protected readonly labelProvider: LabelProvider;
@inject(ClipboardService) protected readonly clipboardService: ClipboardService;
@inject(PreferenceService) protected readonly preferenceService: PreferenceService;
@inject(OVSXClient) protected readonly client: OVSXClient;
@inject(OVSXAsyncClient) protected readonly client: OVSXAsyncClient;
@inject(PluginServer) protected readonly pluginServer: PluginServer;
@inject(QuickInputService) protected readonly quickInput: QuickInputService
@inject(QuickInputService) protected readonly quickInput: QuickInputService;

constructor() {
super({
Expand Down Expand Up @@ -95,6 +96,7 @@ export class VSXExtensionsContribution extends AbstractViewContribution<VSXExten

commands.registerCommand({ id: VSXExtensionsCommands.INSTALL_ANOTHER_VERSION.id }, {
execute: async (extension: VSXExtension) => this.installAnotherVersion(extension),
// Check downloadUrl to ensure we have an idea of where to look for other versions.
isEnabled: (extension: VSXExtension) => !extension.builtin && !!extension.downloadUrl
});

Expand Down Expand Up @@ -133,7 +135,7 @@ export class VSXExtensionsContribution extends AbstractViewContribution<VSXExten
});
menus.registerMenuAction(VSXExtensionsContextMenu.INSTALL, {
commandId: VSXExtensionsCommands.INSTALL_ANOTHER_VERSION.id,
label: 'Install Another Version...'
label: nls.localize('vscode/extensionsActions/install another version', 'Install Another Version...')
});
}

Expand Down Expand Up @@ -189,10 +191,10 @@ export class VSXExtensionsContribution extends AbstractViewContribution<VSXExten
}

/**
* Given an extension, displays a quick pick of other compatible versions and installs the selected version.
*
* @param extension a VSX extension.
*/
* Given an extension, displays a quick pick of other compatible versions and installs the selected version.
*
* @param extension a VSX extension.
*/
protected async installAnotherVersion(extension: VSXExtension): Promise<void> {
const extensionId = extension.id;
const currentVersion = extension.version;
Expand All @@ -213,7 +215,7 @@ export class VSXExtensionsContribution extends AbstractViewContribution<VSXExten
description: publishedDate
});
});
const selectedItem = await this.quickInput.showQuickPick(items, { placeholder: 'Select Version to Install', runIfSingle: false });
const selectedItem = await this.quickInput.showQuickPick(items, { placeholder: nls.localize('vscode/extensionsActions/selectVersion', 'Select Version to Install'), runIfSingle: false });
if (selectedItem && currentVersion && selectedItem.label !== currentVersion) {
const selectedExtension = this.model.getExtension(extensionId);
if (selectedExtension) {
Expand Down Expand Up @@ -241,12 +243,15 @@ export class VSXExtensionsContribution extends AbstractViewContribution<VSXExten
try {
await extension.uninstall();
} catch {
this.messageService.warn(nls.localized('theia/vsx-registry/failedUninstallExisting', 'Failed to uninstall existing plugin version.'));
return;
}
try {
await extension.install({ version: updateToVersion });
} catch {
await extension.install({ version: revertToVersion });
await extension.install({ version: revertToVersion })
.then(() => this.messageService.warn(nls.localize('theia/vsx-registry/failedUpdate', 'Failed to update {0} to {1}. Now on {2}.', extension.displayName, updateToVersion, revertToVersion)))
.catch(() => this.messageService.warn(nls.localize('theia/vsx-registry/failedUpdateRestore', 'Failed to update {0} or restore previous version. The plugin has been uninstalled', extension.displayName)));
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/vsx-registry/src/browser/vsx-extensions-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export class VSXExtensionsModel {
}
for (const id of this._installed) {
const extension = this.getExtension(id);
if (!extension) continue;
if (!extension) {continue; }
refreshing.push(this.refresh(id, extension.version));
}
Promise.all(refreshing);
Expand Down
26 changes: 9 additions & 17 deletions packages/vsx-registry/src/node/vsx-extension-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,22 @@ export class VSXExtensionResolver implements PluginDeployerResolver {
if (!id) {
return;
}
let extensionVersion: string | undefined;
let extension: VSXExtensionRaw | undefined;
const client = await this.clientProvider();
if (options) {
extensionVersion = options.version;
console.log(`[${id}]: trying to resolve version ${extensionVersion}...`);
extension = await client.getExtension(id, { extensionVersion: extensionVersion });
if (!extension) {
return;
}
if (extension.error) {
throw new Error(extension.error);
}
console.log(`[${id}]: trying to resolve version ${options.version}...`);
extension = await client.getExtension(id, { extensionVersion: options.version });
} else {
console.log(`[${id}]: trying to resolve latest version...`);
extension = await client.getLatestCompatibleExtensionVersion(id);
if (!extension) {
return;
}
if (extension.error) {
throw new Error(extension.error);
}
extensionVersion = extension.version;
}
if (!extension) {
return;
}
if (extension.error) {
throw new Error(extension.error);
}
const extensionVersion = extension.version;
const resolvedId = id + '-' + extensionVersion;
const downloadUrl = extension.files.download;
console.log(`[${id}]: resolved to '${resolvedId}'`);
Expand Down

0 comments on commit bdc4fac

Please sign in to comment.