Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IPtyHostService #187177

Merged
merged 3 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 28 additions & 21 deletions src/vs/platform/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,6 @@ export enum TerminalIpcChannels {
Heartbeat = 'heartbeat'
}

export const IPtyService = createDecorator<IPtyService>('ptyService');

export const enum ProcessPropertyType {
Cwd = 'cwd',
InitialCwd = 'initialCwd',
Expand Down Expand Up @@ -266,18 +264,10 @@ export interface IFixedTerminalDimensions {
rows?: number;
}

export interface IPtyHostController {
readonly onPtyHostExit?: Event<number>;
readonly onPtyHostStart?: Event<void>;
readonly onPtyHostUnresponsive?: Event<void>;
readonly onPtyHostResponsive?: Event<void>;
readonly onPtyHostRequestResolveVariables?: Event<IRequestResolveVariablesEvent>;

restartPtyHost?(): void;
acceptPtyHostResolvedVariables?(requestId: number, resolved: string[]): Promise<void>;
}

export interface IPtyService extends IPtyHostController {
/**
* A service that communicates with a pty host.
*/
export interface IPtyService {
readonly _serviceBrand: undefined;

readonly onProcessData: Event<{ id: number; event: IProcessDataEvent | string }>;
Expand All @@ -288,10 +278,6 @@ export interface IPtyService extends IPtyHostController {
readonly onDidChangeProperty: Event<{ id: number; property: IProcessProperty<any> }>;
readonly onProcessExit: Event<{ id: number; event: number | undefined }>;

restartPtyHost?(): Promise<void>;
shutdownAll?(): Promise<void>;
acceptPtyHostResolvedVariables?(requestId: number, resolved: string[]): Promise<void>;

createProcess(
shellLaunchConfig: IShellLaunchConfig,
cwd: string,
Expand All @@ -307,6 +293,7 @@ export interface IPtyService extends IPtyHostController {
): Promise<number>;
attachToProcess(id: number): Promise<void>;
detachFromProcess(id: number, forcePersist?: boolean): Promise<void>;
shutdownAll(): Promise<void>;

/**
* Lists all orphaned processes, ie. those without a connected frontend.
Expand Down Expand Up @@ -334,7 +321,6 @@ export interface IPtyService extends IPtyHostController {
uninstallAllAutoReplies(): Promise<void>;
uninstallAutoReply(match: string): Promise<void>;
getDefaultSystemShell(osOverride?: OperatingSystem): Promise<string>;
getProfiles?(workspaceId: string, profiles: unknown, defaultProfile: unknown, includeDetectedProfiles?: boolean): Promise<ITerminalProfile[]>;
getEnvironment(): Promise<IProcessEnvironment>;
getWslPath(original: string, direction: 'unix-to-win' | 'win-to-unix'): Promise<string>;
getRevivedPtyNewId(workspaceId: string, id: number): Promise<number | undefined>;
Expand All @@ -343,7 +329,7 @@ export interface IPtyService extends IPtyHostController {
reduceConnectionGraceTime(): Promise<void>;
requestDetachInstance(workspaceId: string, instanceId: number): Promise<IProcessDetails | undefined>;
acceptDetachInstanceReply(requestId: number, persistentProcessId?: number): Promise<void>;
freePortKillProcess?(port: string): Promise<{ port: string; processId: string }>;
freePortKillProcess(port: string): Promise<{ port: string; processId: string }>;
/**
* Serializes and returns terminal state.
* @param ids The persistent terminal IDs to serialize.
Expand All @@ -357,8 +343,29 @@ export interface IPtyService extends IPtyHostController {
refreshProperty<T extends ProcessPropertyType>(id: number, property: T): Promise<IProcessPropertyMap[T]>;
updateProperty<T extends ProcessPropertyType>(id: number, property: T, value: IProcessPropertyMap[T]): Promise<void>;

// TODO: Make mandatory and remove impl from pty host service
refreshIgnoreProcessNames?(names: string[]): Promise<void>;
}
export const IPtyService = createDecorator<IPtyService>('ptyService');

export interface IPtyHostController {
readonly onPtyHostExit: Event<number>;
readonly onPtyHostStart: Event<void>;
readonly onPtyHostUnresponsive: Event<void>;
readonly onPtyHostResponsive: Event<void>;
readonly onPtyHostRequestResolveVariables: Event<IRequestResolveVariablesEvent>;

restartPtyHost(): Promise<void>;
acceptPtyHostResolvedVariables(requestId: number, resolved: string[]): Promise<void>;
getProfiles(workspaceId: string, profiles: unknown, defaultProfile: unknown, includeDetectedProfiles?: boolean): Promise<ITerminalProfile[]>;
}

/**
* A service that communicates with a pty host controller (eg. main or server
* process) and is able to launch and forward requests to the pty host.
*/
export interface IPtyHostService extends IPtyService, IPtyHostController {
}

/**
* Serialized terminal state matching the interface that can be used across versions, the version
Expand Down Expand Up @@ -1066,7 +1073,7 @@ export const ILocalPtyService = createDecorator<ILocalPtyService>('localPtyServi
*
* **This service should only be used within the terminal component.**
*/
export interface ILocalPtyService extends IPtyService { }
export interface ILocalPtyService extends IPtyHostService { }

export const ITerminalLogService = createDecorator<ITerminalLogService>('terminalLogService');
export interface ITerminalLogService extends ILogService {
Expand Down
9 changes: 6 additions & 3 deletions src/vs/platform/terminal/node/ptyHostService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { RemoteLoggerChannelClient } from 'vs/platform/log/common/logIpc';
import { getResolvedShellEnv } from 'vs/platform/shell/node/shellEnv';
import { IPtyHostProcessReplayEvent } from 'vs/platform/terminal/common/capabilities/capabilities';
import { RequestStore } from 'vs/platform/terminal/common/requestStore';
import { HeartbeatConstants, IHeartbeatService, IProcessDataEvent, IProcessProperty, IProcessPropertyMap, IProcessReadyEvent, IPtyService, IRequestResolveVariablesEvent, ISerializedTerminalState, IShellLaunchConfig, ITerminalLaunchError, ITerminalProcessOptions, ITerminalProfile, ITerminalsLayoutInfo, ProcessPropertyType, TerminalIcon, TerminalIpcChannels, TerminalSettingId, TitleEventSource } from 'vs/platform/terminal/common/terminal';
import { HeartbeatConstants, IHeartbeatService, IProcessDataEvent, IProcessProperty, IProcessPropertyMap, IProcessReadyEvent, IPtyHostService, IPtyService, IRequestResolveVariablesEvent, ISerializedTerminalState, IShellLaunchConfig, ITerminalLaunchError, ITerminalProcessOptions, ITerminalProfile, ITerminalsLayoutInfo, ProcessPropertyType, TerminalIcon, TerminalIpcChannels, TerminalSettingId, TitleEventSource } from 'vs/platform/terminal/common/terminal';
import { registerTerminalPlatformConfiguration } from 'vs/platform/terminal/common/terminalPlatformConfiguration';
import { IGetTerminalLayoutInfoArgs, IProcessDetails, ISetTerminalLayoutInfoArgs } from 'vs/platform/terminal/common/terminalProcess';
import { IPtyHostConnection, IPtyHostStarter } from 'vs/platform/terminal/node/ptyHost';
Expand All @@ -29,7 +29,7 @@ enum Constants {
* This service implements IPtyService by launching a pty host process, forwarding messages to and
* from the pty host process and manages the connection.
*/
export class PtyHostService extends Disposable implements IPtyService {
export class PtyHostService extends Disposable implements IPtyHostService {
declare readonly _serviceBrand: undefined;

private __connection?: IPtyHostConnection;
Expand Down Expand Up @@ -230,6 +230,9 @@ export class PtyHostService extends Disposable implements IPtyService {
detachFromProcess(id: number, forcePersist?: boolean): Promise<void> {
return this._proxy.detachFromProcess(id, forcePersist);
}
shutdownAll(): Promise<void> {
return this._proxy.shutdownAll();
}
listProcesses(): Promise<IProcessDetails[]> {
return this._proxy.listProcesses();
}
Expand Down Expand Up @@ -354,7 +357,7 @@ export class PtyHostService extends Disposable implements IPtyService {
}

private _disposePtyHost(): void {
this._proxy.shutdownAll?.();
this._proxy.shutdownAll();
this._connection.store.dispose();
}

Expand Down
8 changes: 1 addition & 7 deletions src/vs/platform/terminal/node/ptyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { URI } from 'vs/base/common/uri';
import { getSystemShell } from 'vs/base/node/shell';
import { ILogService, LogLevel } from 'vs/platform/log/common/log';
import { RequestStore } from 'vs/platform/terminal/common/requestStore';
import { IProcessDataEvent, IProcessReadyEvent, IPtyService, IRawTerminalInstanceLayoutInfo, IReconnectConstants, IRequestResolveVariablesEvent, IShellLaunchConfig, ITerminalInstanceLayoutInfoById, ITerminalLaunchError, ITerminalsLayoutInfo, ITerminalTabLayoutInfoById, TerminalIcon, IProcessProperty, TitleEventSource, ProcessPropertyType, IProcessPropertyMap, IFixedTerminalDimensions, IPersistentTerminalProcessLaunchConfig, ICrossVersionSerializedTerminalState, ISerializedTerminalState, ITerminalProcessOptions } from 'vs/platform/terminal/common/terminal';
import { IProcessDataEvent, IProcessReadyEvent, IPtyService, IRawTerminalInstanceLayoutInfo, IReconnectConstants, IShellLaunchConfig, ITerminalInstanceLayoutInfoById, ITerminalLaunchError, ITerminalsLayoutInfo, ITerminalTabLayoutInfoById, TerminalIcon, IProcessProperty, TitleEventSource, ProcessPropertyType, IProcessPropertyMap, IFixedTerminalDimensions, IPersistentTerminalProcessLaunchConfig, ICrossVersionSerializedTerminalState, ISerializedTerminalState, ITerminalProcessOptions } from 'vs/platform/terminal/common/terminal';
import { TerminalDataBufferer } from 'vs/platform/terminal/common/terminalDataBuffering';
import { escapeNonWindowsPath } from 'vs/platform/terminal/common/terminalEnvironment';
import { Terminal as XtermTerminal } from 'xterm-headless';
Expand Down Expand Up @@ -136,12 +136,6 @@ export class PtyService extends Disposable implements IPtyService {
ignoreProcessNames.push(...names);
}

onPtyHostExit?: Event<number> | undefined;
onPtyHostStart?: Event<void> | undefined;
onPtyHostUnresponsive?: Event<void> | undefined;
onPtyHostResponsive?: Event<void> | undefined;
onPtyHostRequestResolveVariables?: Event<IRequestResolveVariablesEvent> | undefined;

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