@@ -1586,10 +1586,10 @@ index 0000000000000000000000000000000000000000..c8a613ac2db1ff154a49aa7b6da5f7d2
15861586+ }
15871587diff --git a/src/vs/server/node/channel.ts b/src/vs/server/node/channel.ts
15881588new file mode 100644
1589- index 0000000000000000000000000000000000000000..4827b2da780b66e6dfd65c2a2f1c938cb23f6c26
1589+ index 0000000000000000000000000000000000000000..a6c1f9f848f441b761397ba78e2fef60329b56fa
15901590--- /dev/null
15911591+++ b/src/vs/server/node/channel.ts
1592- @@ -0,0 +1,897 @@
1592+ @@ -0,0 +1,906 @@
15931593+ import { field, logger } from '@coder/logger';
15941594+ import { Server } from '@coder/node-browser';
15951595+ import * as os from 'os';
@@ -2028,6 +2028,9 @@ index 0000000000000000000000000000000000000000..4827b2da780b66e6dfd65c2a2f1c938c
20282028+ private readonly _onDispose = new Emitter<void>();
20292029+ public get onDispose(): Event<void> { return this._onDispose.event; }
20302030+
2031+ + private _isOrphan = true;
2032+ + public get isOrphan(): boolean { return this._isOrphan; }
2033+ +
20312034+ // These are replayed when a client reconnects.
20322035+ private cols: number;
20332036+ private rows: number;
@@ -2047,6 +2050,7 @@ index 0000000000000000000000000000000000000000..4827b2da780b66e6dfd65c2a2f1c938c
20472050+ // Don't bind to data until something is listening.
20482051+ onFirstListenerAdd: () => {
20492052+ logger.debug('Terminal bound', field('id', this.id));
2053+ + this._isOrphan = false;
20502054+ if (!this.buffering) {
20512055+ this.buffering = true;
20522056+ this.bufferer.startBuffering(this.id, this.process.onProcessData);
@@ -2077,6 +2081,7 @@ index 0000000000000000000000000000000000000000..4827b2da780b66e6dfd65c2a2f1c938c
20772081+
20782082+ onLastListenerRemove: () => {
20792083+ logger.debug('Terminal unbound', field('id', this.id));
2084+ + this._isOrphan = true;
20802085+ if (!this.persist) { // Used by debug consoles.
20812086+ this.dispose();
20822087+ } else {
@@ -2469,7 +2474,7 @@ index 0000000000000000000000000000000000000000..4827b2da780b66e6dfd65c2a2f1c938c
24692474+ // behavior when first listing terminals but I don't know what you'd want to
24702475+ // do differently. Maybe it's to reset the terminal dispose timeouts or
24712476+ // something like that, but why not do it each time you list?
2472- + return Promise.all(Array.from(this.terminals).map(async ([id, terminal]) => {
2477+ + const terminals = await Promise.all(Array.from(this.terminals).map(async ([id, terminal]) => {
24732478+ const cwd = await terminal.getCwd();
24742479+ return {
24752480+ id,
@@ -2478,8 +2483,12 @@ index 0000000000000000000000000000000000000000..4827b2da780b66e6dfd65c2a2f1c938c
24782483+ cwd,
24792484+ workspaceId: terminal.workspaceId,
24802485+ workspaceName: terminal.workspaceName,
2486+ + isOrphan: terminal.isOrphan,
24812487+ };
24822488+ }));
2489+ + // Only returned orphaned terminals so we don't end up attaching to
2490+ + // terminals already attached elsewhere.
2491+ + return terminals.filter((t) => t.isOrphan);
24832492+ }
24842493+ }
24852494+
0 commit comments