Skip to content

Commit

Permalink
Support PluginExt#extensionKind properly (#13763)
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew authored Jun 24, 2024
1 parent 447e38e commit 1f08797
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
7 changes: 6 additions & 1 deletion packages/core/src/browser/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ export const isSafari = (userAgent.indexOf('Chrome') === -1) && (userAgent.index
export const isIPad = (userAgent.indexOf('iPad') >= 0);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
/**
* @deprecated us Environment.electron.is
* @deprecated use Environment.electron.is
*/
export const isNative = environment.electron.is();
/**
* Determines whether the backend is running in a remote environment.
* I.e. we use the browser version or connect to a remote Theia instance in Electron.
*/
export const isRemote = !environment.electron.is() || new URL(location.href).searchParams.has('localPort');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const isBasicWasmSupported = typeof (window as any).WebAssembly !== 'undefined';

Expand Down
14 changes: 14 additions & 0 deletions packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ export enum UIKind {
Web = 2
}

export enum ExtensionKind {
/**
* Extension runs where the UI runs.
*/
UI = 1,

/**
* Extension runs where the remote extension host runs.
*/
Workspace = 2
}

export interface EnvInit {
queryParams: QueryParameters;
language: string;
Expand All @@ -178,6 +190,7 @@ export interface PluginManager {
getAllPlugins(): Plugin[];
getPluginById(pluginId: string): Plugin | undefined;
getPluginExport(pluginId: string): PluginAPI | undefined;
getPluginKind(): theia.ExtensionKind;
isRunning(pluginId: string): boolean;
isActive(pluginId: string): boolean;
activatePlugin(pluginId: string): PromiseLike<void>;
Expand Down Expand Up @@ -233,6 +246,7 @@ export interface PluginManagerInitializeParams {
globalState: KeysToKeysToAnyValue
workspaceState: KeysToKeysToAnyValue
env: EnvInit
pluginKind: ExtensionKind
extApi?: ExtPluginApi[]
webview: WebviewInitData
jsonValidation: PluginJsonValidationContribution[]
Expand Down
4 changes: 3 additions & 1 deletion packages/plugin-ext/src/hosted/browser/hosted-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { injectable, inject, postConstruct } from '@theia/core/shared/inversify'
import { PluginWorker } from './plugin-worker';
import { getPluginId, DeployedPlugin, HostedPluginServer } from '../../common/plugin-protocol';
import { HostedPluginWatcher } from './hosted-plugin-watcher';
import { MAIN_RPC_CONTEXT, PluginManagerExt, UIKind } from '../../common/plugin-api-rpc';
import { ExtensionKind, MAIN_RPC_CONTEXT, PluginManagerExt, UIKind } from '../../common/plugin-api-rpc';
import { setUpPluginApi } from '../../main/browser/main-context';
import { RPCProtocol, RPCProtocolImpl } from '../../common/rpc-protocol';
import {
Expand Down Expand Up @@ -71,6 +71,7 @@ import {
AbstractHostedPluginSupport, PluginContributions, PluginHost,
ALL_ACTIVATION_EVENT, isConnectionScopedBackendPlugin
} from '../common/hosted-plugin';
import { isRemote } from '@theia/core/lib/browser/browser';

export type DebugActivationEvent = 'onDebugResolve' | 'onDebugInitialConfigurations' | 'onDebugAdapterProtocolTracker' | 'onDebugDynamicConfigurations';

Expand Down Expand Up @@ -334,6 +335,7 @@ export class HostedPluginSupport extends AbstractHostedPluginSupport<PluginManag
webviewCspSource
},
jsonValidation,
pluginKind: isRemote ? ExtensionKind.Workspace : ExtensionKind.UI,
supportedActivationEvents
});
if (toDisconnect.disposed) {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1508,7 +1508,7 @@ export class PluginExt<T> extends Plugin<T> implements ExtensionPlugin<T> {

this.extensionPath = this.pluginPath;
this.extensionUri = this.pluginUri;
this.extensionKind = ExtensionKind.UI; // stub as a local extension (not running on a remote workspace)
this.extensionKind = pluginManager.getPluginKind();
this.isFromDifferentExtensionHost = isFromDifferentExtensionHost;
}

Expand Down
9 changes: 8 additions & 1 deletion packages/plugin-ext/src/plugin/plugin-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import {
PluginManagerInitializeParams,
PluginManagerStartParams,
TerminalServiceExt,
LocalizationExt
LocalizationExt,
ExtensionKind
} from '../common/plugin-api-rpc';
import { PluginMetadata, PluginJsonValidationContribution } from '../common/plugin-protocol';
import * as theia from '@theia/plugin';
Expand Down Expand Up @@ -121,6 +122,7 @@ export abstract class AbstractPluginManagerExtImpl<P extends Record<string, any>
private notificationMain: NotificationMain;

protected jsonValidation: PluginJsonValidationContribution[] = [];
protected pluginKind = ExtensionKind.UI;
protected ready = new Deferred();

@postConstruct()
Expand Down Expand Up @@ -410,6 +412,10 @@ export abstract class AbstractPluginManagerExtImpl<P extends Record<string, any>
}
}

getPluginKind(): theia.ExtensionKind {
return this.pluginKind;
}

getAllPlugins(): Plugin[] {
return Array.from(this.registry.values());
}
Expand Down Expand Up @@ -477,6 +483,7 @@ export class PluginManagerExtImpl extends AbstractPluginManagerExtImpl<PluginMan

this.webview.init(params.webview);
this.jsonValidation = params.jsonValidation;
this.pluginKind = params.pluginKind;

this.supportedActivationEvents = new Set(params.supportedActivationEvents ?? []);
}
Expand Down

0 comments on commit 1f08797

Please sign in to comment.