Skip to content

Commit 074121e

Browse files
committed
Remove now unneeded optional checks
1 parent ed59e75 commit 074121e

File tree

2 files changed

+58
-68
lines changed

2 files changed

+58
-68
lines changed

src/vs/server/node/remoteTerminalChannel.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export class RemoteTerminalChannel extends Disposable implements IServerChannel<
107107

108108
async call(ctx: RemoteAgentConnectionContext, command: string, args?: any): Promise<any> {
109109
switch (command) {
110-
case '$restartPtyHost': return this._ptyHostService.restartPtyHost?.apply(this._ptyHostService, args);
110+
case '$restartPtyHost': return this._ptyHostService.restartPtyHost.apply(this._ptyHostService, args);
111111

112112
case '$createProcess': {
113113
const uriTransformer = createURITransformer(ctx.remoteAuthority);
@@ -119,7 +119,7 @@ export class RemoteTerminalChannel extends Disposable implements IServerChannel<
119119
case '$listProcesses': return this._ptyHostService.listProcesses.apply(this._ptyHostService, args);
120120
case '$getPerformanceMarks': return this._ptyHostService.getPerformanceMarks.apply(this._ptyHostService, args);
121121
case '$orphanQuestionReply': return this._ptyHostService.orphanQuestionReply.apply(this._ptyHostService, args);
122-
case '$acceptPtyHostResolvedVariables': return this._ptyHostService.acceptPtyHostResolvedVariables?.apply(this._ptyHostService, args);
122+
case '$acceptPtyHostResolvedVariables': return this._ptyHostService.acceptPtyHostResolvedVariables.apply(this._ptyHostService, args);
123123

124124
case '$start': return this._ptyHostService.start.apply(this._ptyHostService, args);
125125
case '$input': return this._ptyHostService.input.apply(this._ptyHostService, args);
@@ -152,7 +152,7 @@ export class RemoteTerminalChannel extends Disposable implements IServerChannel<
152152
case '$refreshProperty': return this._ptyHostService.refreshProperty.apply(this._ptyHostService, args);
153153
case '$requestDetachInstance': return this._ptyHostService.requestDetachInstance(args[0], args[1]);
154154
case '$acceptDetachedInstance': return this._ptyHostService.acceptDetachInstanceReply(args[0], args[1]);
155-
case '$freePortKillProcess': return this._ptyHostService.freePortKillProcess?.apply(this._ptyHostService, args);
155+
case '$freePortKillProcess': return this._ptyHostService.freePortKillProcess.apply(this._ptyHostService, args);
156156
}
157157

158158
throw new Error(`IPC Command ${command} not found`);
@@ -320,7 +320,7 @@ export class RemoteTerminalChannel extends Disposable implements IServerChannel<
320320
}
321321

322322
private async _getProfiles(workspaceId: string, profiles: unknown, defaultProfile: unknown, includeDetectedProfiles?: boolean): Promise<ITerminalProfile[]> {
323-
return this._ptyHostService.getProfiles?.(workspaceId, profiles, defaultProfile, includeDetectedProfiles) || [];
323+
return this._ptyHostService.getProfiles(workspaceId, profiles, defaultProfile, includeDetectedProfiles) || [];
324324
}
325325

326326
private _getEnvironment(): platform.IProcessEnvironment {

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

Lines changed: 54 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -46,73 +46,63 @@ export abstract class BaseTerminalBackend extends Disposable {
4646
let hasStarted = false;
4747

4848
// Attach pty host listeners
49-
if (this._ptyHostController.onPtyHostExit) {
50-
this._register(this._ptyHostController.onPtyHostExit(() => {
51-
this._logService.error(`The terminal's pty host process exited, the connection to all terminal processes was lost`);
52-
}));
53-
}
54-
if (this._ptyHostController.onPtyHostStart) {
55-
this.onPtyHostConnected(() => hasStarted = true);
56-
this._register(this._ptyHostController.onPtyHostStart(() => {
57-
this._logService.debug(`The terminal's pty host process is starting`);
58-
// Only fire the _restart_ event after it has started
59-
if (hasStarted) {
60-
this._logService.trace('IPtyHostController#onPtyHostRestart');
61-
this._onPtyHostRestart.fire();
62-
}
63-
statusBarAccessor?.dispose();
64-
this._isPtyHostUnresponsive = false;
65-
}));
66-
}
67-
if (this._ptyHostController.onPtyHostUnresponsive) {
68-
this._register(this._ptyHostController.onPtyHostUnresponsive(() => {
69-
statusBarAccessor?.dispose();
70-
if (!unresponsiveStatusBarEntry) {
71-
unresponsiveStatusBarEntry = {
72-
name: localize('ptyHostStatus', 'Pty Host Status'),
73-
text: `$(debug-disconnect) ${localize('ptyHostStatus.short', 'Pty Host')}`,
74-
tooltip: localize('nonResponsivePtyHost', "The connection to the terminal's pty host process is unresponsive, terminals may stop working. Click to manually restart the pty host."),
75-
ariaLabel: localize('ptyHostStatus.ariaLabel', 'Pty Host is unresponsive'),
76-
command: TerminalCommandId.RestartPtyHost,
77-
backgroundColor: themeColorFromId(STATUS_BAR_WARNING_ITEM_BACKGROUND),
78-
color: themeColorFromId(STATUS_BAR_WARNING_ITEM_FOREGROUND),
79-
};
80-
}
81-
statusBarAccessor = statusBarService.addEntry(unresponsiveStatusBarEntry, 'ptyHostStatus', StatusbarAlignment.LEFT);
82-
this._isPtyHostUnresponsive = true;
83-
this._onPtyHostUnresponsive.fire();
84-
}));
85-
}
86-
if (this._ptyHostController.onPtyHostResponsive) {
87-
this._register(this._ptyHostController.onPtyHostResponsive(() => {
88-
if (!this._isPtyHostUnresponsive) {
89-
return;
90-
}
91-
this._logService.info('The pty host became responsive again');
92-
statusBarAccessor?.dispose();
93-
this._isPtyHostUnresponsive = false;
94-
this._onPtyHostResponsive.fire();
95-
}));
96-
}
97-
if (this._ptyHostController.onPtyHostRequestResolveVariables) {
98-
this._register(this._ptyHostController.onPtyHostRequestResolveVariables(async e => {
99-
// Only answer requests for this workspace
100-
if (e.workspaceId !== this._workspaceContextService.getWorkspace().id) {
101-
return;
102-
}
103-
const activeWorkspaceRootUri = historyService.getLastActiveWorkspaceRoot(Schemas.file);
104-
const lastActiveWorkspaceRoot = activeWorkspaceRootUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri)) : undefined;
105-
const resolveCalls: Promise<string>[] = e.originalText.map(t => {
106-
return configurationResolverService.resolveAsync(lastActiveWorkspaceRoot, t);
107-
});
108-
const result = await Promise.all(resolveCalls);
109-
this._ptyHostController.acceptPtyHostResolvedVariables?.(e.requestId, result);
110-
}));
111-
}
49+
this._register(this._ptyHostController.onPtyHostExit(() => {
50+
this._logService.error(`The terminal's pty host process exited, the connection to all terminal processes was lost`);
51+
}));
52+
this.onPtyHostConnected(() => hasStarted = true);
53+
this._register(this._ptyHostController.onPtyHostStart(() => {
54+
this._logService.debug(`The terminal's pty host process is starting`);
55+
// Only fire the _restart_ event after it has started
56+
if (hasStarted) {
57+
this._logService.trace('IPtyHostController#onPtyHostRestart');
58+
this._onPtyHostRestart.fire();
59+
}
60+
statusBarAccessor?.dispose();
61+
this._isPtyHostUnresponsive = false;
62+
}));
63+
this._register(this._ptyHostController.onPtyHostUnresponsive(() => {
64+
statusBarAccessor?.dispose();
65+
if (!unresponsiveStatusBarEntry) {
66+
unresponsiveStatusBarEntry = {
67+
name: localize('ptyHostStatus', 'Pty Host Status'),
68+
text: `$(debug-disconnect) ${localize('ptyHostStatus.short', 'Pty Host')}`,
69+
tooltip: localize('nonResponsivePtyHost', "The connection to the terminal's pty host process is unresponsive, terminals may stop working. Click to manually restart the pty host."),
70+
ariaLabel: localize('ptyHostStatus.ariaLabel', 'Pty Host is unresponsive'),
71+
command: TerminalCommandId.RestartPtyHost,
72+
backgroundColor: themeColorFromId(STATUS_BAR_WARNING_ITEM_BACKGROUND),
73+
color: themeColorFromId(STATUS_BAR_WARNING_ITEM_FOREGROUND),
74+
};
75+
}
76+
statusBarAccessor = statusBarService.addEntry(unresponsiveStatusBarEntry, 'ptyHostStatus', StatusbarAlignment.LEFT);
77+
this._isPtyHostUnresponsive = true;
78+
this._onPtyHostUnresponsive.fire();
79+
}));
80+
this._register(this._ptyHostController.onPtyHostResponsive(() => {
81+
if (!this._isPtyHostUnresponsive) {
82+
return;
83+
}
84+
this._logService.info('The pty host became responsive again');
85+
statusBarAccessor?.dispose();
86+
this._isPtyHostUnresponsive = false;
87+
this._onPtyHostResponsive.fire();
88+
}));
89+
this._register(this._ptyHostController.onPtyHostRequestResolveVariables(async e => {
90+
// Only answer requests for this workspace
91+
if (e.workspaceId !== this._workspaceContextService.getWorkspace().id) {
92+
return;
93+
}
94+
const activeWorkspaceRootUri = historyService.getLastActiveWorkspaceRoot(Schemas.file);
95+
const lastActiveWorkspaceRoot = activeWorkspaceRootUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri)) : undefined;
96+
const resolveCalls: Promise<string>[] = e.originalText.map(t => {
97+
return configurationResolverService.resolveAsync(lastActiveWorkspaceRoot, t);
98+
});
99+
const result = await Promise.all(resolveCalls);
100+
this._ptyHostController.acceptPtyHostResolvedVariables(e.requestId, result);
101+
}));
112102
}
113103

114104
restartPtyHost(): void {
115-
this._ptyHostController.restartPtyHost?.();
105+
this._ptyHostController.restartPtyHost();
116106
}
117107

118108
protected _deserializeTerminalState(serializedState: string | undefined): ISerializedTerminalState[] | undefined {

0 commit comments

Comments
 (0)