|
| 1 | +Make opening files/folders from the terminal only open in the current instance |
| 2 | + |
| 3 | +Previously they would open in every code-server tab/window. |
| 4 | + |
| 5 | +To test: |
| 6 | + |
| 7 | +1. Run code-server |
| 8 | +2. Open code-server |
| 9 | +3. Open terminal |
| 10 | +4. Open another code-server window |
| 11 | +5. Run code-server with a file or directory argument |
| 12 | + |
| 13 | +The file or directory should only open from the instance attached to that |
| 14 | +terminal. |
| 15 | + |
| 16 | +Index: code-server/lib/vscode/src/vs/server/node/remoteTerminalChannel.ts |
| 17 | +=================================================================== |
| 18 | +--- code-server.orig/lib/vscode/src/vs/server/node/remoteTerminalChannel.ts |
| 19 | ++++ code-server/lib/vscode/src/vs/server/node/remoteTerminalChannel.ts |
| 20 | +@@ -89,7 +89,7 @@ export class RemoteTerminalChannel exten |
| 21 | + uriTransformer: IURITransformer; |
| 22 | + }>(); |
| 23 | + |
| 24 | +- private readonly _onExecuteCommand = this._register(new Emitter<{ reqId: number; commandId: string; commandArgs: any[] }>()); |
| 25 | ++ private readonly _onExecuteCommand = this._register(new Emitter<{ reqId: number; terminalId: number; commandId: string; commandArgs: any[] }>()); |
| 26 | + readonly onExecuteCommand = this._onExecuteCommand.event; |
| 27 | + |
| 28 | + constructor( |
| 29 | +@@ -240,20 +240,20 @@ export class RemoteTerminalChannel exten |
| 30 | + const ipcHandlePath = createRandomIPCHandle(); |
| 31 | + env.VSCODE_IPC_HOOK_CLI = ipcHandlePath; |
| 32 | + const commandsExecuter: ICommandsExecuter = { |
| 33 | +- executeCommand: <T>(id: string, ...args: any[]): Promise<T> => this._executeCommand(id, args, uriTransformer) |
| 34 | ++ executeCommand: <T>(commandId: string, ...args: any[]): Promise<T> => this._executeCommand(terminalId, commandId, args, uriTransformer) |
| 35 | + }; |
| 36 | + const cliServer = new CLIServerBase(commandsExecuter, this._logService, ipcHandlePath); |
| 37 | + |
| 38 | +- const id = await this._ptyService.createProcess(shellLaunchConfig, initialCwd, args.cols, args.rows, args.unicodeVersion, env, baseEnv, args.options, args.shouldPersistTerminal, args.workspaceId, args.workspaceName); |
| 39 | +- this._ptyService.onProcessExit(e => e.id === id && cliServer.dispose()); |
| 40 | ++ const terminalId = await this._ptyService.createProcess(shellLaunchConfig, initialCwd, args.cols, args.rows, args.unicodeVersion, env, baseEnv, args.options, args.shouldPersistTerminal, args.workspaceId, args.workspaceName); |
| 41 | ++ this._ptyService.onProcessExit(e => e.id === terminalId && cliServer.dispose()); |
| 42 | + |
| 43 | + return { |
| 44 | +- persistentTerminalId: id, |
| 45 | ++ persistentTerminalId: terminalId, |
| 46 | + resolvedShellLaunchConfig: shellLaunchConfig |
| 47 | + }; |
| 48 | + } |
| 49 | + |
| 50 | +- private _executeCommand<T>(commandId: string, commandArgs: any[], uriTransformer: IURITransformer): Promise<T> { |
| 51 | ++ private _executeCommand<T>(terminalId: number, commandId: string, commandArgs: any[], uriTransformer: IURITransformer): Promise<T> { |
| 52 | + let resolve!: (data: any) => void; |
| 53 | + let reject!: (err: any) => void; |
| 54 | + const result = new Promise<T>((_resolve, _reject) => { |
| 55 | +@@ -276,6 +276,7 @@ export class RemoteTerminalChannel exten |
| 56 | + }); |
| 57 | + this._onExecuteCommand.fire({ |
| 58 | + reqId, |
| 59 | ++ terminalId, |
| 60 | + commandId, |
| 61 | + commandArgs: serializedCommandArgs |
| 62 | + }); |
| 63 | +Index: code-server/lib/vscode/src/vs/workbench/contrib/terminal/browser/remoteTerminalBackend.ts |
| 64 | +=================================================================== |
| 65 | +--- code-server.orig/lib/vscode/src/vs/workbench/contrib/terminal/browser/remoteTerminalBackend.ts |
| 66 | ++++ code-server/lib/vscode/src/vs/workbench/contrib/terminal/browser/remoteTerminalBackend.ts |
| 67 | +@@ -94,10 +94,14 @@ class RemoteTerminalBackend extends Base |
| 68 | + this._remoteTerminalChannel.onExecuteCommand(async e => { |
| 69 | + const reqId = e.reqId; |
| 70 | + const commandId = e.commandId; |
| 71 | ++ const terminalId = e.terminalId; |
| 72 | + if (!allowedCommands.includes(commandId)) { |
| 73 | + this._remoteTerminalChannel.sendCommandResult(reqId, true, 'Invalid remote cli command: ' + commandId); |
| 74 | + return; |
| 75 | + } |
| 76 | ++ if (typeof terminalId !== "undefined" && !this._ptys.has(terminalId)) { |
| 77 | ++ return |
| 78 | ++ } |
| 79 | + const commandArgs = e.commandArgs.map(arg => revive(arg)); |
| 80 | + try { |
| 81 | + const result = await this._commandService.executeCommand(e.commandId, ...commandArgs); |
| 82 | +Index: code-server/lib/vscode/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts |
| 83 | +=================================================================== |
| 84 | +--- code-server.orig/lib/vscode/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts |
| 85 | ++++ code-server/lib/vscode/src/vs/workbench/contrib/terminal/common/remoteTerminalChannel.ts |
| 86 | +@@ -88,8 +88,8 @@ export class RemoteTerminalChannelClient |
| 87 | + get onProcessOrphanQuestion(): Event<{ id: number }> { |
| 88 | + return this._channel.listen<{ id: number }>('$onProcessOrphanQuestion'); |
| 89 | + } |
| 90 | +- get onExecuteCommand(): Event<{ reqId: number; commandId: string; commandArgs: any[] }> { |
| 91 | +- return this._channel.listen<{ reqId: number; commandId: string; commandArgs: any[] }>('$onExecuteCommand'); |
| 92 | ++ get onExecuteCommand(): Event<{ reqId: number; terminalId: number; commandId: string; commandArgs: any[] }> { |
| 93 | ++ return this._channel.listen<{ reqId: number; terminalId: number; commandId: string; commandArgs: any[] }>('$onExecuteCommand'); |
| 94 | + } |
| 95 | + get onDidRequestDetach(): Event<{ requestId: number; workspaceId: string; instanceId: number }> { |
| 96 | + return this._channel.listen<{ requestId: number; workspaceId: string; instanceId: number }>('$onDidRequestDetach'); |
0 commit comments