@@ -852,7 +852,7 @@ index 0000000000..eb62b87798
852852+ }
853853diff --git a/src/vs/server/entry.ts b/src/vs/server/entry.ts
854854new file mode 100644
855- index 0000000000..cb606e6a68
855+ index 0000000000..9995e9f7fc
856856--- /dev/null
857857+++ b/src/vs/server/entry.ts
858858@@ -0,0 +1,67 @@
@@ -897,8 +897,8 @@ index 0000000000..cb606e6a68
897897+ process.send(message);
898898+ };
899899+
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.
902902+ process.on('message', async (message: CodeServerMessage, socket) => {
903903+ logger.debug('got message from code-server', field('message', message));
904904+ switch (message.type) {
@@ -934,10 +934,10 @@ index 0000000000..56331ff1fc
934934+ require('../../bootstrap-amd').load('vs/server/entry');
935935diff --git a/src/vs/server/ipc.d.ts b/src/vs/server/ipc.d.ts
936936new file mode 100644
937- index 0000000000..218faa34d2
937+ index 0000000000..3bfef75d81
938938--- /dev/null
939939+++ b/src/vs/server/ipc.d.ts
940- @@ -0,0 +1,93 @@
940+ @@ -0,0 +1,91 @@
941941+ /**
942942+ * External interfaces for integration into code-server over IPC. No vs imports
943943+ * should be made in this file.
@@ -971,19 +971,18 @@ index 0000000000..218faa34d2
971971+ export type VscodeMessage = ReadyMessage | OptionsMessage;
972972+
973973+ export interface StartPath {
974- + path?: string[] | string;
975- + workspace? : boolean;
974+ + url: string;
975+ + workspace: boolean;
976976+ }
977977+
978- + export interface Settings {
979- + lastVisited?: StartPath ;
978+ + export interface Args {
979+ + _: string[] ;
980980+ }
981981+
982982+ export interface VscodeOptions {
983983+ readonly remoteAuthority: string;
984- + readonly query: Query;
985- + readonly args?: string[];
986- + readonly settings: Settings;
984+ + readonly args: Args;
985+ + readonly startPath?: StartPath;
987986+ }
988987+
989988+ export interface VscodeOptionsMessage extends VscodeOptions {
@@ -1008,7 +1007,6 @@ index 0000000000..218faa34d2
10081007+ }
10091008+
10101009+ export interface WorkbenchOptions {
1011- + readonly startPath?: StartPath;
10121010+ readonly workbenchWebConfiguration: {
10131011+ readonly remoteAuthority?: string;
10141012+ readonly folderUri?: UriComponents;
@@ -2181,15 +2179,13 @@ index 0000000000..3c74512192
21812179+ }
21822180diff --git a/src/vs/server/node/server.ts b/src/vs/server/node/server.ts
21832181new file mode 100644
2184- index 0000000000..5207c90081
2182+ index 0000000000..81d275a80a
21852183--- /dev/null
21862184+++ b/src/vs/server/node/server.ts
2187- @@ -0,0 +1,293 @@
2188- + import * as fs from 'fs-extra';
2185+ @@ -0,0 +1,253 @@
21892186+ import * as net from 'net';
21902187+ import * as path from 'path';
21912188+ import { Emitter } from 'vs/base/common/event';
2192- + import { sanitizeFilePath } from 'vs/base/common/extpath';
21932189+ import { Schemas } from 'vs/base/common/network';
21942190+ import { URI } from 'vs/base/common/uri';
21952191+ import { getMachineId } from 'vs/base/node/id';
@@ -2232,12 +2228,10 @@ index 0000000000..5207c90081
22322228+ import { resolveCommonProperties } from 'vs/platform/telemetry/node/commonProperties';
22332229+ import { INodeProxyService, NodeProxyChannel } from 'vs/server/common/nodeProxy';
22342230+ 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';
22362232+ import { ExtensionEnvironmentChannel, FileProviderChannel, NodeProxyService } from 'vs/server/node/channel';
2237- + import { parseArgs } from 'vs/server/node/cli';
22382233+ import { Connection, ExtensionHostConnection, ManagementConnection } from 'vs/server/node/connection';
22392234+ import { TelemetryClient } from 'vs/server/node/insights';
2240- + import { logger } from 'vs/server/node/logger';
22412235+ import { getLocaleFromConfig, getNlsConfiguration } from 'vs/server/node/nls';
22422236+ import { Protocol } from 'vs/server/node/protocol';
22432237+ import { getUriTransformer } from 'vs/server/node/util';
@@ -2253,27 +2247,19 @@ index 0000000000..5207c90081
22532247+
22542248+ private readonly services = new ServiceCollection();
22552249+ private servicesPromise?: Promise<void>;
2256- + private args?: ParsedArgs;
22572250+
22582251+ public async initialize(options: VscodeOptions): Promise<WorkbenchOptions> {
2259- + if (!this.args) {
2260- + this.args = parseArgs(options.args || []);
2261- + }
22622252+ const transformer = getUriTransformer(options.remoteAuthority);
2263- + const startPath = await this.getFirstValidPath([
2264- + options.settings.lastVisited,
2265- + { path: this.args._[0] },
2266- + ]);
22672253+ if (!this.servicesPromise) {
2268- + this.servicesPromise = this.initializeServices(this .args);
2254+ + this.servicesPromise = this.initializeServices(options .args);
22692255+ }
22702256+ await this.servicesPromise;
22712257+ const environment = this.services.get(IEnvironmentService) as IEnvironmentService;
2258+ + const startPath = options.startPath;
22722259+ return {
2273- + startPath,
22742260+ 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,
22772263+ remoteAuthority: options.remoteAuthority,
22782264+ logLevel: getLogLevel(environment),
22792265+ },
@@ -2305,34 +2291,6 @@ index 0000000000..5207c90081
23052291+ return true;
23062292+ }
23072293+
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- +
23362294+ private async connect(message: ConnectionTypeRequest, protocol: Protocol): Promise<void> {
23372295+ if (product.commit && message.commit !== product.commit) {
23382296+ throw new Error(`Version mismatch (${message.commit} instead of ${product.commit})`);
0 commit comments