From 9e5db7756755fe2cc4155f59fda27f32b3d5bbe4 Mon Sep 17 00:00:00 2001 From: Johannes Faltermeier Date: Tue, 21 Jun 2022 12:59:23 +0200 Subject: [PATCH] [vscode] Support Terminal#creationOptions #11138 Signed-off-by: Johannes Faltermeier Co-authored-by: Vincent Fugnitto Contributed on behalf of STMicroelectronics --- packages/plugin-ext/src/plugin/terminal-ext.ts | 18 ++++++++++++++---- packages/plugin/src/theia.d.ts | 6 ++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/plugin-ext/src/plugin/terminal-ext.ts b/packages/plugin-ext/src/plugin/terminal-ext.ts index 4e2873484f141..df0c0a6127cb2 100644 --- a/packages/plugin-ext/src/plugin/terminal-ext.ts +++ b/packages/plugin-ext/src/plugin/terminal-ext.ts @@ -76,17 +76,23 @@ export class TerminalServiceExtImpl implements TerminalServiceExt { }; } this.proxy.$createTerminal(id, options, !!pseudoTerminal); - return this.obtainTerminal(id, options.name || 'Terminal'); + + let creationOptions: theia.TerminalOptions | theia.ExtensionTerminalOptions = options; + // make sure to pass ExtensionTerminalOptions as creation options + if (typeof nameOrOptions === 'object' && 'pty' in nameOrOptions) { + creationOptions = nameOrOptions; + } + return this.obtainTerminal(id, options.name || 'Terminal', creationOptions); } attachPtyToTerminal(terminalId: number, pty: theia.Pseudoterminal): void { this._pseudoTerminals.set(terminalId.toString(), new PseudoTerminal(terminalId, this.proxy, pty, true)); } - protected obtainTerminal(id: string, name: string): TerminalExtImpl { + protected obtainTerminal(id: string, name: string, options?: theia.TerminalOptions | theia.ExtensionTerminalOptions): TerminalExtImpl { let terminal = this._terminals.get(id); if (!terminal) { - terminal = new TerminalExtImpl(this.proxy); + terminal = new TerminalExtImpl(this.proxy, options ?? {}); this._terminals.set(id, terminal); } terminal.name = name; @@ -279,7 +285,11 @@ export class TerminalExtImpl implements Terminal { return this.deferredProcessId.promise; } - constructor(private readonly proxy: TerminalServiceMain) { } + readonly creationOptions: Readonly; + + constructor(private readonly proxy: TerminalServiceMain, private readonly options: theia.TerminalOptions | theia.ExtensionTerminalOptions) { + this.creationOptions = this.options; + } sendText(text: string, addNewLine: boolean = true): void { this.id.promise.then(id => this.proxy.$sendText(id, text, addNewLine)); diff --git a/packages/plugin/src/theia.d.ts b/packages/plugin/src/theia.d.ts index 668586bc65c9b..0ab3560fe71cc 100644 --- a/packages/plugin/src/theia.d.ts +++ b/packages/plugin/src/theia.d.ts @@ -2928,6 +2928,12 @@ export module '@theia/plugin' { */ readonly exitStatus: TerminalExitStatus | undefined; + /** + * The object used to initialize the terminal, this is useful for example to detecting the shell type of when the terminal was not launched by this extension or for + * detecting what folder the shell was launched in. + */ + readonly creationOptions: Readonly + /** * Send text to the terminal. * @param text - text content.