Skip to content

Commit 94a1bd6

Browse files
committed
Force persist the process if detach was requested by user
1 parent 50e34c9 commit 94a1bd6

File tree

9 files changed

+21
-20
lines changed

9 files changed

+21
-20
lines changed

src/vs/platform/terminal/common/terminal.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ export interface IPtyService extends IPtyHostController {
297297
workspaceName: string
298298
): Promise<number>;
299299
attachToProcess(id: number): Promise<void>;
300-
detachFromProcess(id: number): Promise<void>;
300+
detachFromProcess(id: number, forcePersist?: boolean): Promise<void>;
301301

302302
/**
303303
* Lists all orphaned processes, ie. those without a connected frontend.
@@ -642,8 +642,9 @@ export interface ITerminalChildProcess {
642642

643643
/**
644644
* Detach the process from the UI and await reconnect.
645+
* @param forcePersist Whether to force the process to persist if it supports persistence.
645646
*/
646-
detach?(): Promise<void>;
647+
detach?(forcePersist?: boolean): Promise<void>;
647648

648649
/**
649650
* Shutdown the terminal process.

src/vs/platform/terminal/node/ptyHostService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ export class PtyHostService extends Disposable implements IPtyService {
229229
attachToProcess(id: number): Promise<void> {
230230
return this._proxy.attachToProcess(id);
231231
}
232-
detachFromProcess(id: number): Promise<void> {
233-
return this._proxy.detachFromProcess(id);
232+
detachFromProcess(id: number, forcePersist?: boolean): Promise<void> {
233+
return this._proxy.detachFromProcess(id, forcePersist);
234234
}
235235
listProcesses(): Promise<IProcessDetails[]> {
236236
return this._proxy.listProcesses();

src/vs/platform/terminal/node/ptyService.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ export class PtyService extends Disposable implements IPtyService {
236236
return this._throwIfNoPty(id).updateProperty(type, value);
237237
}
238238

239-
async detachFromProcess(id: number): Promise<void> {
240-
return this._throwIfNoPty(id).detach();
239+
async detachFromProcess(id: number, forcePersist?: boolean): Promise<void> {
240+
return this._throwIfNoPty(id).detach(forcePersist);
241241
}
242242

243243
async reduceConnectionGraceTime(): Promise<void> {
@@ -595,11 +595,11 @@ export class PersistentTerminalProcess extends Disposable {
595595
this._disconnectRunner2.cancel();
596596
}
597597

598-
async detach(): Promise<void> {
599-
this._logService.trace('persistentTerminalProcess#detach', this._persistentProcessId);
598+
async detach(forcePersist?: boolean): Promise<void> {
599+
this._logService.trace('persistentTerminalProcess#detach', this._persistentProcessId, forcePersist);
600600
// Keep the process around if it was indicated to persist and it has had some iteraction or
601601
// was replayed
602-
if (this.shouldPersistTerminal && this._interactionState !== InteractionState.None) {
602+
if (this.shouldPersistTerminal && (this._interactionState !== InteractionState.None || forcePersist)) {
603603
this._disconnectRunner1.schedule();
604604
} else {
605605
this.shutdown(true);

src/vs/workbench/contrib/terminal/browser/remotePty.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ export class RemotePty extends Disposable implements ITerminalChildProcess {
7676
return undefined;
7777
}
7878

79-
async detach(): Promise<void> {
79+
async detach(forcePersist?: boolean): Promise<void> {
8080
await this._startBarrier.wait();
81-
return this._remoteTerminalChannel.detachFromProcess(this.id);
81+
return this._remoteTerminalChannel.detachFromProcess(this.id, forcePersist);
8282
}
8383

8484
shutdown(immediate: boolean): void {

src/vs/workbench/contrib/terminal/browser/terminalInstance.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,8 +1483,8 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
14831483

14841484
async detachProcessAndDispose(reason: TerminalExitReason): Promise<void> {
14851485
// Detach the process and dispose the instance, without the instance dispose the terminal
1486-
// won't go away
1487-
await this._processManager.detachFromProcess();
1486+
// won't go away. Force persist if the detach was requested by the user (not shutdown).
1487+
await this._processManager.detachFromProcess(reason === TerminalExitReason.User);
14881488
this.dispose(reason);
14891489
}
14901490

src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce
195195
});
196196
}
197197

198-
async detachFromProcess(): Promise<void> {
199-
await this._process?.detach?.();
198+
async detachFromProcess(forcePersist?: boolean): Promise<void> {
199+
await this._process?.detach?.(forcePersist);
200200
this._process = null;
201201
}
202202

src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ export class RemoteTerminalChannelClient implements IPtyHostController {
195195
attachToProcess(id: number): Promise<void> {
196196
return this._channel.call('$attachToProcess', [id]);
197197
}
198-
detachFromProcess(id: number): Promise<void> {
199-
return this._channel.call('$detachFromProcess', [id]);
198+
detachFromProcess(id: number, forcePersist?: boolean): Promise<void> {
199+
return this._channel.call('$detachFromProcess', [id, forcePersist]);
200200
}
201201
listProcesses(): Promise<IProcessDetails[]> {
202202
return this._channel.call('$listProcesses');

src/vs/workbench/contrib/terminal/common/terminal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ export interface ITerminalProcessManager extends IDisposable {
398398
readonly onRestoreCommands: Event<ISerializedCommandDetectionCapability>;
399399

400400
dispose(immediate?: boolean): void;
401-
detachFromProcess(): Promise<void>;
401+
detachFromProcess(forcePersist?: boolean): Promise<void>;
402402
createProcess(shellLaunchConfig: IShellLaunchConfig, cols: number, rows: number, isScreenReaderModeEnabled: boolean): Promise<ITerminalLaunchError | undefined>;
403403
relaunch(shellLaunchConfig: IShellLaunchConfig, cols: number, rows: number, isScreenReaderModeEnabled: boolean, reset: boolean): Promise<ITerminalLaunchError | undefined>;
404404
write(data: string): Promise<void>;

src/vs/workbench/contrib/terminal/electron-sandbox/localPty.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ export class LocalPty extends Disposable implements ITerminalChildProcess {
5252
start(): Promise<ITerminalLaunchError | undefined> {
5353
return this._localPtyService.start(this.id);
5454
}
55-
detach(): Promise<void> {
56-
return this._localPtyService.detachFromProcess(this.id);
55+
detach(forcePersist?: boolean): Promise<void> {
56+
return this._localPtyService.detachFromProcess(this.id, forcePersist);
5757
}
5858
shutdown(immediate: boolean): void {
5959
this._localPtyService.shutdown(this.id, immediate);

0 commit comments

Comments
 (0)