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

[vscode] Support env.onDidChangeShell event #13097

Merged
merged 1 commit into from
Nov 28, 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
## v1.44.0

- [task] prevent task widget title from being changed by task process [#13003](https://github.com/eclipse-theia/theia/pull/13003)
- [vscode] Added Notebook CodeActionKind [#13093](https://github.com/eclipse-theia/theia/pull/13093) - contributed on behalf of STMicroelectronics
- [vscode] added Notebook CodeActionKind [#13093](https://github.com/eclipse-theia/theia/pull/13093) - contributed on behalf of STMicroelectronics
- [vscode] added support to env.ondidChangeShell event [#13097](https://github.com/eclipse-theia/theia/pull/13097) - contributed on behalf of STMicroelectronics

## v1.43.0 - 10/26/2023

Expand Down
1 change: 1 addition & 0 deletions packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ export interface TerminalServiceExt {
$provideTerminalLinks(line: string, terminalId: string, token: theia.CancellationToken): Promise<ProvidedTerminalLink[]>;
$handleTerminalLink(link: ProvidedTerminalLink): Promise<void>;
getEnvironmentVariableCollection(extensionIdentifier: string): theia.GlobalEnvironmentVariableCollection;
$setShell(shell: string): void;
}
export interface OutputChannelRegistryExt {
createOutputChannel(name: string, pluginInfo: PluginInfo): theia.OutputChannel,
Expand Down
7 changes: 7 additions & 0 deletions packages/plugin-ext/src/main/browser/terminal-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { interfaces } from '@theia/core/shared/inversify';
import { ApplicationShell, WidgetOpenerOptions } from '@theia/core/lib/browser';
import { TerminalEditorLocationOptions, TerminalOptions } from '@theia/plugin';
import { TerminalLocation, TerminalWidget } from '@theia/terminal/lib/browser/base/terminal-widget';
import { TerminalProfileService } from '@theia/terminal/lib/browser/terminal-profile-service';
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';
Expand All @@ -36,6 +37,7 @@ import { HostedPluginSupport } from '../../hosted/browser/hosted-plugin';
export class TerminalServiceMainImpl implements TerminalServiceMain, TerminalLinkProvider, Disposable {

private readonly terminals: TerminalService;
private readonly terminalProfileService: TerminalProfileService;
private readonly pluginTerminalRegistry: PluginTerminalRegistry;
private readonly hostedPluginSupport: HostedPluginSupport;
private readonly shell: ApplicationShell;
Expand All @@ -47,6 +49,7 @@ export class TerminalServiceMainImpl implements TerminalServiceMain, TerminalLin

constructor(rpc: RPCProtocol, container: interfaces.Container) {
this.terminals = container.get(TerminalService);
this.terminalProfileService = container.get(TerminalProfileService);
this.pluginTerminalRegistry = container.get(PluginTerminalRegistry);
this.hostedPluginSupport = container.get(HostedPluginSupport);
this.shell = container.get(ApplicationShell);
Expand All @@ -64,6 +67,10 @@ export class TerminalServiceMainImpl implements TerminalServiceMain, TerminalLin
this.pluginTerminalRegistry.startCallback = id => this.startProfile(id);

container.bind(TerminalLinkProvider).toDynamicValue(() => this);

this.toDispose.push(this.terminalProfileService.onDidChangeDefaultShell(shell => {
this.extProxy.$setShell(shell);
}));
}

async startProfile(id: string): Promise<string> {
Expand Down
8 changes: 0 additions & 8 deletions packages/plugin-ext/src/plugin/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export abstract class EnvExtImpl {
private queryParameters: QueryParameters;
private lang: string;
private applicationName: string;
private defaultShell: string;
private ui: theia.UIKind;
private envMachineId: string;
private envSessionId: string;
Expand Down Expand Up @@ -68,10 +67,6 @@ export abstract class EnvExtImpl {
this.lang = lang;
}

setShell(shell: string): void {
this.defaultShell = shell;
}

setUIKind(uiKind: theia.UIKind): void {
this.ui = uiKind;
}
Expand Down Expand Up @@ -112,9 +107,6 @@ export abstract class EnvExtImpl {
get uriScheme(): string {
return 'theia';
}
get shell(): string {
return this.defaultShell;
}
get uiKind(): theia.UIKind {
return this.ui;
}
Expand Down
5 changes: 4 additions & 1 deletion packages/plugin-ext/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,10 @@ export function createAPIFactory(
get machineId(): string { return envExt.machineId; },
get sessionId(): string { return envExt.sessionId; },
get uriScheme(): string { return envExt.uriScheme; },
get shell(): string { return envExt.shell; },
get shell(): string { return terminalExt.defaultShell; },
get onDidChangeShell(): theia.Event<string> {
return terminalExt.onDidChangeShell;
},
get uiKind(): theia.UIKind { return envExt.uiKind; },
clipboard,
getEnvVariable(envVarName: string): PromiseLike<string | undefined> {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/plugin/plugin-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export class PluginManagerExtImpl implements PluginManagerExt, PluginManager {

this.envExt.setQueryParameters(params.env.queryParams);
this.envExt.setLanguage(params.env.language);
this.envExt.setShell(params.env.shell);
this.terminalService.$setShell(params.env.shell);
this.envExt.setUIKind(params.env.uiKind);
this.envExt.setApplicationName(params.env.appName);
this.envExt.setAppHost(params.env.appHost);
Expand Down
15 changes: 15 additions & 0 deletions packages/plugin-ext/src/plugin/terminal-ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ export class TerminalServiceExtImpl implements TerminalServiceExt {

protected environmentVariableCollections: MultiKeyMap<string, EnvironmentVariableCollectionImpl> = new MultiKeyMap(2);

private shell: string;
private readonly onDidChangeShellEmitter = new Emitter<string>();
readonly onDidChangeShell: theia.Event<string> = this.onDidChangeShellEmitter.event;

constructor(rpc: RPCProtocol) {
this.proxy = rpc.getProxy(PLUGIN_RPC_CONTEXT.TERMINAL_MAIN);
}
Expand All @@ -79,6 +83,17 @@ export class TerminalServiceExtImpl implements TerminalServiceExt {
return [...this._terminals.values()];
}

get defaultShell(): string {
return this.shell || '';
}

async $setShell(shell: string): Promise<void> {
if (this.shell !== shell) {
this.shell = shell;
this.onDidChangeShellEmitter.fire(shell);
}
}

createTerminal(
nameOrOptions: TerminalOptions | PseudoTerminalOptions | ExtensionTerminalOptions | (string | undefined),
shellPath?: string, shellArgs?: string[] | string
Expand Down
10 changes: 9 additions & 1 deletion packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7720,6 +7720,12 @@ export module '@theia/plugin' {
*/
export const isTelemetryEnabled: boolean;

/**
* An {@link Event} which fires when the default shell changes. This fires with the new
* shell path.
*/
export const onDidChangeShell: Event<string>;

/**
* An {@link Event} which fires when the user enabled or disables telemetry.
* `true` if the user has enabled telemetry or `false` if the user has disabled telemetry.
Expand Down Expand Up @@ -7747,7 +7753,9 @@ export module '@theia/plugin' {
export const remoteName: string | undefined;

/**
* The detected default shell for the extension host.
* The detected default shell for the extension host, this is overridden by the
* `terminal.integrated.defaultProfile` setting for the extension host's platform. Note that in
* environments that do not support a shell the value is the empty string.
*/
export const shell: string;

Expand Down
5 changes: 5 additions & 0 deletions packages/terminal/src/browser/shell-terminal-profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ import { TerminalWidget, TerminalWidgetOptions } from './base/terminal-widget';
import { TerminalProfile } from './terminal-profile-service';

export class ShellTerminalProfile implements TerminalProfile {

get shellPath(): string | undefined {
return this.options.shellPath;
}

constructor(protected readonly terminalService: TerminalService, protected readonly options: TerminalWidgetOptions) { }

async start(): Promise<TerminalWidget> {
Expand Down
10 changes: 10 additions & 0 deletions packages/terminal/src/browser/terminal-profile-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { Emitter, Event } from '@theia/core';
import { injectable } from '@theia/core/shared/inversify';
import { TerminalWidget } from './base/terminal-widget';
import { ShellTerminalProfile } from './shell-terminal-profile';

export const TerminalProfileService = Symbol('TerminalProfileService');
export const ContributedTerminalProfileStore = Symbol('ContributedTerminalProfileStore');
Expand All @@ -36,6 +37,7 @@ export interface TerminalProfileService {
getProfile(id: string): TerminalProfile | undefined
readonly all: [string, TerminalProfile][];
setDefaultProfile(id: string): void;
readonly onDidChangeDefaultShell: Event<string>;
readonly defaultProfile: TerminalProfile | undefined;
}

Expand Down Expand Up @@ -87,9 +89,11 @@ export class DefaultTerminalProfileService implements TerminalProfileService {

protected readonly onAddedEmitter: Emitter<string> = new Emitter();
protected readonly onRemovedEmitter: Emitter<string> = new Emitter();
protected readonly onDidChangeDefaultShellEmitter: Emitter<string> = new Emitter();

onAdded: Event<string> = this.onAddedEmitter.event;
onRemoved: Event<string> = this.onRemovedEmitter.event;
onDidChangeDefaultShell: Event<string> = this.onDidChangeDefaultShellEmitter.event;

constructor(...stores: TerminalProfileStore[]) {
this.stores = stores;
Expand Down Expand Up @@ -144,6 +148,12 @@ export class DefaultTerminalProfileService implements TerminalProfileService {
throw new Error(`Cannot set default to unknown profile '${id}' `);
}
this.defaultProfileIndex = this.order.indexOf(id);

if (profile instanceof ShellTerminalProfile && profile.shellPath) {
this.onDidChangeDefaultShellEmitter.fire(profile.shellPath);
} else {
this.onDidChangeDefaultShellEmitter.fire('');
}
}

getProfile(id: string): TerminalProfile | undefined {
Expand Down
Loading