Skip to content

Commit

Permalink
vscode: Support isTransient in TerminalOptions and ExtensionTerminalO…
Browse files Browse the repository at this point in the history
…ptions

* Extend `TerminalOptions` and `ExtensionTerminalOptions` with `isTransient` property
  according to the VSCode API
* Add terminal preference `enablePersistentSessions` with default value `true`
* Adhere to pref. `enablePersistentSessions` and option `isTransient` in the terminal widget

Fix eclipse-theia#11777

Contributed on behalf of STMicroelectronics.

Signed-off-by: Lucas Koehler <lkoehler@eclipsesource.com>
  • Loading branch information
lucas-koehler committed Jan 10, 2023
1 parent 5bafaa5 commit 7d6af21
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

- [Previous Changelogs](https://github.com/eclipse-theia/theia/tree/master/doc/changelogs/)

## v1.34.0 - 01/26/2023

- [plugin] added support for `isTransient` of `TerminalOptions` and `ExternalTerminalOptions` VS Code API [#12055](https://github.com/eclipse-theia/theia/pull/12055) - Contributed on behalf of STMicroelectronics
- [terminal] added support for preference `terminal.integrated.enablePersistentSessions` to allow disabling restoring terminals on reload [#12055](https://github.com/eclipse-theia/theia/pull/12055) - Contributed on behalf of STMicroelectronics

## v1.33.0 - 12/20/2022

- [application-package] added support for declaring extensions as peer dependencies [#11808](https://github.com/eclipse-theia/theia/pull/11808)
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-ext/src/main/browser/terminal-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ export class TerminalServiceMainImpl implements TerminalServiceMain, TerminalLin
attributes: options.attributes,
hideFromUser: options.hideFromUser,
location: this.getTerminalLocation(options, parentId),
isPseudoTerminal
isPseudoTerminal,
isTransient: options.isTransient
});
if (options.message) {
terminal.writeLine(options.message);
Expand Down
12 changes: 12 additions & 0 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3006,6 +3006,12 @@ export module '@theia/plugin' {
*/
location?: TerminalLocation | TerminalEditorLocationOptions | TerminalSplitLocationOptions;

/**
* Opt-out of the default terminal persistence on restart and reload.
* This will only take effect when `terminal.integrated.enablePersistentSessions` is enabled.
*/
isTransient?: boolean;

/**
* Terminal attributes. Can be useful to apply some implementation specific information.
*/
Expand Down Expand Up @@ -3077,6 +3083,12 @@ export module '@theia/plugin' {
* The {@link TerminalLocation} or {@link TerminalEditorLocationOptions} or {@link TerminalSplitLocationOptions} for the terminal.
*/
location?: TerminalLocation | TerminalEditorLocationOptions | TerminalSplitLocationOptions;

/**
* Opt-out of the default terminal persistence on restart and reload.
* This will only take effect when `terminal.integrated.enablePersistentSessions` is enabled.
*/
isTransient?: boolean;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions packages/terminal/src/browser/base/terminal-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,9 @@ export interface TerminalWidgetOptions {
readonly hideFromUser?: boolean;

readonly location?: TerminalLocationOptions;

/**
* When enabled, the terminal will not be persisted across window reloads.
*/
readonly isTransient?: boolean;
}
8 changes: 7 additions & 1 deletion packages/terminal/src/browser/terminal-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ export const TerminalConfigSchema: PreferenceSchema = {
nls.localize('theia/terminal/confirmCloseChildren', 'Confirm if there are any terminals that have child processes.'),
],
default: 'never'
},
'terminal.integrated.enablePersistentSessions': {
type: 'boolean',
description: nls.localizeByDefault('Persist terminal sessions for the workspace across window reloads.'),
default: true
}
}
};
Expand Down Expand Up @@ -181,7 +186,8 @@ export interface TerminalConfiguration {
'terminal.integrated.shellArgs.windows': string[],
'terminal.integrated.shellArgs.osx': string[],
'terminal.integrated.shellArgs.linux': string[],
'terminal.integrated.confirmOnExit': ConfirmOnExitType
'terminal.integrated.confirmOnExit': ConfirmOnExitType,
'terminal.integrated.enablePersistentSessions': boolean
}

type FontWeight = 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900';
Expand Down
11 changes: 8 additions & 3 deletions packages/terminal/src/browser/terminal-widget-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,11 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget
return this.options.hideFromUser ?? false;
}

get transient(): boolean {
// The terminal is transient if session persistence is disabled or it's explicitly marked as transient
return !this.preferences['terminal.integrated.enablePersistentSessions'] || !!this.options.isTransient;
}

onDispose(onDispose: () => void): void {
this.toDispose.push(Disposable.create(onDispose));
}
Expand All @@ -421,15 +426,15 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget

storeState(): object {
this.closeOnDispose = false;
if (this.options.isPseudoTerminal) {
if (this.transient || this.options.isPseudoTerminal) {
return {};
}
return { terminalId: this.terminalId, titleLabel: this.title.label };
}

restoreState(oldState: object): void {
// pseudo terminal can not restore
if (this.options.isPseudoTerminal) {
// transient terminals and pseudo terminals are not restored
if (this.transient || this.options.isPseudoTerminal) {
this.dispose();
return;
}
Expand Down

0 comments on commit 7d6af21

Please sign in to comment.