Skip to content

Commit 73f32f7

Browse files
vscode: Support isTransient in TerminalOptions and ExtensionTerminalOptions (eclipse-theia#12055)
Fix eclipse-theia#11777 * 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 Contributed on behalf of STMicroelectronics. Signed-off-by: Lucas Koehler <[email protected]>
1 parent c5e48b5 commit 73f32f7

File tree

6 files changed

+39
-5
lines changed

6 files changed

+39
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

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

7+
## v1.34.0 - 01/26/2023
8+
9+
- [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
10+
- [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
11+
712
## v1.33.0 - 12/20/2022
813

914
- [application-package] added support for declaring extensions as peer dependencies [#11808](https://github.com/eclipse-theia/theia/pull/11808)

packages/plugin-ext/src/main/browser/terminal-main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ export class TerminalServiceMainImpl implements TerminalServiceMain, TerminalLin
137137
attributes: options.attributes,
138138
hideFromUser: options.hideFromUser,
139139
location: this.getTerminalLocation(options, parentId),
140-
isPseudoTerminal
140+
isPseudoTerminal,
141+
isTransient: options.isTransient
141142
});
142143
if (options.message) {
143144
terminal.writeLine(options.message);

packages/plugin/src/theia.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3006,6 +3006,12 @@ export module '@theia/plugin' {
30063006
*/
30073007
location?: TerminalLocation | TerminalEditorLocationOptions | TerminalSplitLocationOptions;
30083008

3009+
/**
3010+
* Opt-out of the default terminal persistence on restart and reload.
3011+
* This will only take effect when `terminal.integrated.enablePersistentSessions` is enabled.
3012+
*/
3013+
isTransient?: boolean;
3014+
30093015
/**
30103016
* Terminal attributes. Can be useful to apply some implementation specific information.
30113017
*/
@@ -3077,6 +3083,12 @@ export module '@theia/plugin' {
30773083
* The {@link TerminalLocation} or {@link TerminalEditorLocationOptions} or {@link TerminalSplitLocationOptions} for the terminal.
30783084
*/
30793085
location?: TerminalLocation | TerminalEditorLocationOptions | TerminalSplitLocationOptions;
3086+
3087+
/**
3088+
* Opt-out of the default terminal persistence on restart and reload.
3089+
* This will only take effect when `terminal.integrated.enablePersistentSessions` is enabled.
3090+
*/
3091+
isTransient?: boolean;
30803092
}
30813093

30823094
/**

packages/terminal/src/browser/base/terminal-widget.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,9 @@ export interface TerminalWidgetOptions {
231231
readonly hideFromUser?: boolean;
232232

233233
readonly location?: TerminalLocationOptions;
234+
235+
/**
236+
* When enabled, the terminal will not be persisted across window reloads.
237+
*/
238+
readonly isTransient?: boolean;
234239
}

packages/terminal/src/browser/terminal-preferences.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ export const TerminalConfigSchema: PreferenceSchema = {
153153
nls.localize('theia/terminal/confirmCloseChildren', 'Confirm if there are any terminals that have child processes.'),
154154
],
155155
default: 'never'
156+
},
157+
'terminal.integrated.enablePersistentSessions': {
158+
type: 'boolean',
159+
description: nls.localizeByDefault('Persist terminal sessions for the workspace across window reloads.'),
160+
default: true
156161
}
157162
}
158163
};
@@ -181,7 +186,8 @@ export interface TerminalConfiguration {
181186
'terminal.integrated.shellArgs.windows': string[],
182187
'terminal.integrated.shellArgs.osx': string[],
183188
'terminal.integrated.shellArgs.linux': string[],
184-
'terminal.integrated.confirmOnExit': ConfirmOnExitType
189+
'terminal.integrated.confirmOnExit': ConfirmOnExitType,
190+
'terminal.integrated.enablePersistentSessions': boolean
185191
}
186192

187193
type FontWeight = 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900';

packages/terminal/src/browser/terminal-widget-impl.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,11 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget
407407
return this.options.hideFromUser ?? false;
408408
}
409409

410+
get transient(): boolean {
411+
// The terminal is transient if session persistence is disabled or it's explicitly marked as transient
412+
return !this.preferences['terminal.integrated.enablePersistentSessions'] || !!this.options.isTransient;
413+
}
414+
410415
onDispose(onDispose: () => void): void {
411416
this.toDispose.push(Disposable.create(onDispose));
412417
}
@@ -421,15 +426,15 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget
421426

422427
storeState(): object {
423428
this.closeOnDispose = false;
424-
if (this.options.isPseudoTerminal) {
429+
if (this.transient || this.options.isPseudoTerminal) {
425430
return {};
426431
}
427432
return { terminalId: this.terminalId, titleLabel: this.title.label };
428433
}
429434

430435
restoreState(oldState: object): void {
431-
// pseudo terminal can not restore
432-
if (this.options.isPseudoTerminal) {
436+
// transient terminals and pseudo terminals are not restored
437+
if (this.transient || this.options.isPseudoTerminal) {
433438
this.dispose();
434439
return;
435440
}

0 commit comments

Comments
 (0)