Skip to content

Commit

Permalink
vsx-registry: update api-compatibility handling
Browse files Browse the repository at this point in the history
The following commit updates the logic present in `@theia/vsx-registry`
which is used to determine API-compatible extensions. The changes update
the previous assumption that vscode-builtin extensions could not be
downloaded through the extensions-view.

The updated logic behaves in the following way:
- builtins bundled with the application are excluded from fetching their
  compatible version.
- builtins installed through the extensions-view are checked for their
  latest compatible version.

Signed-off-by: vince-fugnitto <[email protected]>
  • Loading branch information
vince-fugnitto committed Apr 6, 2021
1 parent 3420ef6 commit a9483c3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
22 changes: 20 additions & 2 deletions packages/vsx-registry/src/browser/vsx-extensions-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import * as sanitize from 'sanitize-html';
import { Emitter } from '@theia/core/lib/common/event';
import { CancellationToken, CancellationTokenSource } from '@theia/core/lib/common/cancellation';
import { VSXRegistryAPI, VSXResponseError } from '../common/vsx-registry-api';
import { VSXSearchParam } from '../common/vsx-registry-types';
import { VSXExtensionRaw, VSXSearchParam } from '../common/vsx-registry-types';
import { HostedPluginSupport } from '@theia/plugin-ext/lib/hosted/browser/hosted-plugin';
import { VSXExtension, VSXExtensionFactory } from './vsx-extension';
import { ProgressService } from '@theia/core/lib/common/progress-service';
Expand Down Expand Up @@ -217,7 +217,7 @@ export class VSXExtensionsModel {

protected async refresh(id: string): Promise<VSXExtension | undefined> {
try {
const data = await this.api.getLatestCompatibleExtensionVersion(id);
const data = await this.getExtensionRaw(id);
if (!data) {
return;
}
Expand Down Expand Up @@ -249,6 +249,24 @@ export class VSXExtensionsModel {
return undefined;
}

protected isBuiltin(id: string): boolean {
return this.getExtension(id)?.builtin === true;
}

/**
* Get the extension raw data if it exists.
* - If the extension is a builtin, no compatibility check is performed.
* - If the extension is not a builtin, the latest compatible version should be fetched.
* @param id the extension id.
*
* @returns the extension data if it exists.
*/
protected async getExtensionRaw(id: string): Promise<VSXExtensionRaw | undefined> {
return this.isBuiltin(id)
? this.api.getExtension(id)
: this.api.getLatestCompatibleExtensionVersion(id);
}

/**
* Compare two extensions based on their display name, and publisher if applicable.
* @param a the first extension id for comparison.
Expand Down
10 changes: 1 addition & 9 deletions packages/vsx-registry/src/common/vsx-registry-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ export namespace VSXResponseError {
}
}

/**
* Namespace reserved for vscode builtin extensions.
*/
const VSCODE_NAMESPACE = 'vscode';

@injectable()
export class VSXRegistryAPI {

Expand Down Expand Up @@ -145,10 +140,7 @@ export class VSXRegistryAPI {
const extensions = await this.getAllVersions(id);
for (let i = 0; i < extensions.length; i++) {
const extension: VSXExtensionRaw = extensions[i];
// Skip vscode builtin extensions.
if (extension.namespace === VSCODE_NAMESPACE) {
return extension;
} else if (extension.engines && this.isEngineSupported(extension.engines.vscode)) {
if (extension.engines && this.isEngineSupported(extension.engines.vscode)) {
return extension;
}
}
Expand Down

0 comments on commit a9483c3

Please sign in to comment.