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

Implement VS Code extensions namespace #11887

Merged
merged 1 commit into from
Nov 21, 2022
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
19 changes: 19 additions & 0 deletions packages/plugin-ext/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,24 @@ export function createAPIFactory(
get onDidChangeLogLevel(): theia.Event<theia.LogLevel> { return onDidChangeLogLevel.event; }
});

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 {
const plg = pluginManager.getPluginById(extensionId.toLowerCase());
if (plg) {
return new PluginExt(pluginManager, plg);
}
return undefined;
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
get all(): readonly theia.Extension<any>[] {
return pluginManager.getAllPlugins().map(plg => new PluginExt(pluginManager, plg));
},
get onDidChange(): theia.Event<void> {
return pluginManager.onDidChange;
}
});

const languages: typeof theia.languages = {
getLanguages(): PromiseLike<string[]> {
return languagesExt.getLanguages();
Expand Down Expand Up @@ -971,6 +989,7 @@ export function createAPIFactory(
window,
workspace,
env,
extensions,
languages,
plugins,
debug,
Expand Down
21 changes: 21 additions & 0 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9523,6 +9523,27 @@ export module '@theia/plugin' {
provideDocumentRangeSemanticTokens(document: TextDocument, range: Range, token: CancellationToken): ProviderResult<SemanticTokens>;
}

export namespace extensions {
/**
* Get an extension by its full identifier in the form of: `publisher.name`.
*
* @param extensionId An extension identifier.
* @return An extension or `undefined`.
*/
export function getExtension<T = any>(extensionId: string): Extension<T> | undefined;

/**
* All extensions currently known to the system.
*/
export const all: readonly Extension<any>[];

/**
* An event which fires when `extensions.all` changes. This can happen when extensions are
* installed, uninstalled, enabled or disabled.
*/
export const onDidChange: Event<void>;
}

export namespace languages {
/**
* Return the identifiers of all known languages.
Expand Down