mirror of
https://github.com/coder/code-server.git
synced 2024-11-22 02:44:44 +03:00
494a3e0c2b
* Update Code to 1.95.1 * Update Node to 20.18.0 * Update build.yaml to use Ubuntu 22.04 This is to resolve a gcc error. Might have to address the release step later as well. * Fix --stdin-to-clipboard With the switch to esm, the fs require is failing. fs is already imported, so we can just use it anyway. * Fix mangled exports * Update CSP hashes
129 lines
4.8 KiB
Diff
129 lines
4.8 KiB
Diff
Store the IPC socket with workspace metadata.
|
|
|
|
This lets us use it to open files inside code-server from outside of
|
|
code-server.
|
|
|
|
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.
|
|
|
|
When the extension host is terminated, the socket is unregistered.
|
|
|
|
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
|
|
@@ -3,6 +3,7 @@
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
+import * as _http from 'http';
|
|
import * as performance from '../../../base/common/performance.js';
|
|
import { createApiFactoryAndRegisterActors } from '../common/extHost.api.impl.js';
|
|
import { RequireInterceptor } from '../common/extHostRequireInterceptor.js';
|
|
@@ -17,6 +18,7 @@ import { ExtensionRuntime } from '../com
|
|
import { CLIServer } from './extHostCLIServer.js';
|
|
import { realpathSync } from '../../../base/node/extpath.js';
|
|
import { ExtHostConsoleForwarder } from './extHostConsoleForwarder.js';
|
|
+import { IExtHostWorkspace } from '../common/extHostWorkspace.js';
|
|
import { ExtHostDiskFileSystemProvider } from './extHostDiskFileSystemProvider.js';
|
|
import { createRequire } from 'node:module';
|
|
const require = createRequire(import.meta.url);
|
|
@@ -97,6 +99,52 @@ export class ExtHostExtensionService ext
|
|
await interceptor.install();
|
|
performance.mark('code/extHost/didInitAPI');
|
|
|
|
+ (async () => {
|
|
+ const socketPath = process.env['VSCODE_IPC_HOOK_CLI'];
|
|
+ const codeServerSocketPath = process.env['CODE_SERVER_SESSION_SOCKET']
|
|
+ if (!socketPath || !codeServerSocketPath) {
|
|
+ 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();
|
|
+ });
|
|
+ })().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, this._store);
|
|
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
|
|
@@ -3,6 +3,7 @@
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
+import * as _http from 'http';
|
|
import minimist from 'minimist';
|
|
import * as nativeWatchdog from 'native-watchdog';
|
|
import * as net from 'net';
|
|
@@ -422,7 +423,28 @@ async function startExtensionHostProcess
|
|
);
|
|
|
|
// 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'];
|
|
+ const codeServerSocketPath = process.env['CODE_SERVER_SESSION_SOCKET']
|
|
+ if (!socketPath || !codeServerSocketPath) {
|
|
+ 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();
|
|
+ };
|
|
}
|
|
|
|
startExtensionHostProcess().catch((err) => console.log(err));
|