From 2921b424ae8ee3808bc6d0cb4701b15d923d4dde Mon Sep 17 00:00:00 2001 From: vince-fugnitto Date: Tue, 26 Oct 2021 15:47:49 -0400 Subject: [PATCH 1/6] ovsx-client: introduce async provider The commit fixes an issue where previously the backend would never properly read the cli arguments in time to create the ovsx-client. This meant that while the api-version was respected when searching in the view, it was not when installing. The change removes the use of `OVSXAsyncClient` and instead uses an `async` provider of `OVSXClient` which will probably be set with the correct api version and url when ready. Signed-off-by: vince-fugnitto --- dev-packages/ovsx-client/src/ovsx-client.ts | 4 +++ .../src/browser/vsx-extensions-model.ts | 18 +++++----- .../browser/vsx-registry-frontend-module.ts | 15 ++------ .../ovsx-client-provider.ts} | 34 +++++++------------ .../src/node/vsx-extension-resolver.ts | 9 ++--- .../src/node/vsx-registry-backend-module.ts | 12 ++----- 6 files changed, 36 insertions(+), 56 deletions(-) rename packages/vsx-registry/src/{browser/ovsx-async-client.ts => common/ovsx-client-provider.ts} (51%) diff --git a/dev-packages/ovsx-client/src/ovsx-client.ts b/dev-packages/ovsx-client/src/ovsx-client.ts index 685316a6bcd46..f79dacf8f9532 100644 --- a/dev-packages/ovsx-client/src/ovsx-client.ts +++ b/dev-packages/ovsx-client/src/ovsx-client.ts @@ -34,6 +34,10 @@ export interface OVSXClientOptions { apiVersion: string apiUrl: string } + +export const OVSXClientProvider = Symbol('OVSXClientProvider'); +export type OVSXClientProvider = () => Promise; + export class OVSXClient { constructor(readonly options: OVSXClientOptions) { } diff --git a/packages/vsx-registry/src/browser/vsx-extensions-model.ts b/packages/vsx-registry/src/browser/vsx-extensions-model.ts index ba611fdc387f7..95fcc4c997e26 100644 --- a/packages/vsx-registry/src/browser/vsx-extensions-model.ts +++ b/packages/vsx-registry/src/browser/vsx-extensions-model.ts @@ -30,7 +30,7 @@ import { WorkspaceService } from '@theia/workspace/lib/browser'; import { RecommendedExtensions } from './recommended-extensions/recommended-extensions-preference-contribution'; import URI from '@theia/core/lib/common/uri'; import { VSXResponseError, VSXSearchParam } from '@theia/ovsx-client/lib/ovsx-types'; -import { OVSXAsyncClient } from './ovsx-async-client'; +import { OVSXClientProvider } from '@theia/ovsx-client'; @injectable() export class VSXExtensionsModel { @@ -38,8 +38,8 @@ export class VSXExtensionsModel { protected readonly onDidChangeEmitter = new Emitter(); readonly onDidChange = this.onDidChangeEmitter.event; - @inject(OVSXAsyncClient) - protected client: OVSXAsyncClient; + @inject(OVSXClientProvider) + protected clientProvider: OVSXClientProvider; @inject(HostedPluginSupport) protected readonly pluginSupport: HostedPluginSupport; @@ -63,7 +63,6 @@ export class VSXExtensionsModel { @postConstruct() protected async init(): Promise { - await this.client.ready; await Promise.all([ this.initInstalled(), this.initSearchResult(), @@ -167,14 +166,15 @@ export class VSXExtensionsModel { }, 150); protected doUpdateSearchResult(param: VSXSearchParam, token: CancellationToken): Promise { return this.doChange(async () => { - const result = await this.client.search(param); + const client = await this.clientProvider(); + const result = await client.search(param); if (token.isCancellationRequested) { return; } const searchResult = new Set(); for (const data of result.extensions) { const id = data.namespace.toLowerCase() + '.' + data.name.toLowerCase(); - const extension = this.client.getLatestCompatibleVersion(data); + const extension = client.getLatestCompatibleVersion(data); if (!extension) { continue; } @@ -260,7 +260,8 @@ export class VSXExtensionsModel { } if (extension.readmeUrl) { try { - const rawReadme = await this.client.fetchText(extension.readmeUrl); + const client = await this.clientProvider(); + const rawReadme = await client.fetchText(extension.readmeUrl); const readme = this.compileReadme(rawReadme); extension.update({ readme }); } catch (e) { @@ -292,7 +293,8 @@ export class VSXExtensionsModel { if (!this.shouldRefresh(extension)) { return extension; } - const data = await this.client.getLatestCompatibleExtensionVersion(id); + const client = await this.clientProvider(); + const data = await client.getLatestCompatibleExtensionVersion(id); if (!data) { return; } diff --git a/packages/vsx-registry/src/browser/vsx-registry-frontend-module.ts b/packages/vsx-registry/src/browser/vsx-registry-frontend-module.ts index 300de4549dbb7..41433cc97c335 100644 --- a/packages/vsx-registry/src/browser/vsx-registry-frontend-module.ts +++ b/packages/vsx-registry/src/browser/vsx-registry-frontend-module.ts @@ -28,24 +28,13 @@ import { VSXExtensionFactory, VSXExtension, VSXExtensionOptions } from './vsx-ex import { VSXExtensionEditor } from './vsx-extension-editor'; import { VSXExtensionEditorManager } from './vsx-extension-editor-manager'; import { VSXExtensionsSourceOptions } from './vsx-extensions-source'; -import { VSXEnvironment } from '../common/vsx-environment'; import { VSXExtensionsSearchModel } from './vsx-extensions-search-model'; import { bindExtensionPreferences } from './recommended-extensions/recommended-extensions-preference-contribution'; import { bindPreferenceProviderOverrides } from './recommended-extensions/preference-provider-overrides'; -import { OVSXAsyncClient } from './ovsx-async-client'; +import { bindOVSXClientProvider } from '../common/ovsx-client-provider'; export default new ContainerModule((bind, unbind) => { - bind(VSXEnvironment).toSelf().inSingletonScope(); - bind(OVSXAsyncClient).toDynamicValue(ctx => { - const vsxEnvironment = ctx.container.get(VSXEnvironment); - return new OVSXAsyncClient(Promise.all([ - vsxEnvironment.getVscodeApiVersion(), - vsxEnvironment.getRegistryApiUri() - ]).then(([apiVersion, apiUri]) => ({ - apiVersion, - apiUrl: apiUri.toString() - }))); - }).inSingletonScope(); + bindOVSXClientProvider(bind); bind(VSXExtension).toSelf(); bind(VSXExtensionFactory).toFactory(ctx => (option: VSXExtensionOptions) => { diff --git a/packages/vsx-registry/src/browser/ovsx-async-client.ts b/packages/vsx-registry/src/common/ovsx-client-provider.ts similarity index 51% rename from packages/vsx-registry/src/browser/ovsx-async-client.ts rename to packages/vsx-registry/src/common/ovsx-client-provider.ts index 56871769e873d..00a5b02908fbc 100644 --- a/packages/vsx-registry/src/browser/ovsx-async-client.ts +++ b/packages/vsx-registry/src/common/ovsx-client-provider.ts @@ -14,26 +14,18 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ -import { OVSXClient, OVSXClientOptions } from '@theia/ovsx-client/lib'; +import { interfaces } from '@theia/core/shared/inversify'; +import { OVSXClient, OVSXClientProvider } from '@theia/ovsx-client'; +import { VSXEnvironment } from './vsx-environment'; -/** - * In some instances, the OVSXClient must be created asynchronously. This class - * makes it possible to get an un-initialized instance and wait for it to be ready. - */ -export class OVSXAsyncClient extends OVSXClient { - - /** - * Resolves once the initial asynchronous options are resolved. - * - * Calling methods before this promise is resolved will throw errors. - */ - readonly ready: Promise; - - constructor(asyncOptions: Promise) { - super(undefined!); // hack: using methods at this point will fail. - this.ready = asyncOptions.then(options => { - (this.options as OVSXClientOptions) = options; - return this; - }); - } +export function bindOVSXClientProvider(bind: interfaces.Bind): void { + bind(VSXEnvironment).toSelf().inSingletonScope(); + bind(OVSXClientProvider).toProvider(ctx => async () => { + const vsxEnvironment = ctx.container.get(VSXEnvironment); + const [apiVersion, apiUrl] = await Promise.all([ + vsxEnvironment.getVscodeApiVersion(), + vsxEnvironment.getRegistryApiUri() + ]); + return new OVSXClient({ apiVersion, apiUrl: apiUrl.toString() }); + }); } diff --git a/packages/vsx-registry/src/node/vsx-extension-resolver.ts b/packages/vsx-registry/src/node/vsx-extension-resolver.ts index 029afe1470078..61865b0c18c5a 100644 --- a/packages/vsx-registry/src/node/vsx-extension-resolver.ts +++ b/packages/vsx-registry/src/node/vsx-extension-resolver.ts @@ -23,13 +23,13 @@ import { injectable, inject } from '@theia/core/shared/inversify'; import URI from '@theia/core/lib/common/uri'; import { PluginDeployerResolver, PluginDeployerResolverContext } from '@theia/plugin-ext/lib/common/plugin-protocol'; import { VSXExtensionUri } from '../common/vsx-extension-uri'; -import { OVSXClient } from '@theia/ovsx-client/lib/ovsx-client'; +import { OVSXClientProvider } from '@theia/ovsx-client'; @injectable() export class VSXExtensionResolver implements PluginDeployerResolver { - @inject(OVSXClient) - protected client: OVSXClient; + @inject(OVSXClientProvider) + protected clientProvider: OVSXClientProvider; protected readonly downloadPath: string; @@ -49,7 +49,8 @@ export class VSXExtensionResolver implements PluginDeployerResolver { return; } console.log(`[${id}]: trying to resolve latest version...`); - const extension = await this.client.getLatestCompatibleExtensionVersion(id); + const client = await this.clientProvider(); + const extension = await client.getLatestCompatibleExtensionVersion(id); if (!extension) { return; } diff --git a/packages/vsx-registry/src/node/vsx-registry-backend-module.ts b/packages/vsx-registry/src/node/vsx-registry-backend-module.ts index cbb4a41f767f5..af61e55ae7181 100644 --- a/packages/vsx-registry/src/node/vsx-registry-backend-module.ts +++ b/packages/vsx-registry/src/node/vsx-registry-backend-module.ts @@ -17,18 +17,10 @@ import { ContainerModule } from '@theia/core/shared/inversify'; import { VSXExtensionResolver } from './vsx-extension-resolver'; import { PluginDeployerResolver } from '@theia/plugin-ext/lib/common/plugin-protocol'; -import { VSCODE_DEFAULT_API_VERSION, VSX_REGISTRY_URL_DEFAULT } from '@theia/plugin-ext-vscode/lib/common/plugin-vscode-types'; -import { OVSXClient } from '@theia/ovsx-client/lib/ovsx-client'; +import { bindOVSXClientProvider } from '../common/ovsx-client-provider'; export default new ContainerModule(bind => { - bind(OVSXClient).toConstantValue(new OVSXClient({ - apiVersion: process.env['VSCODE_API_VERSION'] || VSCODE_DEFAULT_API_VERSION, - apiUrl: resolveRegistryUrl() - })); + bindOVSXClientProvider(bind); bind(VSXExtensionResolver).toSelf().inSingletonScope(); bind(PluginDeployerResolver).toService(VSXExtensionResolver); }); - -function resolveRegistryUrl(): string { - return process.env['VSX_REGISTRY_URL'] || VSX_REGISTRY_URL_DEFAULT; -} From c236176b9a19090ec6f97060cac03b9a91e9bb0b Mon Sep 17 00:00:00 2001 From: Paul Marechal Date: Wed, 27 Oct 2021 16:01:40 -0400 Subject: [PATCH 2/6] properly read value from the cli --- dev-packages/ovsx-client/src/ovsx-client.ts | 3 -- .../node/plugin-vscode-cli-contribution.ts | 21 +++++--- .../src/browser/vsx-extension.tsx | 2 +- .../src/browser/vsx-extensions-model.ts | 2 +- .../browser/vsx-registry-frontend-module.ts | 12 +++-- .../src/common/ovsx-client-provider.ts | 22 ++++---- .../src/common/vsx-environment.ts | 24 +++++++++ .../src/common/vsx-environment.tsx | 51 ------------------- .../src/node/vsx-environment-impl.ts | 41 +++++++++++++++ .../src/node/vsx-extension-resolver.ts | 2 +- .../src/node/vsx-registry-backend-module.ts | 11 +++- 11 files changed, 111 insertions(+), 80 deletions(-) create mode 100644 packages/vsx-registry/src/common/vsx-environment.ts delete mode 100644 packages/vsx-registry/src/common/vsx-environment.tsx create mode 100644 packages/vsx-registry/src/node/vsx-environment-impl.ts diff --git a/dev-packages/ovsx-client/src/ovsx-client.ts b/dev-packages/ovsx-client/src/ovsx-client.ts index f79dacf8f9532..2d49873d29aa6 100644 --- a/dev-packages/ovsx-client/src/ovsx-client.ts +++ b/dev-packages/ovsx-client/src/ovsx-client.ts @@ -35,9 +35,6 @@ export interface OVSXClientOptions { apiUrl: string } -export const OVSXClientProvider = Symbol('OVSXClientProvider'); -export type OVSXClientProvider = () => Promise; - export class OVSXClient { constructor(readonly options: OVSXClientOptions) { } diff --git a/packages/plugin-ext-vscode/src/node/plugin-vscode-cli-contribution.ts b/packages/plugin-ext-vscode/src/node/plugin-vscode-cli-contribution.ts index a16c8272aabf5..fb5bcd887f906 100644 --- a/packages/plugin-ext-vscode/src/node/plugin-vscode-cli-contribution.ts +++ b/packages/plugin-ext-vscode/src/node/plugin-vscode-cli-contribution.ts @@ -19,6 +19,7 @@ import { Argv, Arguments } from '@theia/core/shared/yargs'; import { CliContribution } from '@theia/core/lib/node/cli'; import { PluginHostEnvironmentVariable } from '@theia/plugin-ext/lib/common'; import { VSCODE_DEFAULT_API_VERSION } from '../common/plugin-vscode-types'; +import { Deferred } from '@theia/core/lib/common/promise-util'; /** * CLI Contribution allowing to override the VS Code API version which is returned by `vscode.version` API call. @@ -26,25 +27,33 @@ import { VSCODE_DEFAULT_API_VERSION } from '../common/plugin-vscode-types'; @injectable() export class PluginVsCodeCliContribution implements CliContribution, PluginHostEnvironmentVariable { + /** + * CLI argument name to define the supported VS Code API version. + */ static VSCODE_API_VERSION = 'vscode-api-version'; - protected vsCodeApiVersion: string | undefined; + protected vsCodeApiVersion?: string; + protected vsCodeApiVersionDeferred = new Deferred(); + + get vsCodeApiVersionPromise(): Promise { + return this.vsCodeApiVersionDeferred.promise; + } configure(conf: Argv): void { conf.option(PluginVsCodeCliContribution.VSCODE_API_VERSION, { // eslint-disable-next-line max-len description: `Overrides the version returned by VSCode API 'vscode.version'. Example: --${PluginVsCodeCliContribution.VSCODE_API_VERSION}=. Default [${VSCODE_DEFAULT_API_VERSION}]`, + default: VSCODE_DEFAULT_API_VERSION, type: 'string', nargs: 1 }); } setArguments(args: Arguments): void { - const arg = args[PluginVsCodeCliContribution.VSCODE_API_VERSION] as string; - if (arg) { - this.vsCodeApiVersion = arg; - this.process(process.env); - } + const arg = args[PluginVsCodeCliContribution.VSCODE_API_VERSION] as string | undefined; + this.vsCodeApiVersion = arg?.trim() || VSCODE_DEFAULT_API_VERSION; + process.env['VSCODE_API_VERSION'] = this.vsCodeApiVersion; + this.vsCodeApiVersionDeferred.resolve(this.vsCodeApiVersion); } process(env: NodeJS.ProcessEnv): void { diff --git a/packages/vsx-registry/src/browser/vsx-extension.tsx b/packages/vsx-registry/src/browser/vsx-extension.tsx index a16b1dc65ba4e..baf870e13bdda 100644 --- a/packages/vsx-registry/src/browser/vsx-extension.tsx +++ b/packages/vsx-registry/src/browser/vsx-extension.tsx @@ -322,7 +322,7 @@ export class VSXExtension implements VSXExtensionData, TreeElement { * @returns the registry link for the given extension at the path. */ async getRegistryLink(path = ''): Promise { - const uri = await this.environment.getRegistryUri(); + const uri = new URI(await this.environment.getRegistryUri()); return uri.resolve('extension/' + this.id.replace('.', '/')).resolve(path); } diff --git a/packages/vsx-registry/src/browser/vsx-extensions-model.ts b/packages/vsx-registry/src/browser/vsx-extensions-model.ts index 95fcc4c997e26..3fa521820032d 100644 --- a/packages/vsx-registry/src/browser/vsx-extensions-model.ts +++ b/packages/vsx-registry/src/browser/vsx-extensions-model.ts @@ -30,7 +30,7 @@ import { WorkspaceService } from '@theia/workspace/lib/browser'; import { RecommendedExtensions } from './recommended-extensions/recommended-extensions-preference-contribution'; import URI from '@theia/core/lib/common/uri'; import { VSXResponseError, VSXSearchParam } from '@theia/ovsx-client/lib/ovsx-types'; -import { OVSXClientProvider } from '@theia/ovsx-client'; +import { OVSXClientProvider } from '../common/ovsx-client-provider'; @injectable() export class VSXExtensionsModel { diff --git a/packages/vsx-registry/src/browser/vsx-registry-frontend-module.ts b/packages/vsx-registry/src/browser/vsx-registry-frontend-module.ts index 41433cc97c335..cac97a1c4502c 100644 --- a/packages/vsx-registry/src/browser/vsx-registry-frontend-module.ts +++ b/packages/vsx-registry/src/browser/vsx-registry-frontend-module.ts @@ -17,7 +17,9 @@ import '../../src/browser/style/index.css'; import { ContainerModule } from '@theia/core/shared/inversify'; -import { WidgetFactory, bindViewContribution, FrontendApplicationContribution, ViewContainerIdentifier, OpenHandler, WidgetManager } from '@theia/core/lib/browser'; +import { + WidgetFactory, bindViewContribution, FrontendApplicationContribution, ViewContainerIdentifier, OpenHandler, WidgetManager, WebSocketConnectionProvider +} from '@theia/core/lib/browser'; import { VSXExtensionsViewContainer } from './vsx-extensions-view-container'; import { VSXExtensionsContribution } from './vsx-extensions-contribution'; import { VSXExtensionsSearchBar } from './vsx-extensions-search-bar'; @@ -31,10 +33,14 @@ import { VSXExtensionsSourceOptions } from './vsx-extensions-source'; import { VSXExtensionsSearchModel } from './vsx-extensions-search-model'; import { bindExtensionPreferences } from './recommended-extensions/recommended-extensions-preference-contribution'; import { bindPreferenceProviderOverrides } from './recommended-extensions/preference-provider-overrides'; -import { bindOVSXClientProvider } from '../common/ovsx-client-provider'; +import { createOVSXClient, OVSXClientProvider } from '../common/ovsx-client-provider'; +import { VSXEnvironment, VSX_ENVIRONMENT_PATH } from '../common/vsx-environment'; export default new ContainerModule((bind, unbind) => { - bindOVSXClientProvider(bind); + bind(VSXEnvironment).toDynamicValue( + ctx => WebSocketConnectionProvider.createProxy(ctx.container, VSX_ENVIRONMENT_PATH) + ).inSingletonScope(); + bind(OVSXClientProvider).toProvider(ctx => () => createOVSXClient(ctx.container.get(VSXEnvironment))); bind(VSXExtension).toSelf(); bind(VSXExtensionFactory).toFactory(ctx => (option: VSXExtensionOptions) => { diff --git a/packages/vsx-registry/src/common/ovsx-client-provider.ts b/packages/vsx-registry/src/common/ovsx-client-provider.ts index 00a5b02908fbc..f85898dd56dfe 100644 --- a/packages/vsx-registry/src/common/ovsx-client-provider.ts +++ b/packages/vsx-registry/src/common/ovsx-client-provider.ts @@ -14,18 +14,16 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ -import { interfaces } from '@theia/core/shared/inversify'; -import { OVSXClient, OVSXClientProvider } from '@theia/ovsx-client'; +import { OVSXClient } from '@theia/ovsx-client'; import { VSXEnvironment } from './vsx-environment'; -export function bindOVSXClientProvider(bind: interfaces.Bind): void { - bind(VSXEnvironment).toSelf().inSingletonScope(); - bind(OVSXClientProvider).toProvider(ctx => async () => { - const vsxEnvironment = ctx.container.get(VSXEnvironment); - const [apiVersion, apiUrl] = await Promise.all([ - vsxEnvironment.getVscodeApiVersion(), - vsxEnvironment.getRegistryApiUri() - ]); - return new OVSXClient({ apiVersion, apiUrl: apiUrl.toString() }); - }); +export const OVSXClientProvider = Symbol('OVSXClientProvider'); +export type OVSXClientProvider = () => Promise; + +export async function createOVSXClient(vsxEnvironment: VSXEnvironment): Promise { + const [apiVersion, apiUrl] = await Promise.all([ + vsxEnvironment.getVscodeApiVersion(), + vsxEnvironment.getRegistryApiUri() + ]); + return new OVSXClient({ apiVersion, apiUrl: apiUrl.toString() }); } diff --git a/packages/vsx-registry/src/common/vsx-environment.ts b/packages/vsx-registry/src/common/vsx-environment.ts new file mode 100644 index 0000000000000..25ae36e78d7c2 --- /dev/null +++ b/packages/vsx-registry/src/common/vsx-environment.ts @@ -0,0 +1,24 @@ +/******************************************************************************** + * Copyright (C) 2021 Ericsson and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ + +export const VSX_ENVIRONMENT_PATH = '/services/vsx-environment'; + +export const VSXEnvironment = Symbol('VSXEnvironment'); +export interface VSXEnvironment { + getRegistryUri(): Promise; + getRegistryApiUri(): Promise; + getVscodeApiVersion(): Promise; +} diff --git a/packages/vsx-registry/src/common/vsx-environment.tsx b/packages/vsx-registry/src/common/vsx-environment.tsx deleted file mode 100644 index 5f70f3d0d480d..0000000000000 --- a/packages/vsx-registry/src/common/vsx-environment.tsx +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************** - * Copyright (C) 2020 TypeFox and others. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the Eclipse - * Public License v. 2.0 are satisfied: GNU General Public License, version 2 - * with the GNU Classpath Exception which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - ********************************************************************************/ - -import { injectable, inject } from '@theia/core/shared/inversify'; -import { EnvVariablesServer } from '@theia/core/lib/common/env-variables'; -import URI from '@theia/core/lib/common/uri'; -import { VSCODE_DEFAULT_API_VERSION } from '@theia/plugin-ext-vscode/lib/common/plugin-vscode-types'; - -@injectable() -export class VSXEnvironment { - - @inject(EnvVariablesServer) - protected readonly environments: EnvVariablesServer; - - protected _registryUri: URI | undefined; - async getRegistryUri(): Promise { - if (!this._registryUri) { - const vsxRegistryUrl = await this.environments.getValue('VSX_REGISTRY_URL'); - this._registryUri = new URI(vsxRegistryUrl && vsxRegistryUrl.value || 'https://open-vsx.org'); - } - return this._registryUri; - } - - async getRegistryApiUri(): Promise { - const registryUri = await this.getRegistryUri(); - return registryUri.resolve('api'); - } - - protected _apiVersion: string | undefined; - async getVscodeApiVersion(): Promise { - if (!this._apiVersion) { - const apiVersion = await this.environments.getValue('VSCODE_API_VERSION'); - this._apiVersion = apiVersion?.value || VSCODE_DEFAULT_API_VERSION; - } - return this._apiVersion; - } - -} diff --git a/packages/vsx-registry/src/node/vsx-environment-impl.ts b/packages/vsx-registry/src/node/vsx-environment-impl.ts new file mode 100644 index 0000000000000..86dbb0d8792b7 --- /dev/null +++ b/packages/vsx-registry/src/node/vsx-environment-impl.ts @@ -0,0 +1,41 @@ +/******************************************************************************** + * Copyright (C) 2020 TypeFox and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ + +import { injectable, inject } from '@theia/core/shared/inversify'; +import URI from '@theia/core/lib/common/uri'; +import { PluginVsCodeCliContribution } from '@theia/plugin-ext-vscode/lib/node/plugin-vscode-cli-contribution'; +import { VSXEnvironment } from '../common/vsx-environment'; + +@injectable() +export class VSXEnvironmentImpl implements VSXEnvironment { + + protected _registryUri = new URI(process.env['VSX_REGISTRY_URL']?.trim() || 'https://open-vsx.org'); + + @inject(PluginVsCodeCliContribution) + protected readonly pluginVscodeCli: PluginVsCodeCliContribution; + + async getRegistryUri(): Promise { + return this._registryUri.toString(true); + } + + async getRegistryApiUri(): Promise { + return this._registryUri.resolve('api').toString(true); + } + + async getVscodeApiVersion(): Promise { + return this.pluginVscodeCli.vsCodeApiVersionPromise; + } +} diff --git a/packages/vsx-registry/src/node/vsx-extension-resolver.ts b/packages/vsx-registry/src/node/vsx-extension-resolver.ts index 61865b0c18c5a..84cd5e939e635 100644 --- a/packages/vsx-registry/src/node/vsx-extension-resolver.ts +++ b/packages/vsx-registry/src/node/vsx-extension-resolver.ts @@ -23,7 +23,7 @@ import { injectable, inject } from '@theia/core/shared/inversify'; import URI from '@theia/core/lib/common/uri'; import { PluginDeployerResolver, PluginDeployerResolverContext } from '@theia/plugin-ext/lib/common/plugin-protocol'; import { VSXExtensionUri } from '../common/vsx-extension-uri'; -import { OVSXClientProvider } from '@theia/ovsx-client'; +import { OVSXClientProvider } from '../common/ovsx-client-provider'; @injectable() export class VSXExtensionResolver implements PluginDeployerResolver { diff --git a/packages/vsx-registry/src/node/vsx-registry-backend-module.ts b/packages/vsx-registry/src/node/vsx-registry-backend-module.ts index af61e55ae7181..e4e47a442ff1b 100644 --- a/packages/vsx-registry/src/node/vsx-registry-backend-module.ts +++ b/packages/vsx-registry/src/node/vsx-registry-backend-module.ts @@ -17,10 +17,17 @@ import { ContainerModule } from '@theia/core/shared/inversify'; import { VSXExtensionResolver } from './vsx-extension-resolver'; import { PluginDeployerResolver } from '@theia/plugin-ext/lib/common/plugin-protocol'; -import { bindOVSXClientProvider } from '../common/ovsx-client-provider'; +import { createOVSXClient, OVSXClientProvider } from '../common/ovsx-client-provider'; +import { VSXEnvironment, VSX_ENVIRONMENT_PATH } from '../common/vsx-environment'; +import { VSXEnvironmentImpl } from './vsx-environment-impl'; +import { ConnectionHandler, JsonRpcConnectionHandler } from '@theia/core'; export default new ContainerModule(bind => { - bindOVSXClientProvider(bind); + bind(VSXEnvironment).to(VSXEnvironmentImpl).inSingletonScope(); + bind(ConnectionHandler).toDynamicValue( + ctx => new JsonRpcConnectionHandler(VSX_ENVIRONMENT_PATH, () => ctx.container.get(VSXEnvironment)) + ).inSingletonScope(); + bind(OVSXClientProvider).toProvider(ctx => () => createOVSXClient(ctx.container.get(VSXEnvironment))); bind(VSXExtensionResolver).toSelf().inSingletonScope(); bind(PluginDeployerResolver).toService(VSXExtensionResolver); }); From 9b242590baabaeb14bb409b0fa848904a9a191db Mon Sep 17 00:00:00 2001 From: Paul Marechal Date: Wed, 27 Oct 2021 16:41:37 -0400 Subject: [PATCH 3/6] cache the OVSXClient --- .../src/browser/vsx-registry-frontend-module.ts | 8 ++++++-- .../vsx-registry/src/node/vsx-registry-backend-module.ts | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/vsx-registry/src/browser/vsx-registry-frontend-module.ts b/packages/vsx-registry/src/browser/vsx-registry-frontend-module.ts index cac97a1c4502c..4260995afeb97 100644 --- a/packages/vsx-registry/src/browser/vsx-registry-frontend-module.ts +++ b/packages/vsx-registry/src/browser/vsx-registry-frontend-module.ts @@ -33,14 +33,18 @@ import { VSXExtensionsSourceOptions } from './vsx-extensions-source'; import { VSXExtensionsSearchModel } from './vsx-extensions-search-model'; import { bindExtensionPreferences } from './recommended-extensions/recommended-extensions-preference-contribution'; import { bindPreferenceProviderOverrides } from './recommended-extensions/preference-provider-overrides'; -import { createOVSXClient, OVSXClientProvider } from '../common/ovsx-client-provider'; +import { OVSXClientProvider, createOVSXClient } from '../common/ovsx-client-provider'; import { VSXEnvironment, VSX_ENVIRONMENT_PATH } from '../common/vsx-environment'; +import { OVSXClient } from '@theia/ovsx-client'; export default new ContainerModule((bind, unbind) => { + bind(OVSXClientProvider).toDynamicValue(ctx => { + const clientPromise: Promise = createOVSXClient(ctx.container.get(VSXEnvironment)); + return () => clientPromise; + }).inSingletonScope(); bind(VSXEnvironment).toDynamicValue( ctx => WebSocketConnectionProvider.createProxy(ctx.container, VSX_ENVIRONMENT_PATH) ).inSingletonScope(); - bind(OVSXClientProvider).toProvider(ctx => () => createOVSXClient(ctx.container.get(VSXEnvironment))); bind(VSXExtension).toSelf(); bind(VSXExtensionFactory).toFactory(ctx => (option: VSXExtensionOptions) => { diff --git a/packages/vsx-registry/src/node/vsx-registry-backend-module.ts b/packages/vsx-registry/src/node/vsx-registry-backend-module.ts index e4e47a442ff1b..b3f0e8abc400c 100644 --- a/packages/vsx-registry/src/node/vsx-registry-backend-module.ts +++ b/packages/vsx-registry/src/node/vsx-registry-backend-module.ts @@ -17,17 +17,21 @@ import { ContainerModule } from '@theia/core/shared/inversify'; import { VSXExtensionResolver } from './vsx-extension-resolver'; import { PluginDeployerResolver } from '@theia/plugin-ext/lib/common/plugin-protocol'; -import { createOVSXClient, OVSXClientProvider } from '../common/ovsx-client-provider'; +import { OVSXClientProvider, createOVSXClient } from '../common/ovsx-client-provider'; import { VSXEnvironment, VSX_ENVIRONMENT_PATH } from '../common/vsx-environment'; import { VSXEnvironmentImpl } from './vsx-environment-impl'; import { ConnectionHandler, JsonRpcConnectionHandler } from '@theia/core'; +import { OVSXClient } from '@theia/ovsx-client'; export default new ContainerModule(bind => { + bind(OVSXClientProvider).toDynamicValue(ctx => { + const clientPromise: Promise = createOVSXClient(ctx.container.get(VSXEnvironment)); + return () => clientPromise; + }).inSingletonScope(); bind(VSXEnvironment).to(VSXEnvironmentImpl).inSingletonScope(); bind(ConnectionHandler).toDynamicValue( ctx => new JsonRpcConnectionHandler(VSX_ENVIRONMENT_PATH, () => ctx.container.get(VSXEnvironment)) ).inSingletonScope(); - bind(OVSXClientProvider).toProvider(ctx => () => createOVSXClient(ctx.container.get(VSXEnvironment))); bind(VSXExtensionResolver).toSelf().inSingletonScope(); bind(PluginDeployerResolver).toService(VSXExtensionResolver); }); From 58a05f40151b529547b751dc4519f7ac6751710f Mon Sep 17 00:00:00 2001 From: Paul Marechal Date: Wed, 27 Oct 2021 16:51:09 -0400 Subject: [PATCH 4/6] typing --- .../vsx-registry/src/browser/vsx-registry-frontend-module.ts | 5 ++--- .../vsx-registry/src/node/vsx-registry-backend-module.ts | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/vsx-registry/src/browser/vsx-registry-frontend-module.ts b/packages/vsx-registry/src/browser/vsx-registry-frontend-module.ts index 4260995afeb97..efcdbb93e4b44 100644 --- a/packages/vsx-registry/src/browser/vsx-registry-frontend-module.ts +++ b/packages/vsx-registry/src/browser/vsx-registry-frontend-module.ts @@ -35,11 +35,10 @@ import { bindExtensionPreferences } from './recommended-extensions/recommended-e import { bindPreferenceProviderOverrides } from './recommended-extensions/preference-provider-overrides'; import { OVSXClientProvider, createOVSXClient } from '../common/ovsx-client-provider'; import { VSXEnvironment, VSX_ENVIRONMENT_PATH } from '../common/vsx-environment'; -import { OVSXClient } from '@theia/ovsx-client'; export default new ContainerModule((bind, unbind) => { - bind(OVSXClientProvider).toDynamicValue(ctx => { - const clientPromise: Promise = createOVSXClient(ctx.container.get(VSXEnvironment)); + bind(OVSXClientProvider).toDynamicValue(ctx => { + const clientPromise = createOVSXClient(ctx.container.get(VSXEnvironment)); return () => clientPromise; }).inSingletonScope(); bind(VSXEnvironment).toDynamicValue( diff --git a/packages/vsx-registry/src/node/vsx-registry-backend-module.ts b/packages/vsx-registry/src/node/vsx-registry-backend-module.ts index b3f0e8abc400c..1905767086110 100644 --- a/packages/vsx-registry/src/node/vsx-registry-backend-module.ts +++ b/packages/vsx-registry/src/node/vsx-registry-backend-module.ts @@ -21,11 +21,10 @@ import { OVSXClientProvider, createOVSXClient } from '../common/ovsx-client-prov import { VSXEnvironment, VSX_ENVIRONMENT_PATH } from '../common/vsx-environment'; import { VSXEnvironmentImpl } from './vsx-environment-impl'; import { ConnectionHandler, JsonRpcConnectionHandler } from '@theia/core'; -import { OVSXClient } from '@theia/ovsx-client'; export default new ContainerModule(bind => { - bind(OVSXClientProvider).toDynamicValue(ctx => { - const clientPromise: Promise = createOVSXClient(ctx.container.get(VSXEnvironment)); + bind(OVSXClientProvider).toDynamicValue(ctx => { + const clientPromise = createOVSXClient(ctx.container.get(VSXEnvironment)); return () => clientPromise; }).inSingletonScope(); bind(VSXEnvironment).to(VSXEnvironmentImpl).inSingletonScope(); From 4207cc1b19d49c5b9c73b99599be82cf99b95d27 Mon Sep 17 00:00:00 2001 From: vince-fugnitto Date: Wed, 27 Oct 2021 17:32:33 -0400 Subject: [PATCH 5/6] vsx: fix setting the env varible Signed-off-by: vince-fugnitto --- .../src/node/plugin-vscode-cli-contribution.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/plugin-ext-vscode/src/node/plugin-vscode-cli-contribution.ts b/packages/plugin-ext-vscode/src/node/plugin-vscode-cli-contribution.ts index fb5bcd887f906..f23be990a5970 100644 --- a/packages/plugin-ext-vscode/src/node/plugin-vscode-cli-contribution.ts +++ b/packages/plugin-ext-vscode/src/node/plugin-vscode-cli-contribution.ts @@ -43,7 +43,6 @@ export class PluginVsCodeCliContribution implements CliContribution, PluginHostE conf.option(PluginVsCodeCliContribution.VSCODE_API_VERSION, { // eslint-disable-next-line max-len description: `Overrides the version returned by VSCode API 'vscode.version'. Example: --${PluginVsCodeCliContribution.VSCODE_API_VERSION}=. Default [${VSCODE_DEFAULT_API_VERSION}]`, - default: VSCODE_DEFAULT_API_VERSION, type: 'string', nargs: 1 }); @@ -51,7 +50,7 @@ export class PluginVsCodeCliContribution implements CliContribution, PluginHostE setArguments(args: Arguments): void { const arg = args[PluginVsCodeCliContribution.VSCODE_API_VERSION] as string | undefined; - this.vsCodeApiVersion = arg?.trim() || VSCODE_DEFAULT_API_VERSION; + this.vsCodeApiVersion = arg?.trim() || process.env['VSCODE_API_VERSION']?.trim() || VSCODE_DEFAULT_API_VERSION; process.env['VSCODE_API_VERSION'] = this.vsCodeApiVersion; this.vsCodeApiVersionDeferred.resolve(this.vsCodeApiVersion); } From 214f5ee018a08c56b6470f20bf4d194e22c0841d Mon Sep 17 00:00:00 2001 From: vince-fugnitto Date: Thu, 28 Oct 2021 10:55:35 -0400 Subject: [PATCH 6/6] vsx: update changelog Signed-off-by: vince-fugnitto --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa0f5e683eb37..785f2cc6f65fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ - [core] moved `NewWindowOptions` to `common/window.ts` [#10291](https://github.com/eclipse-theia/theia/pull/10291) - [ovsx-client] removed `fetchJson` method from `OVSXClient` [#10325](https://github.com/eclipse-theia/theia/pull/10325) - [callhierarchy, plugin-ext] Call hierarchy methods `getRootDefinition`, `$provideRootDefinition`, `provideRootDefinition`, and `prepareCallHierarchy` retyped to allow a return of an item or an array of items. [#10310](https://github.com/eclipse-theia/theia/pull/10310) +- [vsx-registry] removed `OVSXAsyncClient` [#10327](https://github.com/eclipse-theia/theia/pull/10327) +- [vsx-registry] updated `VSXEnvironment` from a class to an interface and symbol implemented in both `browser` and `node` [#10327](https://github.com/eclipse-theia/theia/pull/10327) ## v1.18.0 - 9/30/2021