From b80c556793c850a94b0058d666769600a6533bdf Mon Sep 17 00:00:00 2001 From: Johannes Faltermeier Date: Wed, 23 Aug 2023 17:25:24 +0200 Subject: [PATCH] [vscode] Support EnvironmentVariableCollection description #12696 * add description to SerializableExtensionEnvironmentVariableCollection and use as DTO in $setEnvironmentVariableCollection * add fromMarkdownOrString method to converter * review comments Contributed on behalf of STMicroelectronics Signed-off-by: Johannes Faltermeier --- .../plugin-ext/src/common/plugin-api-rpc.ts | 5 ++--- .../src/main/browser/terminal-main.ts | 13 ++++++------- packages/plugin-ext/src/plugin/terminal-ext.ts | 18 +++++------------- .../plugin-ext/src/plugin/type-converters.ts | 10 ++++++++++ .../src/browser/base/terminal-widget.ts | 4 ++-- .../browser/terminal-frontend-contribution.ts | 2 +- .../src/browser/terminal-info-toolbar-item.tsx | 6 +++--- .../src/browser/terminal-widget-impl.ts | 4 ++-- .../src/common/base-terminal-protocol.ts | 5 +++-- .../terminal/src/node/base-terminal-server.ts | 5 +++-- 10 files changed, 37 insertions(+), 35 deletions(-) diff --git a/packages/plugin-ext/src/common/plugin-api-rpc.ts b/packages/plugin-ext/src/common/plugin-api-rpc.ts index 55a6e003e207f..e2cae1588cb5f 100644 --- a/packages/plugin-ext/src/common/plugin-api-rpc.ts +++ b/packages/plugin-ext/src/common/plugin-api-rpc.ts @@ -111,7 +111,7 @@ import type { TimelineChangeEvent, TimelineProviderDescriptor } from '@theia/timeline/lib/common/timeline-model'; -import { SerializableEnvironmentVariableCollection } from '@theia/terminal/lib/common/base-terminal-protocol'; +import { SerializableEnvironmentVariableCollection, SerializableExtensionEnvironmentVariableCollection } from '@theia/terminal/lib/common/base-terminal-protocol'; import { ThemeType } from '@theia/core/lib/common/theme'; import { Disposable } from '@theia/core/lib/common/disposable'; import { isString, isObject, PickOptions, QuickInputButtonHandle } from '@theia/core/lib/common'; @@ -404,8 +404,7 @@ export interface TerminalServiceMain { */ $disposeByTerminalId(id: number, waitOnExit?: boolean | string): void; - $setEnvironmentVariableCollection(extensionIdentifier: string, persistent: boolean, collection: SerializableEnvironmentVariableCollection | undefined, - description: string | MarkdownString | undefined): void; + $setEnvironmentVariableCollection(persistent: boolean, collection: SerializableExtensionEnvironmentVariableCollection): void; /** * Set the terminal widget name. diff --git a/packages/plugin-ext/src/main/browser/terminal-main.ts b/packages/plugin-ext/src/main/browser/terminal-main.ts index 02a3827087863..b68d5a800881f 100644 --- a/packages/plugin-ext/src/main/browser/terminal-main.ts +++ b/packages/plugin-ext/src/main/browser/terminal-main.ts @@ -16,13 +16,13 @@ import { interfaces } from '@theia/core/shared/inversify'; import { ApplicationShell, WidgetOpenerOptions } from '@theia/core/lib/browser'; -import { MarkdownString, TerminalEditorLocationOptions, TerminalOptions } from '@theia/plugin'; +import { TerminalEditorLocationOptions, TerminalOptions } from '@theia/plugin'; import { TerminalLocation, TerminalWidget } from '@theia/terminal/lib/browser/base/terminal-widget'; import { TerminalService } from '@theia/terminal/lib/browser/base/terminal-service'; import { TerminalServiceMain, TerminalServiceExt, MAIN_RPC_CONTEXT } from '../../common/plugin-api-rpc'; import { RPCProtocol } from '../../common/rpc-protocol'; import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable'; -import { SerializableEnvironmentVariableCollection } from '@theia/terminal/lib/common/base-terminal-protocol'; +import { SerializableEnvironmentVariableCollection, SerializableExtensionEnvironmentVariableCollection } from '@theia/terminal/lib/common/base-terminal-protocol'; import { ShellTerminalServerProxy } from '@theia/terminal/lib/common/shell-terminal-protocol'; import { TerminalLink, TerminalLinkProvider } from '@theia/terminal/lib/browser/terminal-link-provider'; import { URI } from '@theia/core/lib/common/uri'; @@ -75,12 +75,11 @@ export class TerminalServiceMainImpl implements TerminalServiceMain, TerminalLin return this.extProxy.$startProfile(id, CancellationToken.None); } - $setEnvironmentVariableCollection(extensionIdentifier: string, persistent: boolean, collection: SerializableEnvironmentVariableCollection | undefined, - description: string | MarkdownString | undefined): void { - if (collection) { - this.shellTerminalServer.setCollection(extensionIdentifier, persistent, collection, description); + $setEnvironmentVariableCollection(persistent: boolean, collection: SerializableExtensionEnvironmentVariableCollection): void { + if (collection.collection) { + this.shellTerminalServer.setCollection(collection.extensionIdentifier, persistent, collection.collection, collection.description); } else { - this.shellTerminalServer.deleteCollection(extensionIdentifier); + this.shellTerminalServer.deleteCollection(collection.extensionIdentifier); } } diff --git a/packages/plugin-ext/src/plugin/terminal-ext.ts b/packages/plugin-ext/src/plugin/terminal-ext.ts index dce1898377100..0cdfaeb886d4b 100644 --- a/packages/plugin-ext/src/plugin/terminal-ext.ts +++ b/packages/plugin-ext/src/plugin/terminal-ext.ts @@ -25,7 +25,6 @@ import { Disposable, EnvironmentVariableMutatorType, TerminalExitReason, ThemeIc import { SerializableEnvironmentVariableCollection } from '@theia/terminal/lib/common/base-terminal-protocol'; import { ProvidedTerminalLink } from '../common/plugin-api-rpc-model'; import { ThemeIcon as MonacoThemeIcon } from '@theia/monaco-editor-core/esm/vs/platform/theme/common/themeService'; -import { MarkdownString as MarkdownStringDTO } from '@theia/core/lib/common/markdown-rendering'; export function getIconUris(iconPath: theia.TerminalOptions['iconPath']): { id: string } | undefined { if (ThemeIcon.is(iconPath)) { @@ -315,18 +314,11 @@ export class TerminalServiceExtImpl implements TerminalServiceExt { private syncEnvironmentVariableCollection(extensionIdentifier: string, collection: EnvironmentVariableCollection): void { const serialized = [...collection.map.entries()]; - this.proxy.$setEnvironmentVariableCollection(extensionIdentifier, collection.persistent, serialized.length === 0 ? undefined : serialized, - this.descriptionToDTO(collection.description)); - } - - private descriptionToDTO(value: string | theia.MarkdownString | undefined): string | MarkdownStringDTO | undefined { - if (value === undefined) { - return undefined; - } else if (typeof value === 'string') { - return value; - } else { - return Converter.fromMarkdown(value); - } + this.proxy.$setEnvironmentVariableCollection(collection.persistent, { + extensionIdentifier, + collection: serialized.length === 0 ? undefined : serialized, + description: Converter.fromMarkdownOrString(collection.description) + }); } private setEnvironmentVariableCollection(extensionIdentifier: string, collection: EnvironmentVariableCollection): void { diff --git a/packages/plugin-ext/src/plugin/type-converters.ts b/packages/plugin-ext/src/plugin/type-converters.ts index f3c123fb0cec7..797758b79c3cd 100644 --- a/packages/plugin-ext/src/plugin/type-converters.ts +++ b/packages/plugin-ext/src/plugin/type-converters.ts @@ -201,6 +201,16 @@ export function fromMarkdown(markup: theia.MarkdownString | theia.MarkedString): } } +export function fromMarkdownOrString(value: string | theia.MarkdownString | undefined): string | MarkdownStringDTO | undefined { + if (value === undefined) { + return undefined; + } else if (typeof value === 'string') { + return value; + } else { + return fromMarkdown(value); + } +} + export function toMarkdown(value: MarkdownStringDTO): PluginMarkdownStringImpl { const implemented = new PluginMarkdownStringImpl(value.value, value.supportThemeIcons); implemented.isTrusted = value.isTrusted; diff --git a/packages/terminal/src/browser/base/terminal-widget.ts b/packages/terminal/src/browser/base/terminal-widget.ts index 443638ead7c22..b47b322299030 100644 --- a/packages/terminal/src/browser/base/terminal-widget.ts +++ b/packages/terminal/src/browser/base/terminal-widget.ts @@ -59,8 +59,8 @@ export abstract class TerminalWidget extends BaseWidget { */ abstract processInfo: Promise; - /** The extensions contributing to the environment of this terminal */ - abstract contributingExtensions: Promise>; + /** The ids of extensions contributing to the environment of this terminal mapped to the provided description for their changes. */ + abstract envVarCollectionDescriptionsByExtension: Promise>; /** Terminal kind that indicates whether a terminal is created by a user or by some extension for a user */ abstract readonly kind: 'user' | string; diff --git a/packages/terminal/src/browser/terminal-frontend-contribution.ts b/packages/terminal/src/browser/terminal-frontend-contribution.ts index 6850c491f5eb3..dc55bf3875749 100644 --- a/packages/terminal/src/browser/terminal-frontend-contribution.ts +++ b/packages/terminal/src/browser/terminal-frontend-contribution.ts @@ -263,7 +263,7 @@ export class TerminalFrontendContribution implements FrontendApplicationContribu this.storageService.getData(ENVIRONMENT_VARIABLE_COLLECTIONS_KEY).then(data => { if (data) { const collectionsJson: SerializableExtensionEnvironmentVariableCollection[] = JSON.parse(data); - collectionsJson.forEach(c => this.shellTerminalServer.setCollection(c.extensionIdentifier, true, c.collection, undefined)); + collectionsJson.forEach(c => this.shellTerminalServer.setCollection(c.extensionIdentifier, true, c.collection ? c.collection : [], c.description)); } }); }); diff --git a/packages/terminal/src/browser/terminal-info-toolbar-item.tsx b/packages/terminal/src/browser/terminal-info-toolbar-item.tsx index 862b4c8b74ecb..5d115c9d98e04 100644 --- a/packages/terminal/src/browser/terminal-info-toolbar-item.tsx +++ b/packages/terminal/src/browser/terminal-info-toolbar-item.tsx @@ -51,7 +51,7 @@ export class TerminalInfoToolbarItem implements ReactTabBarToolbarItem { ): Promise { const currentTarget = event.currentTarget; if (currentTerminal instanceof TerminalWidget) { - const extensions = await currentTerminal.contributingExtensions; + const extensions = await currentTerminal.envVarCollectionDescriptionsByExtension; const processId = await currentTerminal.processId; const processInfo = await currentTerminal.processInfo; @@ -107,7 +107,7 @@ export class TerminalInfoToolbarItem implements ReactTabBarToolbarItem { } } - protected async onMouseLeave(toDispose: DisposableCollection): Promise { - toDispose.dispose(); + protected async onMouseLeave(hoverResources: DisposableCollection): Promise { + hoverResources.dispose(); } } diff --git a/packages/terminal/src/browser/terminal-widget-impl.ts b/packages/terminal/src/browser/terminal-widget-impl.ts index 72a47d30aa3dc..16c644c51f00f 100644 --- a/packages/terminal/src/browser/terminal-widget-impl.ts +++ b/packages/terminal/src/browser/terminal-widget-impl.ts @@ -423,11 +423,11 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget return this.shellTerminalServer.getProcessInfo(this.terminalId); } - get contributingExtensions(): Promise> { + get envVarCollectionDescriptionsByExtension(): Promise> { if (!IBaseTerminalServer.validateId(this.terminalId)) { return Promise.reject(new Error('terminal is not started')); } - return this.shellTerminalServer.getContributingExtensions(this.terminalId); + return this.shellTerminalServer.getEnvVarCollectionDescriptionsByExtension(this.terminalId); } get terminalId(): number { diff --git a/packages/terminal/src/common/base-terminal-protocol.ts b/packages/terminal/src/common/base-terminal-protocol.ts index 1b19753ac47c6..0ed81c912db98 100644 --- a/packages/terminal/src/common/base-terminal-protocol.ts +++ b/packages/terminal/src/common/base-terminal-protocol.ts @@ -29,7 +29,7 @@ export interface IBaseTerminalServer extends RpcServer { create(IBaseTerminalServerOptions: object): Promise; getProcessId(id: number): Promise; getProcessInfo(id: number): Promise; - getContributingExtensions(id: number): Promise>; + getEnvVarCollectionDescriptionsByExtension(id: number): Promise>; getCwdURI(id: number): Promise; resize(id: number, cols: number, rows: number): Promise; attach(id: number): Promise; @@ -189,7 +189,8 @@ export interface MergedEnvironmentVariableCollection { export interface SerializableExtensionEnvironmentVariableCollection { extensionIdentifier: string, - collection: SerializableEnvironmentVariableCollection + collection: SerializableEnvironmentVariableCollection | undefined, + description: string | MarkdownString | undefined } export type SerializableEnvironmentVariableCollection = [string, EnvironmentVariableMutator][]; diff --git a/packages/terminal/src/node/base-terminal-server.ts b/packages/terminal/src/node/base-terminal-server.ts index e5fbdc1423a2b..71cab2500ec0a 100644 --- a/packages/terminal/src/node/base-terminal-server.ts +++ b/packages/terminal/src/node/base-terminal-server.ts @@ -101,7 +101,7 @@ export abstract class BaseTerminalServer implements IBaseTerminalServer { }; } - async getContributingExtensions(id: number): Promise> { + async getEnvVarCollectionDescriptionsByExtension(id: number): Promise> { const terminal = this.processManager.get(id); if (!(terminal instanceof TerminalProcess)) { throw new Error(`terminal "${id}" does not exist`); @@ -211,7 +211,8 @@ export abstract class BaseTerminalServer implements IBaseTerminalServer { if (collection.persistent) { collectionsJson.push({ extensionIdentifier, - collection: [...this.collections.get(extensionIdentifier)!.map.entries()] + collection: [...this.collections.get(extensionIdentifier)!.map.entries()], + description: collection.description }); } });