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,8 +20,8 @@ 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';
@@ -32,12 +34,12 @@ Index: code-server/lib/vscode/src/vs/workbench/api/node/extHostExtensionService.
32
34
33
35
class NodeModuleRequireInterceptor extends RequireInterceptor {
34
36
35
- @@ -79,6 +82,24 @@ export class ExtHostExtensionService ext
37
+ @@ -79,6 +82,59 @@ export class ExtHostExtensionService ext
36
38
await interceptor.install();
37
39
performance.mark('code/extHost/didInitAPI');
38
40
39
41
+ (async () => {
40
- + let socketPath = process.env['VSCODE_IPC_HOOK_CLI'];
42
+ + const socketPath = process.env['VSCODE_IPC_HOOK_CLI'];
41
43
+ if (!socketPath) {
42
44
+ return;
43
45
+ }
@@ -49,11 +51,90 @@ Index: code-server/lib/vscode/src/vs/workbench/api/node/extHostExtensionService.
49
51
+ workspace,
50
52
+ socketPath
51
53
+ };
52
- + fs.appendFile(path.join(os.tmpdir(), 'vscode-ipc'), '\n' + JSON.stringify(entry), 'utf-8');
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
+ + 'accept': 'application/json'
64
+ + }
65
+ + };
66
+ + const req = _http.request(opts, (res) => {
67
+ + if (res.headers['content-type'] !== 'application/json') {
68
+ + reject('Error in response: Invalid content type: Expected \'application/json\', is: ' + res.headers['content-type']);
69
+ + return;
70
+ + }
71
+ +
72
+ + res.setEncoding('utf8');
73
+ + res.on('error', reject);
74
+ + res.on('end', () => {
75
+ + try {
76
+ + if (res.statusCode === 200) {
77
+ + resolve();
78
+ + } else {
79
+ + reject(new Error('Unexpected status code: ' + res.statusCode));
80
+ + }
81
+ + } catch (e: unknown) {
82
+ + reject(e);
83
+ + }
84
+ + });
85
+ + });
86
+ + req.on('error', reject);
87
+ + req.write(message);
88
+ + req.end();
89
+ + });
53
90
+ })().catch(error => {
54
91
+ this._logService.error(error);
55
92
+ });
56
93
+
57
94
// Do this when extension service exists, but extensions are not being activated yet.
58
95
const configProvider = await this._extHostConfiguration.getConfigProvider();
59
96
await connectProxyResolver(this._extHostWorkspace, configProvider, this, this._logService, this._mainThreadTelemetryProxy, this._initData);
97
+ Index: code-server/lib/vscode/src/vs/workbench/api/node/extensionHostProcess.ts
98
+ ===================================================================
99
+ --- code-server.orig/lib/vscode/src/vs/workbench/api/node/extensionHostProcess.ts
100
+ +++ code-server/lib/vscode/src/vs/workbench/api/node/extensionHostProcess.ts
101
+ @@ -3,6 +3,9 @@
102
+ * Licensed under the MIT License. See License.txt in the project root for license information.
103
+ *--------------------------------------------------------------------------------------------*/
104
+
105
+ + import * as os from 'os';
106
+ + import * as _http from 'http';
107
+ + import * as path from 'vs/base/common/path';
108
+ import * as nativeWatchdog from 'native-watchdog';
109
+ import * as net from 'net';
110
+ import * as minimist from 'minimist';
111
+ @@ -400,7 +403,28 @@ async function startExtensionHostProcess
112
+ );
113
+
114
+ // rewrite onTerminate-function to be a proper shutdown
115
+ - onTerminate = (reason: string) => extensionHostMain.terminate(reason);
116
+ + onTerminate = (reason: string) => {
117
+ + extensionHostMain.terminate(reason);
118
+ +
119
+ + const socketPath = process.env['VSCODE_IPC_HOOK_CLI'];
120
+ + if (!socketPath) {
121
+ + return;
122
+ + }
123
+ + const message = JSON.stringify({socketPath});
124
+ + const codeServerSocketPath = path.join(os.tmpdir(), 'code-server-ipc.sock');
125
+ + const opts: _http.RequestOptions = {
126
+ + path: '/delete-session',
127
+ + socketPath: codeServerSocketPath,
128
+ + method: 'POST',
129
+ + headers: {
130
+ + 'content-type': 'application/json',
131
+ + 'accept': 'application/json'
132
+ + }
133
+ + };
134
+ + const req = _http.request(opts);
135
+ + req.write(message);
136
+ + req.end();
137
+ + };
138
+ }
139
+
140
+ startExtensionHostProcess().catch((err) => console.log(err));
0 commit comments