Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[plugin system] Add stubbed support for proposed extensions.allAcross ExtensionHosts and related APIs #12277

Merged
merged 1 commit into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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