2023-06-15 05:32:07 +08:00
|
|
|
Store the IPC socket with workspace metadata.
|
2022-03-23 04:07:14 +08:00
|
|
|
|
|
|
|
This lets us use it to open files inside code-server from outside of
|
|
|
|
code-server.
|
|
|
|
|
2022-05-05 05:58:49 +08:00
|
|
|
To test this:
|
|
|
|
1. run code-server
|
|
|
|
2. open file outside of code-server i.e. `code-server <path-to-file`
|
|
|
|
|
|
|
|
It should open in your existing code-server instance.
|
|
|
|
|
2023-06-15 05:32:07 +08:00
|
|
|
When the extension host is terminated, the socket is unregistered.
|
|
|
|
|
2022-03-23 04:07:14 +08:00
|
|
|
Index: code-server/lib/vscode/src/vs/workbench/api/node/extHostExtensionService.ts
|
|
|
|
===================================================================
|
|
|
|
--- code-server.orig/lib/vscode/src/vs/workbench/api/node/extHostExtensionService.ts
|
|
|
|
+++ code-server/lib/vscode/src/vs/workbench/api/node/extHostExtensionService.ts
|
2023-06-22 14:47:01 +08:00
|
|
|
@@ -2,7 +2,7 @@
|
2022-03-23 04:07:14 +08:00
|
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
-
|
2023-06-15 05:32:07 +08:00
|
|
|
+import * as _http from 'http';
|
2022-03-23 04:07:14 +08:00
|
|
|
import * as performance from 'vs/base/common/performance';
|
|
|
|
import { createApiFactoryAndRegisterActors } from 'vs/workbench/api/common/extHost.api.impl';
|
|
|
|
import { RequireInterceptor } from 'vs/workbench/api/common/extHostRequireInterceptor';
|
2023-06-22 14:47:01 +08:00
|
|
|
@@ -17,6 +17,7 @@ import { ExtensionRuntime } from 'vs/wor
|
2023-06-15 05:32:07 +08:00
|
|
|
import { CLIServer } from 'vs/workbench/api/node/extHostCLIServer';
|
|
|
|
import { realpathSync } from 'vs/base/node/extpath';
|
|
|
|
import { ExtHostConsoleForwarder } from 'vs/workbench/api/node/extHostConsoleForwarder';
|
|
|
|
+import { IExtHostWorkspace } from '../common/extHostWorkspace';
|
2023-06-16 00:00:03 +08:00
|
|
|
import { ExtHostDiskFileSystemProvider } from 'vs/workbench/api/node/extHostDiskFileSystemProvider';
|
2023-06-15 05:32:07 +08:00
|
|
|
|
|
|
|
class NodeModuleRequireInterceptor extends RequireInterceptor {
|
2023-06-22 14:47:01 +08:00
|
|
|
@@ -83,6 +84,52 @@ export class ExtHostExtensionService ext
|
2023-06-15 05:32:07 +08:00
|
|
|
await interceptor.install();
|
|
|
|
performance.mark('code/extHost/didInitAPI');
|
|
|
|
|
|
|
|
+ (async () => {
|
|
|
|
+ const socketPath = process.env['VSCODE_IPC_HOOK_CLI'];
|
2023-06-22 14:47:01 +08:00
|
|
|
+ const codeServerSocketPath = process.env['CODE_SERVER_SESSION_SOCKET']
|
|
|
|
+ if (!socketPath || !codeServerSocketPath) {
|
2023-06-15 05:32:07 +08:00
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ const workspace = this._instaService.invokeFunction((accessor) => {
|
|
|
|
+ const workspaceService = accessor.get(IExtHostWorkspace);
|
|
|
|
+ return workspaceService.workspace;
|
|
|
|
+ });
|
|
|
|
+ const entry = {
|
|
|
|
+ workspace,
|
|
|
|
+ socketPath
|
|
|
|
+ };
|
|
|
|
+ const message = JSON.stringify({entry});
|
|
|
|
+ await new Promise<void>((resolve, reject) => {
|
|
|
|
+ const opts: _http.RequestOptions = {
|
|
|
|
+ path: '/add-session',
|
|
|
|
+ socketPath: codeServerSocketPath,
|
|
|
|
+ method: 'POST',
|
|
|
|
+ headers: {
|
|
|
|
+ 'content-type': 'application/json',
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ const req = _http.request(opts, (res) => {
|
|
|
|
+ res.on('error', reject);
|
|
|
|
+ res.on('end', () => {
|
|
|
|
+ try {
|
|
|
|
+ if (res.statusCode === 200) {
|
|
|
|
+ resolve();
|
|
|
|
+ } else {
|
|
|
|
+ reject(new Error('Unexpected status code: ' + res.statusCode));
|
|
|
|
+ }
|
|
|
|
+ } catch (e: unknown) {
|
|
|
|
+ reject(e);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ req.on('error', reject);
|
|
|
|
+ req.write(message);
|
|
|
|
+ req.end();
|
2022-03-23 04:07:14 +08:00
|
|
|
+ });
|
2023-06-15 05:32:07 +08:00
|
|
|
+ })().catch(error => {
|
|
|
|
+ this._logService.error(error);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
// Do this when extension service exists, but extensions are not being activated yet.
|
|
|
|
const configProvider = await this._extHostConfiguration.getConfigProvider();
|
|
|
|
await connectProxyResolver(this._extHostWorkspace, configProvider, this, this._logService, this._mainThreadTelemetryProxy, this._initData);
|
|
|
|
Index: code-server/lib/vscode/src/vs/workbench/api/node/extensionHostProcess.ts
|
|
|
|
===================================================================
|
|
|
|
--- code-server.orig/lib/vscode/src/vs/workbench/api/node/extensionHostProcess.ts
|
|
|
|
+++ code-server/lib/vscode/src/vs/workbench/api/node/extensionHostProcess.ts
|
2023-06-22 14:47:01 +08:00
|
|
|
@@ -3,6 +3,7 @@
|
2023-06-15 05:32:07 +08:00
|
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
+import * as _http from 'http';
|
|
|
|
import * as nativeWatchdog from 'native-watchdog';
|
|
|
|
import * as net from 'net';
|
|
|
|
import * as minimist from 'minimist';
|
2024-02-02 09:36:47 +08:00
|
|
|
@@ -418,7 +419,28 @@ async function startExtensionHostProcess
|
2023-06-15 05:32:07 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
// rewrite onTerminate-function to be a proper shutdown
|
|
|
|
- onTerminate = (reason: string) => extensionHostMain.terminate(reason);
|
|
|
|
+ onTerminate = (reason: string) => {
|
|
|
|
+ extensionHostMain.terminate(reason);
|
|
|
|
+
|
|
|
|
+ const socketPath = process.env['VSCODE_IPC_HOOK_CLI'];
|
2023-06-22 14:47:01 +08:00
|
|
|
+ const codeServerSocketPath = process.env['CODE_SERVER_SESSION_SOCKET']
|
|
|
|
+ if (!socketPath || !codeServerSocketPath) {
|
2023-06-15 05:32:07 +08:00
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ const message = JSON.stringify({socketPath});
|
|
|
|
+ const opts: _http.RequestOptions = {
|
|
|
|
+ path: '/delete-session',
|
|
|
|
+ socketPath: codeServerSocketPath,
|
|
|
|
+ method: 'POST',
|
|
|
|
+ headers: {
|
|
|
|
+ 'content-type': 'application/json',
|
|
|
|
+ 'accept': 'application/json'
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ const req = _http.request(opts);
|
|
|
|
+ req.write(message);
|
|
|
|
+ req.end();
|
|
|
|
+ };
|
|
|
|
}
|
2022-03-23 04:07:14 +08:00
|
|
|
|
2023-06-15 05:32:07 +08:00
|
|
|
startExtensionHostProcess().catch((err) => console.log(err));
|