Skip to content

Commit 96613e5

Browse files
committed
fix: file/directory opens from terminal
1 parent a879844 commit 96613e5

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

patches/cli-window-open.diff

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

patches/series

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ sourcemaps.diff
1919
disable-downloads.diff
2020
telemetry.diff
2121
display-language.diff
22+
cli-window-open.diff

0 commit comments

Comments
 (0)