Skip to content

Commit f632275

Browse files
authored
Merge pull request microsoft#187183 from microsoft/tyriar/187176
Use a const enum for all remote terminal channel messages
2 parents 57ae321 + a50fca3 commit f632275

File tree

6 files changed

+214
-112
lines changed

6 files changed

+214
-112
lines changed

src/vs/server/node/remoteTerminalChannel.ts

Lines changed: 62 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { CLIServerBase, ICommandsExecuter } from 'vs/workbench/api/node/extHostC
2222
import { IEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable';
2323
import { MergedEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableCollection';
2424
import { deserializeEnvironmentDescriptionMap, deserializeEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableShared';
25-
import { ICreateTerminalProcessArguments, ICreateTerminalProcessResult, IWorkspaceFolderData } from 'vs/workbench/contrib/terminal/common/remoteTerminalChannel';
25+
import { ICreateTerminalProcessArguments, ICreateTerminalProcessResult, IWorkspaceFolderData, RemoteTerminalChannelEvent, RemoteTerminalChannelRequest } from 'vs/workbench/contrib/terminal/common/remote/terminal';
2626
import * as terminalEnvironment from 'vs/workbench/contrib/terminal/common/terminalEnvironment';
2727
import { AbstractVariableResolverService } from 'vs/workbench/services/configurationResolver/common/variableResolver';
2828
import { buildUserEnvironment } from 'vs/server/node/extensionHostConnection';
@@ -105,79 +105,80 @@ export class RemoteTerminalChannel extends Disposable implements IServerChannel<
105105
super();
106106
}
107107

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

112-
case '$createProcess': {
112+
case RemoteTerminalChannelRequest.CreateProcess: {
113113
const uriTransformer = createURITransformer(ctx.remoteAuthority);
114114
return this._createProcess(uriTransformer, <ICreateTerminalProcessArguments>args);
115115
}
116-
case '$attachToProcess': return this._ptyHostService.attachToProcess.apply(this._ptyHostService, args);
117-
case '$detachFromProcess': return this._ptyHostService.detachFromProcess.apply(this._ptyHostService, args);
118-
119-
case '$listProcesses': return this._ptyHostService.listProcesses.apply(this._ptyHostService, args);
120-
case '$getPerformanceMarks': return this._ptyHostService.getPerformanceMarks.apply(this._ptyHostService, args);
121-
case '$orphanQuestionReply': return this._ptyHostService.orphanQuestionReply.apply(this._ptyHostService, args);
122-
case '$acceptPtyHostResolvedVariables': return this._ptyHostService.acceptPtyHostResolvedVariables.apply(this._ptyHostService, args);
123-
124-
case '$start': return this._ptyHostService.start.apply(this._ptyHostService, args);
125-
case '$input': return this._ptyHostService.input.apply(this._ptyHostService, args);
126-
case '$acknowledgeDataEvent': return this._ptyHostService.acknowledgeDataEvent.apply(this._ptyHostService, args);
127-
case '$shutdown': return this._ptyHostService.shutdown.apply(this._ptyHostService, args);
128-
case '$resize': return this._ptyHostService.resize.apply(this._ptyHostService, args);
129-
case '$clearBuffer': return this._ptyHostService.clearBuffer.apply(this._ptyHostService, args);
130-
case '$getInitialCwd': return this._ptyHostService.getInitialCwd.apply(this._ptyHostService, args);
131-
case '$getCwd': return this._ptyHostService.getCwd.apply(this._ptyHostService, args);
132-
133-
case '$processBinary': return this._ptyHostService.processBinary.apply(this._ptyHostService, args);
134-
135-
case '$sendCommandResult': return this._sendCommandResult(args[0], args[1], args[2]);
136-
case '$installAutoReply': return this._ptyHostService.installAutoReply.apply(this._ptyHostService, args);
137-
case '$uninstallAllAutoReplies': return this._ptyHostService.uninstallAllAutoReplies.apply(this._ptyHostService, args);
138-
case '$getDefaultSystemShell': return this._getDefaultSystemShell.apply(this, args);
139-
case '$getProfiles': return this._getProfiles.apply(this, args);
140-
case '$getEnvironment': return this._getEnvironment();
141-
case '$getWslPath': return this._getWslPath(args[0], args[1]);
142-
case '$getTerminalLayoutInfo': return this._ptyHostService.getTerminalLayoutInfo(<IGetTerminalLayoutInfoArgs>args);
143-
case '$setTerminalLayoutInfo': return this._ptyHostService.setTerminalLayoutInfo(<ISetTerminalLayoutInfoArgs>args);
144-
case '$serializeTerminalState': return this._ptyHostService.serializeTerminalState.apply(this._ptyHostService, args);
145-
case '$reviveTerminalProcesses': return this._ptyHostService.reviveTerminalProcesses.apply(this._ptyHostService, args);
146-
case '$getRevivedPtyNewId': return this._ptyHostService.getRevivedPtyNewId.apply(this._ptyHostService, args);
147-
case '$setUnicodeVersion': return this._ptyHostService.setUnicodeVersion.apply(this._ptyHostService, args);
148-
case '$reduceConnectionGraceTime': return this._reduceConnectionGraceTime();
149-
case '$updateIcon': return this._ptyHostService.updateIcon.apply(this._ptyHostService, args);
150-
case '$updateTitle': return this._ptyHostService.updateTitle.apply(this._ptyHostService, args);
151-
case '$updateProperty': return this._ptyHostService.updateProperty.apply(this._ptyHostService, args);
152-
case '$refreshProperty': return this._ptyHostService.refreshProperty.apply(this._ptyHostService, args);
153-
case '$requestDetachInstance': return this._ptyHostService.requestDetachInstance(args[0], args[1]);
154-
case '$acceptDetachedInstance': return this._ptyHostService.acceptDetachInstanceReply(args[0], args[1]);
155-
case '$freePortKillProcess': return this._ptyHostService.freePortKillProcess.apply(this._ptyHostService, args);
116+
case RemoteTerminalChannelRequest.AttachToProcess: return this._ptyHostService.attachToProcess.apply(this._ptyHostService, args);
117+
case RemoteTerminalChannelRequest.DetachFromProcess: return this._ptyHostService.detachFromProcess.apply(this._ptyHostService, args);
118+
119+
case RemoteTerminalChannelRequest.ListProcesses: return this._ptyHostService.listProcesses.apply(this._ptyHostService, args);
120+
case RemoteTerminalChannelRequest.GetPerformanceMarks: return this._ptyHostService.getPerformanceMarks.apply(this._ptyHostService, args);
121+
case RemoteTerminalChannelRequest.OrphanQuestionReply: return this._ptyHostService.orphanQuestionReply.apply(this._ptyHostService, args);
122+
case RemoteTerminalChannelRequest.AcceptPtyHostResolvedVariables: return this._ptyHostService.acceptPtyHostResolvedVariables.apply(this._ptyHostService, args);
123+
124+
case RemoteTerminalChannelRequest.Start: return this._ptyHostService.start.apply(this._ptyHostService, args);
125+
case RemoteTerminalChannelRequest.Input: return this._ptyHostService.input.apply(this._ptyHostService, args);
126+
case RemoteTerminalChannelRequest.AcknowledgeDataEvent: return this._ptyHostService.acknowledgeDataEvent.apply(this._ptyHostService, args);
127+
case RemoteTerminalChannelRequest.Shutdown: return this._ptyHostService.shutdown.apply(this._ptyHostService, args);
128+
case RemoteTerminalChannelRequest.Resize: return this._ptyHostService.resize.apply(this._ptyHostService, args);
129+
case RemoteTerminalChannelRequest.ClearBuffer: return this._ptyHostService.clearBuffer.apply(this._ptyHostService, args);
130+
case RemoteTerminalChannelRequest.GetInitialCwd: return this._ptyHostService.getInitialCwd.apply(this._ptyHostService, args);
131+
case RemoteTerminalChannelRequest.GetCwd: return this._ptyHostService.getCwd.apply(this._ptyHostService, args);
132+
133+
case RemoteTerminalChannelRequest.ProcessBinary: return this._ptyHostService.processBinary.apply(this._ptyHostService, args);
134+
135+
case RemoteTerminalChannelRequest.SendCommandResult: return this._sendCommandResult(args[0], args[1], args[2]);
136+
case RemoteTerminalChannelRequest.InstallAutoReply: return this._ptyHostService.installAutoReply.apply(this._ptyHostService, args);
137+
case RemoteTerminalChannelRequest.UninstallAllAutoReplies: return this._ptyHostService.uninstallAllAutoReplies.apply(this._ptyHostService, args);
138+
case RemoteTerminalChannelRequest.GetDefaultSystemShell: return this._getDefaultSystemShell.apply(this, args);
139+
case RemoteTerminalChannelRequest.GetProfiles: return this._getProfiles.apply(this, args);
140+
case RemoteTerminalChannelRequest.GetEnvironment: return this._getEnvironment();
141+
case RemoteTerminalChannelRequest.GetWslPath: return this._getWslPath(args[0], args[1]);
142+
case RemoteTerminalChannelRequest.GetTerminalLayoutInfo: return this._ptyHostService.getTerminalLayoutInfo(<IGetTerminalLayoutInfoArgs>args);
143+
case RemoteTerminalChannelRequest.SetTerminalLayoutInfo: return this._ptyHostService.setTerminalLayoutInfo(<ISetTerminalLayoutInfoArgs>args);
144+
case RemoteTerminalChannelRequest.SerializeTerminalState: return this._ptyHostService.serializeTerminalState.apply(this._ptyHostService, args);
145+
case RemoteTerminalChannelRequest.ReviveTerminalProcesses: return this._ptyHostService.reviveTerminalProcesses.apply(this._ptyHostService, args);
146+
case RemoteTerminalChannelRequest.GetRevivedPtyNewId: return this._ptyHostService.getRevivedPtyNewId.apply(this._ptyHostService, args);
147+
case RemoteTerminalChannelRequest.SetUnicodeVersion: return this._ptyHostService.setUnicodeVersion.apply(this._ptyHostService, args);
148+
case RemoteTerminalChannelRequest.ReduceConnectionGraceTime: return this._reduceConnectionGraceTime();
149+
case RemoteTerminalChannelRequest.UpdateIcon: return this._ptyHostService.updateIcon.apply(this._ptyHostService, args);
150+
case RemoteTerminalChannelRequest.UpdateTitle: return this._ptyHostService.updateTitle.apply(this._ptyHostService, args);
151+
case RemoteTerminalChannelRequest.UpdateProperty: return this._ptyHostService.updateProperty.apply(this._ptyHostService, args);
152+
case RemoteTerminalChannelRequest.RefreshProperty: return this._ptyHostService.refreshProperty.apply(this._ptyHostService, args);
153+
case RemoteTerminalChannelRequest.RequestDetachInstance: return this._ptyHostService.requestDetachInstance(args[0], args[1]);
154+
case RemoteTerminalChannelRequest.AcceptDetachedInstance: return this._ptyHostService.acceptDetachInstanceReply(args[0], args[1]);
155+
case RemoteTerminalChannelRequest.FreePortKillProcess: return this._ptyHostService.freePortKillProcess.apply(this._ptyHostService, args);
156+
case RemoteTerminalChannelRequest.AcceptDetachInstanceReply: return this._ptyHostService.acceptDetachInstanceReply.apply(this._ptyHostService, args);
156157
}
157158

159+
// @ts-expect-error Assert command is the `never` type to ensure all messages are handled
158160
throw new Error(`IPC Command ${command} not found`);
159161
}
160162

161-
listen(_: any, event: string, arg: any): Event<any> {
163+
listen(_: any, event: RemoteTerminalChannelEvent, arg: any): Event<any> {
162164
switch (event) {
163-
case '$onPtyHostExitEvent': return this._ptyHostService.onPtyHostExit || Event.None;
164-
case '$onPtyHostStartEvent': return this._ptyHostService.onPtyHostStart || Event.None;
165-
case '$onPtyHostUnresponsiveEvent': return this._ptyHostService.onPtyHostUnresponsive || Event.None;
166-
case '$onPtyHostResponsiveEvent': return this._ptyHostService.onPtyHostResponsive || Event.None;
167-
case '$onPtyHostRequestResolveVariablesEvent': return this._ptyHostService.onPtyHostRequestResolveVariables || Event.None;
168-
case '$onProcessDataEvent': return this._ptyHostService.onProcessData;
169-
case '$onProcessReadyEvent': return this._ptyHostService.onProcessReady;
170-
case '$onProcessExitEvent': return this._ptyHostService.onProcessExit;
171-
case '$onProcessReplayEvent': return this._ptyHostService.onProcessReplay;
172-
case '$onProcessOrphanQuestion': return this._ptyHostService.onProcessOrphanQuestion;
173-
case '$onExecuteCommand': return this.onExecuteCommand;
174-
case '$onDidRequestDetach': return this._ptyHostService.onDidRequestDetach || Event.None;
175-
case '$onDidChangeProperty': return this._ptyHostService.onDidChangeProperty;
176-
default:
177-
break;
165+
case RemoteTerminalChannelEvent.OnPtyHostExitEvent: return this._ptyHostService.onPtyHostExit || Event.None;
166+
case RemoteTerminalChannelEvent.OnPtyHostStartEvent: return this._ptyHostService.onPtyHostStart || Event.None;
167+
case RemoteTerminalChannelEvent.OnPtyHostUnresponsiveEvent: return this._ptyHostService.onPtyHostUnresponsive || Event.None;
168+
case RemoteTerminalChannelEvent.OnPtyHostResponsiveEvent: return this._ptyHostService.onPtyHostResponsive || Event.None;
169+
case RemoteTerminalChannelEvent.OnPtyHostRequestResolveVariablesEvent: return this._ptyHostService.onPtyHostRequestResolveVariables || Event.None;
170+
case RemoteTerminalChannelEvent.OnProcessDataEvent: return this._ptyHostService.onProcessData;
171+
case RemoteTerminalChannelEvent.OnProcessReadyEvent: return this._ptyHostService.onProcessReady;
172+
case RemoteTerminalChannelEvent.OnProcessExitEvent: return this._ptyHostService.onProcessExit;
173+
case RemoteTerminalChannelEvent.OnProcessReplayEvent: return this._ptyHostService.onProcessReplay;
174+
case RemoteTerminalChannelEvent.OnProcessOrphanQuestion: return this._ptyHostService.onProcessOrphanQuestion;
175+
case RemoteTerminalChannelEvent.OnExecuteCommand: return this.onExecuteCommand;
176+
case RemoteTerminalChannelEvent.OnDidRequestDetach: return this._ptyHostService.onDidRequestDetach || Event.None;
177+
case RemoteTerminalChannelEvent.OnDidChangeProperty: return this._ptyHostService.onDidChangeProperty;
178178
}
179179

180-
throw new Error('Not supported');
180+
// @ts-expect-error Assert event is the `never` type to ensure all messages are handled
181+
throw new Error(`IPC Command ${event} not found`);
181182
}
182183

183184
private async _createProcess(uriTransformer: IURITransformer, args: ICreateTerminalProcessArguments): Promise<ICreateTerminalProcessResult> {

src/vs/server/node/serverServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import { RemoteTerminalChannel } from 'vs/server/node/remoteTerminalChannel';
6060
import { createURITransformer } from 'vs/workbench/api/node/uriTransformer';
6161
import { ServerConnectionToken } from 'vs/server/node/serverConnectionToken';
6262
import { ServerEnvironmentService, ServerParsedArgs } from 'vs/server/node/serverEnvironmentService';
63-
import { REMOTE_TERMINAL_CHANNEL_NAME } from 'vs/workbench/contrib/terminal/common/remoteTerminalChannel';
63+
import { REMOTE_TERMINAL_CHANNEL_NAME } from 'vs/workbench/contrib/terminal/common/remote/remoteTerminalChannel';
6464
import { REMOTE_FILE_SYSTEM_CHANNEL_NAME } from 'vs/workbench/services/remote/common/remoteFileSystemProviderClient';
6565
import { ExtensionHostStatusService, IExtensionHostStatusService } from 'vs/server/node/extensionHostStatusService';
6666
import { IExtensionsScannerService } from 'vs/platform/extensionManagement/common/extensionsScannerService';

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { mark } from 'vs/base/common/performance';
1010
import { URI } from 'vs/base/common/uri';
1111
import { IPtyHostProcessReplayEvent, ISerializedCommandDetectionCapability } from 'vs/platform/terminal/common/capabilities/capabilities';
1212
import { IProcessDataEvent, ITerminalChildProcess, ITerminalLaunchError, IProcessProperty, IProcessPropertyMap, ProcessPropertyType, IProcessReadyEvent, ITerminalLogService } from 'vs/platform/terminal/common/terminal';
13-
import { RemoteTerminalChannelClient } from 'vs/workbench/contrib/terminal/common/remoteTerminalChannel';
13+
import { RemoteTerminalChannelClient } from 'vs/workbench/contrib/terminal/common/remote/remoteTerminalChannel';
1414
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
1515

1616
export class RemotePty extends Disposable implements ITerminalChildProcess {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
2222
import { BaseTerminalBackend } from 'vs/workbench/contrib/terminal/browser/baseTerminalBackend';
2323
import { RemotePty } from 'vs/workbench/contrib/terminal/browser/remotePty';
2424
import { ITerminalInstanceService } from 'vs/workbench/contrib/terminal/browser/terminal';
25-
import { RemoteTerminalChannelClient, REMOTE_TERMINAL_CHANNEL_NAME } from 'vs/workbench/contrib/terminal/common/remoteTerminalChannel';
25+
import { RemoteTerminalChannelClient, REMOTE_TERMINAL_CHANNEL_NAME } from 'vs/workbench/contrib/terminal/common/remote/remoteTerminalChannel';
2626
import { ICompleteTerminalConfiguration, ITerminalConfiguration, TERMINAL_CONFIG_SECTION } from 'vs/workbench/contrib/terminal/common/terminal';
2727
import { TerminalStorageKeys } from 'vs/workbench/contrib/terminal/common/terminalStorageKeys';
2828
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';

0 commit comments

Comments
 (0)