Skip to content

Commit

Permalink
clean up terminal dnd
Browse files Browse the repository at this point in the history
  • Loading branch information
meganrogge committed Jul 16, 2021
1 parent f70995e commit b34d226
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/vs/platform/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export interface IPtyService {
getTerminalLayoutInfo(args: IGetTerminalLayoutInfoArgs): Promise<ITerminalsLayoutInfo | undefined>;
reduceConnectionGraceTime(): Promise<void>;
requestDetachInstance(workspaceId: string, instanceId: number): Promise<IProcessDetails | undefined>;
acceptDetachedInstance(requestId: number, process: number): Promise<void>;
acceptDetachInstanceReply(requestId: number, persistentProcessId?: number): Promise<void>;
}

export interface IRequestResolveVariablesEvent {
Expand Down
4 changes: 2 additions & 2 deletions src/vs/platform/terminal/node/ptyHostService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ export class PtyHostService extends Disposable implements IPtyService {
return this._proxy.requestDetachInstance(workspaceId, instanceId);
}

async acceptDetachedInstance(requestId: number, persistentProcessId: number): Promise<void> {
return this._proxy.acceptDetachedInstance(requestId, persistentProcessId);
async acceptDetachInstanceReply(requestId: number, persistentProcessId: number): Promise<void> {
return this._proxy.acceptDetachInstanceReply(requestId, persistentProcessId);
}

async restartPtyHost(): Promise<void> {
Expand Down
11 changes: 8 additions & 3 deletions src/vs/platform/terminal/node/ptyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import { Disposable, toDisposable } from 'vs/base/common/lifecycle';
import { IProcessEnvironment, isWindows, OperatingSystem, OS } from 'vs/base/common/platform';
import { IPtyService, IProcessDataEvent, IShellLaunchConfig, ITerminalDimensionsOverride, ITerminalLaunchError, ITerminalsLayoutInfo, IRawTerminalInstanceLayoutInfo, ITerminalTabLayoutInfoById, ITerminalInstanceLayoutInfoById, TerminalShellType, IProcessReadyEvent, TitleEventSource, TerminalIcon, IReconnectConstants } from 'vs/platform/terminal/common/terminal';
import { IPtyService, IProcessDataEvent, IShellLaunchConfig, ITerminalDimensionsOverride, ITerminalLaunchError, ITerminalsLayoutInfo, IRawTerminalInstanceLayoutInfo, ITerminalTabLayoutInfoById, ITerminalInstanceLayoutInfoById, TerminalShellType, IProcessReadyEvent, TitleEventSource, TerminalIcon, IReconnectConstants, IRequestResolveVariablesEvent } from 'vs/platform/terminal/common/terminal';
import { AutoOpenBarrier, Queue, RunOnceScheduler } from 'vs/base/common/async';
import { Emitter } from 'vs/base/common/event';
import { Emitter, Event } from 'vs/base/common/event';
import { TerminalRecorder } from 'vs/platform/terminal/common/terminalRecorder';
import { TerminalProcess } from 'vs/platform/terminal/node/terminalProcess';
import { ISetTerminalLayoutInfoArgs, ITerminalTabLayoutInfoDto, IProcessDetails, IGetTerminalLayoutInfoArgs, IPtyHostProcessReplayEvent } from 'vs/platform/terminal/common/terminalProcess';
Expand Down Expand Up @@ -72,12 +72,17 @@ export class PtyService extends Disposable implements IPtyService {
this._detachInstanceRequestStore = this._register(new RequestStore(undefined, this._logService));
this._detachInstanceRequestStore.onCreateRequest(this._onDidRequestDetach.fire, this._onDidRequestDetach);
}
onPtyHostExit?: Event<number> | undefined;
onPtyHostStart?: Event<void> | undefined;
onPtyHostUnresponsive?: Event<void> | undefined;
onPtyHostResponsive?: Event<void> | undefined;
onPtyHostRequestResolveVariables?: Event<IRequestResolveVariablesEvent> | undefined;

async requestDetachInstance(workspaceId: string, instanceId: number): Promise<IProcessDetails | undefined> {
return this._detachInstanceRequestStore.createRequest({ workspaceId, instanceId });
}

async acceptDetachedInstance(requestId: number, persistentProcessId: number): Promise<void> {
async acceptDetachInstanceReply(requestId: number, persistentProcessId: number): Promise<void> {
let processDetails: IProcessDetails | undefined = undefined;
const pty = this._ptys.get(persistentProcessId);
if (pty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,16 @@ export class RemoteTerminalService extends Disposable implements IRemoteTerminal
return this._remoteTerminalChannel.requestDetachInstance(workspaceId, instanceId);
}

async acceptDetachedInstance(requestId: number, persistentProcessId: number): Promise<void> {
async acceptDetachInstanceReply(requestId: number, persistentProcessId?: number): Promise<void> {
if (!this._remoteTerminalChannel) {
throw new Error(`Cannot accept detached instance when there is no remote!`);
} else if (!persistentProcessId) {
this._logService.warn('Cannot attach to feature terminals, custom pty terminals, or those without a persistentProcessId');
return;
}
return this._remoteTerminalChannel.acceptDetachedInstance(requestId, persistentProcessId);
}

return this._remoteTerminalChannel.acceptDetachInstanceReply(requestId, persistentProcessId);
}

async createProcess(shellLaunchConfig: IShellLaunchConfig, configuration: ICompleteTerminalConfiguration, activeWorkspaceRootUri: URI | undefined, cols: number, rows: number, shouldPersist: boolean, configHelper: ITerminalConfigHelper): Promise<ITerminalChildProcess> {
if (!this._remoteTerminalChannel) {
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/contrib/terminal/browser/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ export interface ITerminalInstance {
readonly instanceId: number;
/**
* A unique URI for this terminal instance with the following encoding:
* path: Title
* fragment: workspace ID / instance ID
* path: /<workspace ID>/<instance ID>
* fragment: Title
*/
readonly resource: URI;

Expand Down
5 changes: 4 additions & 1 deletion src/vs/workbench/contrib/terminal/browser/terminalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,10 @@ export class TerminalService implements ITerminalService {
const persistentProcessId = instanceToDetach?.persistentProcessId;
if (persistentProcessId && !instanceToDetach.shellLaunchConfig.isFeatureTerminal && !instanceToDetach.shellLaunchConfig.customPtyImplementation) {
await instanceToDetach.detachFromProcess();
await this._primaryOffProcessTerminalService?.acceptDetachedInstance(e.requestId, persistentProcessId);
await this._primaryOffProcessTerminalService?.acceptDetachInstanceReply(e.requestId, persistentProcessId);
} else {
// will get rejected without a persistentProcessId to attach to
await this._primaryOffProcessTerminalService?.acceptDetachInstanceReply(e.requestId, undefined);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ export class RemoteTerminalChannelClient {
requestDetachInstance(workspaceId: string, instanceId: number): Promise<IProcessDetails | undefined> {
return this._channel.call('$requestDetachInstance', [workspaceId, instanceId]);
}
acceptDetachedInstance(requestId: number, persistentProcessId: number): Promise<void> {
return this._channel.call('$acceptDetachedInstance', [requestId, persistentProcessId]);
acceptDetachInstanceReply(requestId: number, persistentProcessId: number): Promise<void> {
return this._channel.call('$acceptDetachInstanceReply', [requestId, persistentProcessId]);
}
attachToProcess(id: number): Promise<void> {
return this._channel.call('$attachToProcess', [id]);
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export interface IOffProcessTerminalService {
getTerminalLayoutInfo(): Promise<ITerminalsLayoutInfo | undefined>;
reduceConnectionGraceTime(): Promise<void>;
requestDetachInstance(workspaceId: string, instanceId: number): Promise<IProcessDetails | undefined>;
acceptDetachedInstance(requestId: number, persistentProcessId: number): Promise<void>;
acceptDetachInstanceReply(requestId: number, persistentProcessId?: number): Promise<void>;
}

export const ILocalTerminalService = createDecorator<ILocalTerminalService>('localTerminalService');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,12 @@ export class LocalTerminalService extends Disposable implements ILocalTerminalSe
return this._localPtyService.requestDetachInstance(workspaceId, instanceId);
}

async acceptDetachedInstance(requestId: number, persistentProcessId: number): Promise<void> {
await this._localPtyService.acceptDetachedInstance(requestId, persistentProcessId);
async acceptDetachInstanceReply(requestId: number, persistentProcessId?: number): Promise<void> {
if (!persistentProcessId) {
this._logService.warn('Cannot attach to feature terminals, custom pty terminals, or those without a persistentProcessId');
return;
}
return this._localPtyService.acceptDetachInstanceReply(requestId, persistentProcessId);
}

async updateTitle(id: number, title: string, titleSource: TitleEventSource): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/test/browser/workbenchTestServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,7 @@ export class TestLocalTerminalService implements ILocalTerminalService {
updateTitle(id: number, title: string): Promise<void> { throw new Error('Method not implemented.'); }
updateIcon(id: number, icon: URI | { light: URI; dark: URI } | { id: string, color?: { id: string } }, color?: string): Promise<void> { throw new Error('Method not implemented.'); }
requestDetachInstance(workspaceId: string, instanceId: number): Promise<IProcessDetails | undefined> { throw new Error('Method not implemented.'); }
acceptDetachedInstance(requestId: number, persistentProcessId: number): Promise<void> { throw new Error('Method not implemented.'); }
acceptDetachInstanceReply(requestId: number, persistentProcessId: number): Promise<void> { throw new Error('Method not implemented.'); }
}

class TestTerminalChildProcess implements ITerminalChildProcess {
Expand Down

0 comments on commit b34d226

Please sign in to comment.