@@ -852,7 +852,7 @@ index 0000000000..eb62b87798
852
852
+ }
853
853
diff --git a/src/vs/server/entry.ts b/src/vs/server/entry.ts
854
854
new file mode 100644
855
- index 0000000000..cb606e6a68
855
+ index 0000000000..9995e9f7fc
856
856
--- /dev/null
857
857
+++ b/src/vs/server/entry.ts
858
858
@@ -0,0 +1,67 @@
@@ -897,8 +897,8 @@ index 0000000000..cb606e6a68
897
897
+ process.send(message);
898
898
+ };
899
899
+
900
- + // Wait for the init message then start up VS Code. Future messages will return
901
- + // new workbench options without starting a new instance.
900
+ + // Wait for the init message then start up VS Code. Subsequent messages will
901
+ + // return new workbench options without starting a new instance.
902
902
+ process.on('message', async (message: CodeServerMessage, socket) => {
903
903
+ logger.debug('got message from code-server', field('message', message));
904
904
+ switch (message.type) {
@@ -934,10 +934,10 @@ index 0000000000..56331ff1fc
934
934
+ require('../../bootstrap-amd').load('vs/server/entry');
935
935
diff --git a/src/vs/server/ipc.d.ts b/src/vs/server/ipc.d.ts
936
936
new file mode 100644
937
- index 0000000000..218faa34d2
937
+ index 0000000000..3bfef75d81
938
938
--- /dev/null
939
939
+++ b/src/vs/server/ipc.d.ts
940
- @@ -0,0 +1,93 @@
940
+ @@ -0,0 +1,91 @@
941
941
+ /**
942
942
+ * External interfaces for integration into code-server over IPC. No vs imports
943
943
+ * should be made in this file.
@@ -971,19 +971,18 @@ index 0000000000..218faa34d2
971
971
+ export type VscodeMessage = ReadyMessage | OptionsMessage;
972
972
+
973
973
+ export interface StartPath {
974
- + path?: string[] | string;
975
- + workspace? : boolean;
974
+ + url: string;
975
+ + workspace: boolean;
976
976
+ }
977
977
+
978
- + export interface Settings {
979
- + lastVisited?: StartPath ;
978
+ + export interface Args {
979
+ + _: string[] ;
980
980
+ }
981
981
+
982
982
+ export interface VscodeOptions {
983
983
+ readonly remoteAuthority: string;
984
- + readonly query: Query;
985
- + readonly args?: string[];
986
- + readonly settings: Settings;
984
+ + readonly args: Args;
985
+ + readonly startPath?: StartPath;
987
986
+ }
988
987
+
989
988
+ export interface VscodeOptionsMessage extends VscodeOptions {
@@ -1008,7 +1007,6 @@ index 0000000000..218faa34d2
1008
1007
+ }
1009
1008
+
1010
1009
+ export interface WorkbenchOptions {
1011
- + readonly startPath?: StartPath;
1012
1010
+ readonly workbenchWebConfiguration: {
1013
1011
+ readonly remoteAuthority?: string;
1014
1012
+ readonly folderUri?: UriComponents;
@@ -2181,15 +2179,13 @@ index 0000000000..3c74512192
2181
2179
+ }
2182
2180
diff --git a/src/vs/server/node/server.ts b/src/vs/server/node/server.ts
2183
2181
new file mode 100644
2184
- index 0000000000..5207c90081
2182
+ index 0000000000..81d275a80a
2185
2183
--- /dev/null
2186
2184
+++ b/src/vs/server/node/server.ts
2187
- @@ -0,0 +1,293 @@
2188
- + import * as fs from 'fs-extra';
2185
+ @@ -0,0 +1,253 @@
2189
2186
+ import * as net from 'net';
2190
2187
+ import * as path from 'path';
2191
2188
+ import { Emitter } from 'vs/base/common/event';
2192
- + import { sanitizeFilePath } from 'vs/base/common/extpath';
2193
2189
+ import { Schemas } from 'vs/base/common/network';
2194
2190
+ import { URI } from 'vs/base/common/uri';
2195
2191
+ import { getMachineId } from 'vs/base/node/id';
@@ -2232,12 +2228,10 @@ index 0000000000..5207c90081
2232
2228
+ import { resolveCommonProperties } from 'vs/platform/telemetry/node/commonProperties';
2233
2229
+ import { INodeProxyService, NodeProxyChannel } from 'vs/server/common/nodeProxy';
2234
2230
+ import { TelemetryChannel } from 'vs/server/common/telemetry';
2235
- + import { Query, StartPath, VscodeOptions, WorkbenchOptions } from 'vs/server/ipc';
2231
+ + import { Query, VscodeOptions, WorkbenchOptions } from 'vs/server/ipc';
2236
2232
+ import { ExtensionEnvironmentChannel, FileProviderChannel, NodeProxyService } from 'vs/server/node/channel';
2237
- + import { parseArgs } from 'vs/server/node/cli';
2238
2233
+ import { Connection, ExtensionHostConnection, ManagementConnection } from 'vs/server/node/connection';
2239
2234
+ import { TelemetryClient } from 'vs/server/node/insights';
2240
- + import { logger } from 'vs/server/node/logger';
2241
2235
+ import { getLocaleFromConfig, getNlsConfiguration } from 'vs/server/node/nls';
2242
2236
+ import { Protocol } from 'vs/server/node/protocol';
2243
2237
+ import { getUriTransformer } from 'vs/server/node/util';
@@ -2253,27 +2247,19 @@ index 0000000000..5207c90081
2253
2247
+
2254
2248
+ private readonly services = new ServiceCollection();
2255
2249
+ private servicesPromise?: Promise<void>;
2256
- + private args?: ParsedArgs;
2257
2250
+
2258
2251
+ public async initialize(options: VscodeOptions): Promise<WorkbenchOptions> {
2259
- + if (!this.args) {
2260
- + this.args = parseArgs(options.args || []);
2261
- + }
2262
2252
+ const transformer = getUriTransformer(options.remoteAuthority);
2263
- + const startPath = await this.getFirstValidPath([
2264
- + options.settings.lastVisited,
2265
- + { path: this.args._[0] },
2266
- + ]);
2267
2253
+ if (!this.servicesPromise) {
2268
- + this.servicesPromise = this.initializeServices(this .args);
2254
+ + this.servicesPromise = this.initializeServices(options .args);
2269
2255
+ }
2270
2256
+ await this.servicesPromise;
2271
2257
+ const environment = this.services.get(IEnvironmentService) as IEnvironmentService;
2258
+ + const startPath = options.startPath;
2272
2259
+ return {
2273
- + startPath,
2274
2260
+ workbenchWebConfiguration: {
2275
- + workspaceUri: startPath && startPath.workspace ? transformer.transformOutgoing( URI.file (startPath.path) ) : undefined,
2276
- + folderUri: startPath && !startPath.workspace ? transformer.transformOutgoing( URI.file (startPath.path) ) : undefined,
2261
+ + workspaceUri: startPath && startPath.workspace ? URI.parse (startPath.url ) : undefined,
2262
+ + folderUri: startPath && !startPath.workspace ? URI.parse (startPath.url ) : undefined,
2277
2263
+ remoteAuthority: options.remoteAuthority,
2278
2264
+ logLevel: getLogLevel(environment),
2279
2265
+ },
@@ -2305,34 +2291,6 @@ index 0000000000..5207c90081
2305
2291
+ return true;
2306
2292
+ }
2307
2293
+
2308
- + /**
2309
- + * Choose the first valid path. If `workspace` is undefined then either a
2310
- + * workspace or a directory are acceptable. Otherwise it must be a file if a
2311
- + * workspace or a directory otherwise.
2312
- + */
2313
- + private async getFirstValidPath(startPaths: Array<StartPath | undefined>): Promise<{ path: string, workspace?: boolean} | undefined> {
2314
- + const cwd = process.env.VSCODE_CWD || process.cwd();
2315
- + for (let i = 0; i < startPaths.length; ++i) {
2316
- + const startPath = startPaths[i];
2317
- + if (!startPath) {
2318
- + continue;
2319
- + }
2320
- + const paths = typeof startPath.path === 'string' ? [startPath.path] : (startPath.path || []);
2321
- + for (let j = 0; j < paths.length; ++j) {
2322
- + const p = sanitizeFilePath(paths[j], cwd);
2323
- + try {
2324
- + const stat = await fs.stat(p);
2325
- + if (typeof startPath.workspace === 'undefined' || startPath.workspace !== stat.isDirectory()) {
2326
- + return { path: p, workspace: !stat.isDirectory() };
2327
- + }
2328
- + } catch (error) {
2329
- + logger.warn(error.message);
2330
- + }
2331
- + }
2332
- + }
2333
- + return undefined;
2334
- + }
2335
- +
2336
2294
+ private async connect(message: ConnectionTypeRequest, protocol: Protocol): Promise<void> {
2337
2295
+ if (product.commit && message.commit !== product.commit) {
2338
2296
+ throw new Error(`Version mismatch (${message.commit} instead of ${product.commit})`);
0 commit comments