1
- Store a static reference to the IPC socket
1
+ Store the IPC socket with workspace metadata.
2
2
3
3
This lets us use it to open files inside code-server from outside of
4
4
code-server.
@@ -9,6 +9,8 @@ To test this:
9
9
10
10
It should open in your existing code-server instance.
11
11
12
+ When the extension host is terminated, the socket is unregistered.
13
+
12
14
Index: code-server/lib/vscode/src/vs/workbench/api/node/extHostExtensionService.ts
13
15
===================================================================
14
16
--- code-server.orig/lib/vscode/src/vs/workbench/api/node/extHostExtensionService.ts
@@ -18,20 +20,114 @@ Index: code-server/lib/vscode/src/vs/workbench/api/node/extHostExtensionService.
18
20
* Licensed under the MIT License. See License.txt in the project root for license information.
19
21
*--------------------------------------------------------------------------------------------*/
20
22
-
21
- + import { promises as fs } from 'fs ';
22
- + import * as os from 'os'
23
+ + import * as os from 'os ';
24
+ + import * as _http from 'http';
23
25
+ import * as path from 'vs/base/common/path';
24
26
import * as performance from 'vs/base/common/performance';
25
27
import { createApiFactoryAndRegisterActors } from 'vs/workbench/api/common/extHost.api.impl';
26
28
import { RequireInterceptor } from 'vs/workbench/api/common/extHostRequireInterceptor';
27
- @@ -72,6 +74,10 @@ export class ExtHostExtensionService ext
28
- if (this._initData.remote.isRemote && this._initData.remote.authority) {
29
- const cliServer = this._instaService.createInstance(CLIServer);
30
- process.env['VSCODE_IPC_HOOK_CLI'] = cliServer.ipcHandlePath;
31
- +
32
- + fs.writeFile(path.join(os.tmpdir(), 'vscode-ipc'), cliServer.ipcHandlePath).catch((error) => {
33
- + this._logService.error(error);
29
+ @@ -17,6 +19,7 @@ import { ExtensionRuntime } from 'vs/wor
30
+ import { CLIServer } from 'vs/workbench/api/node/extHostCLIServer';
31
+ import { realpathSync } from 'vs/base/node/extpath';
32
+ import { ExtHostConsoleForwarder } from 'vs/workbench/api/node/extHostConsoleForwarder';
33
+ + import { IExtHostWorkspace } from '../common/extHostWorkspace';
34
+
35
+ class NodeModuleRequireInterceptor extends RequireInterceptor {
36
+
37
+ @@ -79,6 +82,52 @@ export class ExtHostExtensionService ext
38
+ await interceptor.install();
39
+ performance.mark('code/extHost/didInitAPI');
40
+
41
+ + (async () => {
42
+ + const socketPath = process.env['VSCODE_IPC_HOOK_CLI'];
43
+ + if (!socketPath) {
44
+ + return;
45
+ + }
46
+ + const workspace = this._instaService.invokeFunction((accessor) => {
47
+ + const workspaceService = accessor.get(IExtHostWorkspace);
48
+ + return workspaceService.workspace;
49
+ + });
50
+ + const entry = {
51
+ + workspace,
52
+ + socketPath
53
+ + };
54
+ + const message = JSON.stringify({entry});
55
+ + const codeServerSocketPath = path.join(os.tmpdir(), 'code-server-ipc.sock');
56
+ + await new Promise<void>((resolve, reject) => {
57
+ + const opts: _http.RequestOptions = {
58
+ + path: '/add-session',
59
+ + socketPath: codeServerSocketPath,
60
+ + method: 'POST',
61
+ + headers: {
62
+ + 'content-type': 'application/json',
63
+ + }
64
+ + };
65
+ + const req = _http.request(opts, (res) => {
66
+ + res.on('error', reject);
67
+ + res.on('end', () => {
68
+ + try {
69
+ + if (res.statusCode === 200) {
70
+ + resolve();
71
+ + } else {
72
+ + reject(new Error('Unexpected status code: ' + res.statusCode));
73
+ + }
74
+ + } catch (e: unknown) {
75
+ + reject(e);
76
+ + }
77
+ + });
78
+ + });
79
+ + req.on('error', reject);
80
+ + req.write(message);
81
+ + req.end();
34
82
+ });
35
- }
83
+ + })().catch(error => {
84
+ + this._logService.error(error);
85
+ + });
86
+ +
87
+ // Do this when extension service exists, but extensions are not being activated yet.
88
+ const configProvider = await this._extHostConfiguration.getConfigProvider();
89
+ await connectProxyResolver(this._extHostWorkspace, configProvider, this, this._logService, this._mainThreadTelemetryProxy, this._initData);
90
+ Index: code-server/lib/vscode/src/vs/workbench/api/node/extensionHostProcess.ts
91
+ ===================================================================
92
+ --- code-server.orig/lib/vscode/src/vs/workbench/api/node/extensionHostProcess.ts
93
+ +++ code-server/lib/vscode/src/vs/workbench/api/node/extensionHostProcess.ts
94
+ @@ -3,6 +3,9 @@
95
+ * Licensed under the MIT License. See License.txt in the project root for license information.
96
+ *--------------------------------------------------------------------------------------------*/
97
+
98
+ + import * as os from 'os';
99
+ + import * as _http from 'http';
100
+ + import * as path from 'vs/base/common/path';
101
+ import * as nativeWatchdog from 'native-watchdog';
102
+ import * as net from 'net';
103
+ import * as minimist from 'minimist';
104
+ @@ -400,7 +403,28 @@ async function startExtensionHostProcess
105
+ );
106
+
107
+ // rewrite onTerminate-function to be a proper shutdown
108
+ - onTerminate = (reason: string) => extensionHostMain.terminate(reason);
109
+ + onTerminate = (reason: string) => {
110
+ + extensionHostMain.terminate(reason);
111
+ +
112
+ + const socketPath = process.env['VSCODE_IPC_HOOK_CLI'];
113
+ + if (!socketPath) {
114
+ + return;
115
+ + }
116
+ + const message = JSON.stringify({socketPath});
117
+ + const codeServerSocketPath = path.join(os.tmpdir(), 'code-server-ipc.sock');
118
+ + const opts: _http.RequestOptions = {
119
+ + path: '/delete-session',
120
+ + socketPath: codeServerSocketPath,
121
+ + method: 'POST',
122
+ + headers: {
123
+ + 'content-type': 'application/json',
124
+ + 'accept': 'application/json'
125
+ + }
126
+ + };
127
+ + const req = _http.request(opts);
128
+ + req.write(message);
129
+ + req.end();
130
+ + };
131
+ }
36
132
37
- // Module loading tricks
133
+ startExtensionHostProcess().catch((err) => console.log(err));
0 commit comments