From a39be083a6383573237be79c493107e3d2b885ca Mon Sep 17 00:00:00 2001 From: Marc Dumais Date: Thu, 9 Mar 2023 15:59:57 -0500 Subject: [PATCH] [plugin system] Add stubbed support for proposed extensions.allAcrossExtensionHosts and related APIs I believe that we do not support multiple extension hosts yet, so this is effectively adding a stubbed version of these proposed vscode APIs, for the benefit of extensions that use them. At the moment, built-in "vscode.html-language-features" (1.70.2) does, and will not activate correctly without this. Fixes #12276 Signed-off-by: Marc Dumais --- .../plugin-ext/src/plugin/plugin-context.ts | 11 ++++-- packages/plugin/src/theia-proposed.d.ts | 34 +++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/packages/plugin-ext/src/plugin/plugin-context.ts b/packages/plugin-ext/src/plugin/plugin-context.ts index 8ca0a19b64f92..279249afcd244 100644 --- a/packages/plugin-ext/src/plugin/plugin-context.ts +++ b/packages/plugin-ext/src/plugin/plugin-context.ts @@ -753,7 +753,8 @@ export function createAPIFactory( const extensions: typeof theia.extensions = Object.freeze({ // eslint-disable-next-line @typescript-eslint/no-explicit-any - getExtension(extensionId: string): theia.Extension | undefined { + getExtension(extensionId: string, includeFromDifferentExtensionHosts: boolean = false): theia.Extension | undefined { + includeFromDifferentExtensionHosts = false; const plg = pluginManager.getPluginById(extensionId.toLowerCase()); if (plg) { return new PluginExt(pluginManager, plg); @@ -764,6 +765,10 @@ export function createAPIFactory( get all(): readonly theia.Extension[] { return pluginManager.getAllPlugins().map(plg => new PluginExt(pluginManager, plg)); }, + get allAcrossExtensionHosts(): readonly theia.Extension[] { + // we only support one extension host ATM so equivalent to calling "all()" + return this.all; + }, get onDidChange(): theia.Event { return pluginManager.onDidChange; } @@ -1369,13 +1374,15 @@ export class PluginExt extends Plugin implements ExtensionPlugin { extensionPath: string; extensionUri: theia.Uri; extensionKind: ExtensionKind; + isFromDifferentExtensionHost: boolean; - constructor(protected override readonly pluginManager: PluginManager, plugin: InternalPlugin) { + constructor(protected override readonly pluginManager: PluginManager, plugin: InternalPlugin, isFromDifferentExtensionHost = false) { super(pluginManager, plugin); this.extensionPath = this.pluginPath; this.extensionUri = this.pluginUri; this.extensionKind = ExtensionKind.UI; // stub as a local extension (not running on a remote workspace) + this.isFromDifferentExtensionHost = isFromDifferentExtensionHost; } override get isActive(): boolean { diff --git a/packages/plugin/src/theia-proposed.d.ts b/packages/plugin/src/theia-proposed.d.ts index 8607009fb76a9..1b48bf9bb5d6c 100644 --- a/packages/plugin/src/theia-proposed.d.ts +++ b/packages/plugin/src/theia-proposed.d.ts @@ -608,6 +608,40 @@ export module '@theia/plugin' { export function registerTimelineProvider(scheme: string | string[], provider: TimelineProvider): Disposable; } + // Copied from https://github.com/microsoft/vscode/blob/ad4470522ecd858cfaf53a87c2702d7a40946ba1/src/vscode-dts/vscode.proposed.extensionsAny.d.ts + // https://github.com/microsoft/vscode/issues/145307 + + export interface Extension { + + /** + * `true` when the extension is associated to another extension host. + * + * *Note* that an extension from another extension host cannot export + * API, e.g {@link Extension.exports its exports} are always `undefined`. + */ + readonly isFromDifferentExtensionHost: boolean; + } + + export namespace extensions { + + /** + * Get an extension by its full identifier in the form of: `publisher.name`. + * + * @param extensionId An extension identifier. + * @param includeDifferentExtensionHosts Include extensions from different extension host + * @return An extension or `undefined`. + */ + export function getExtension(extensionId: string, includeDifferentExtensionHosts: boolean): Extension | undefined; + + /** + * All extensions across all extension hosts. + * + * @see {@link Extension.isFromDifferentExtensionHost} + */ + export const allAcrossExtensionHosts: readonly Extension[]; + + } + // #endregion }