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 7, 2021
1 parent 3420ef6 commit 2b07510
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
14 changes: 13 additions & 1 deletion packages/vsx-registry/src/browser/vsx-extensions-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,18 @@ export class VSXExtensionsModel {

protected async refresh(id: string): Promise<VSXExtension | undefined> {
try {
let extension = this.getExtension(id);
if (!this.shouldRefresh(extension)) {
return extension;
}
const data = await this.api.getLatestCompatibleExtensionVersion(id);
if (!data) {
return;
}
if (data.error) {
return this.onDidFailRefresh(id, data.error);
}
const extension = this.setExtension(id);
extension = this.setExtension(id);
extension.update(Object.assign(data, {
publisher: data.namespace,
downloadUrl: data.files.download,
Expand All @@ -239,6 +243,14 @@ export class VSXExtensionsModel {
}
}

/**
* Determines if the given extension should be refreshed.
* @param extension the extension to refresh.
*/
protected shouldRefresh(extension?: VSXExtension): boolean {
return extension?.builtin !== true;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
protected onDidFailRefresh(id: string, error: any): VSXExtension | undefined {
const cached = this.getExtension(id);
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 2b07510

Please sign in to comment.