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

Move LocalPty onto the direct proxy #186083

Merged
merged 1 commit into from
Jun 26, 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
34 changes: 17 additions & 17 deletions src/vs/workbench/contrib/terminal/electron-sandbox/localPty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { Emitter } from 'vs/base/common/event';
import { Disposable } from 'vs/base/common/lifecycle';
import { IProcessDataEvent, ITerminalChildProcess, ITerminalLaunchError, IProcessProperty, IProcessPropertyMap, ProcessPropertyType, IProcessReadyEvent, ILocalPtyService } from 'vs/platform/terminal/common/terminal';
import { IProcessDataEvent, ITerminalChildProcess, ITerminalLaunchError, IProcessProperty, IProcessPropertyMap, ProcessPropertyType, IProcessReadyEvent, IPtyService } from 'vs/platform/terminal/common/terminal';
import { URI } from 'vs/base/common/uri';
import { IPtyHostProcessReplayEvent, ISerializedCommandDetectionCapability } from 'vs/platform/terminal/common/capabilities/capabilities';

Expand Down Expand Up @@ -46,48 +46,48 @@ export class LocalPty extends Disposable implements ITerminalChildProcess {
constructor(
readonly id: number,
readonly shouldPersist: boolean,
@ILocalPtyService private readonly _localPtyService: ILocalPtyService
private readonly _proxy: IPtyService
) {
super();
}

start(): Promise<ITerminalLaunchError | { injectedArgs: string[] } | undefined> {
return this._localPtyService.start(this.id);
return this._proxy.start(this.id);
}
detach(forcePersist?: boolean): Promise<void> {
return this._localPtyService.detachFromProcess(this.id, forcePersist);
return this._proxy.detachFromProcess(this.id, forcePersist);
}
shutdown(immediate: boolean): void {
this._localPtyService.shutdown(this.id, immediate);
this._proxy.shutdown(this.id, immediate);
}
async processBinary(data: string): Promise<void> {
if (this._inReplay) {
return;
}
return this._localPtyService.processBinary(this.id, data);
return this._proxy.processBinary(this.id, data);
}
input(data: string): void {
if (this._inReplay) {
return;
}
this._localPtyService.input(this.id, data);
this._proxy.input(this.id, data);
}
resize(cols: number, rows: number): void {
if (this._inReplay || this._lastDimensions.cols === cols && this._lastDimensions.rows === rows) {
return;
}
this._lastDimensions.cols = cols;
this._lastDimensions.rows = rows;
this._localPtyService.resize(this.id, cols, rows);
this._proxy.resize(this.id, cols, rows);
}
async clearBuffer(): Promise<void> {
this._localPtyService.clearBuffer?.(this.id);
this._proxy.clearBuffer?.(this.id);
}
freePortKillProcess(port: string): Promise<{ port: string; processId: string }> {
if (!this._localPtyService.freePortKillProcess) {
if (!this._proxy.freePortKillProcess) {
throw new Error('freePortKillProcess does not exist on the local pty service');
}
return this._localPtyService.freePortKillProcess(port);
return this._proxy.freePortKillProcess(port);
}
async getInitialCwd(): Promise<string> {
return this._properties.initialCwd;
Expand All @@ -96,23 +96,23 @@ export class LocalPty extends Disposable implements ITerminalChildProcess {
return this._properties.cwd || this._properties.initialCwd;
}
async refreshProperty<T extends ProcessPropertyType>(type: T): Promise<IProcessPropertyMap[T]> {
return this._localPtyService.refreshProperty(this.id, type);
return this._proxy.refreshProperty(this.id, type);
}
async updateProperty<T extends ProcessPropertyType>(type: T, value: IProcessPropertyMap[T]): Promise<void> {
return this._localPtyService.updateProperty(this.id, type, value);
return this._proxy.updateProperty(this.id, type, value);
}
getLatency(): Promise<number> {
// TODO: The idea here was to add the result plus the time it took to get the latency
return this._localPtyService.getLatency(this.id);
return this._proxy.getLatency(this.id);
}
acknowledgeDataEvent(charCount: number): void {
if (this._inReplay) {
return;
}
this._localPtyService.acknowledgeDataEvent(this.id, charCount);
this._proxy.acknowledgeDataEvent(this.id, charCount);
}
setUnicodeVersion(version: '6' | '11'): Promise<void> {
return this._localPtyService.setUnicodeVersion(this.id, version);
return this._proxy.setUnicodeVersion(this.id, version);
}

handleData(e: string | IProcessDataEvent) {
Expand Down Expand Up @@ -165,6 +165,6 @@ export class LocalPty extends Disposable implements ITerminalChildProcess {
}

handleOrphanQuestion() {
this._localPtyService.orphanQuestionReply(this.id);
this._proxy.orphanQuestionReply(this.id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBacke
readonly onDidRequestDetach = this._onDidRequestDetach.event;

constructor(
@IInstantiationService private readonly _instantiationService: IInstantiationService,
@IWorkspaceContextService workspaceContextService: IWorkspaceContextService,
@ILifecycleService private readonly _lifecycleService: ILifecycleService,
@ITerminalLogService logService: ITerminalLogService,
Expand Down Expand Up @@ -190,15 +189,15 @@ class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBacke
const executableEnv = await this._shellEnvironmentService.getShellEnv();
// TODO: Using _proxy here bypasses the lastPtyId tracking on the main process
const id = await this._proxy.createProcess(shellLaunchConfig, cwd, cols, rows, unicodeVersion, env, executableEnv, options, shouldPersist, this._getWorkspaceId(), this._getWorkspaceName());
const pty = this._instantiationService.createInstance(LocalPty, id, shouldPersist);
const pty = new LocalPty(id, shouldPersist, this._proxy);
this._ptys.set(id, pty);
return pty;
}

async attachToProcess(id: number): Promise<ITerminalChildProcess | undefined> {
try {
await this._proxy.attachToProcess(id);
const pty = this._instantiationService.createInstance(LocalPty, id, true);
const pty = new LocalPty(id, true, this._proxy);
this._ptys.set(id, pty);
return pty;
} catch (e) {
Expand Down