Skip to content

Commit

Permalink
[plugin system] Add stubbed support for proposed extensions.allAcross…
Browse files Browse the repository at this point in the history
…ExtensionHosts 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-support" (v.70.2) does,
and will not activate correctly without this.

Fixes #12276

Signed-off-by: Marc Dumais <[email protected]>
  • Loading branch information
marcdumais-work committed Mar 9, 2023
1 parent 610eb13 commit e15d8bf
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/plugin-ext/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,8 @@ export function createAPIFactory(

const extensions: typeof theia.extensions = Object.freeze({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getExtension<T = any>(extensionId: string): theia.Extension<T> | undefined {
getExtension<T = any>(extensionId: string, includeFromDifferentExtensionHosts: boolean = false): theia.Extension<T> | undefined {
includeFromDifferentExtensionHosts = false;
const plg = pluginManager.getPluginById(extensionId.toLowerCase());
if (plg) {
return new PluginExt(pluginManager, plg);
Expand All @@ -764,6 +765,10 @@ export function createAPIFactory(
get all(): readonly theia.Extension<any>[] {
return pluginManager.getAllPlugins().map(plg => new PluginExt(pluginManager, plg));
},
get allAcrossExtensionHosts(): readonly theia.Extension<any>[] {
// we only support one extension host ATM so equivalent to calling "all()"
return this.all;
},
get onDidChange(): theia.Event<void> {
return pluginManager.onDidChange;
}
Expand Down Expand Up @@ -1369,13 +1374,15 @@ export class PluginExt<T> extends Plugin<T> implements ExtensionPlugin<T> {
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 {
Expand Down
34 changes: 34 additions & 0 deletions packages/plugin/src/theia-proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {

/**
* `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<T = any>(extensionId: string, includeDifferentExtensionHosts: boolean): Extension<T> | undefined;

/**
* All extensions across all extension hosts.
*
* @see {@link Extension.isFromDifferentExtensionHost}
*/
export const allAcrossExtensionHosts: readonly Extension<void>[];

}

// #endregion
}

Expand Down

0 comments on commit e15d8bf

Please sign in to comment.