Skip to content

Commit f3f2e04

Browse files
committed
Flesh out fixes to align with upstream.
1 parent 705e821 commit f3f2e04

File tree

5 files changed

+86
-67
lines changed

5 files changed

+86
-67
lines changed

src/node/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const listen = (server: http.Server, { host, port, socket }: ListenOptions) => {
4444
server.listen(socket, onListen)
4545
} else {
4646
// [] is the correct format when using :: but Node errors with them.
47-
server.listen(port, host.replace(/^\[|\]$/g, ""), onListen)
47+
server.listen(parseInt(port, 10), host.replace(/^\[|\]$/g, ""), onListen)
4848
}
4949
})
5050
}

src/node/cli.ts

Lines changed: 56 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,7 @@ export enum LogLevel {
2929

3030
export class OptionalString extends Optional<string> {}
3131

32-
export interface Args
33-
extends Pick<
34-
CodeServerLib.NativeParsedArgs,
35-
| "_"
36-
| "user-data-dir"
37-
| "enable-proposed-api"
38-
| "extensions-dir"
39-
| "builtin-extensions-dir"
40-
| "extra-extensions-dir"
41-
| "extra-builtin-extensions-dir"
42-
| "ignore-last-opened"
43-
| "locale"
44-
| "log"
45-
| "verbose"
46-
| "install-source"
47-
| "list-extensions"
48-
| "install-extension"
49-
| "uninstall-extension"
50-
| "locate-extension"
51-
// | "telemetry"
52-
> {
32+
export interface Args extends CodeServerLib.ServerParsedArgs {
5333
config?: string
5434
auth?: AuthType
5535
password?: string
@@ -65,7 +45,6 @@ export interface Args
6545
json?: boolean
6646
log?: LogLevel
6747
open?: boolean
68-
port?: number
6948
"bind-addr"?: string
7049
socket?: string
7150
version?: boolean
@@ -74,6 +53,7 @@ export interface Args
7453
"proxy-domain"?: string[]
7554
"reuse-window"?: boolean
7655
"new-window"?: boolean
56+
verbose?: boolean
7757

7858
link?: OptionalString
7959
}
@@ -167,7 +147,7 @@ const options: Options<Required<Args>> = {
167147

168148
// These two have been deprecated by bindAddr.
169149
host: { type: "string", description: "" },
170-
port: { type: "number", description: "" },
150+
port: { type: "string", description: "" },
171151

172152
socket: { type: "string", path: true, description: "Path to a socket (bind-addr will be ignored)." },
173153
version: { type: "boolean", short: "v", description: "Display version information." },
@@ -176,31 +156,18 @@ const options: Options<Required<Args>> = {
176156
"user-data-dir": { type: "string", path: true, description: "Path to the user data directory." },
177157
"extensions-dir": { type: "string", path: true, description: "Path to the extensions directory." },
178158
"builtin-extensions-dir": { type: "string", path: true },
179-
"extra-extensions-dir": { type: "string[]", path: true },
180-
"extra-builtin-extensions-dir": { type: "string[]", path: true },
181159
"list-extensions": { type: "boolean", description: "List installed VS Code extensions." },
182160
force: { type: "boolean", description: "Avoid prompts when installing VS Code extensions." },
183-
"install-source": { type: "string" },
184161
"locate-extension": { type: "string[]" },
185162
"install-extension": {
186163
type: "string[]",
187164
description:
188165
"Install or update a VS Code extension by id or vsix. The identifier of an extension is `${publisher}.${name}`.\n" +
189166
"To install a specific version provide `@${version}`. For example: 'vscode.csharp@1.2.3'.",
190167
},
191-
"enable-proposed-api": {
192-
type: "string[]",
193-
description:
194-
"Enable proposed API features for extensions. Can receive one or more extension IDs to enable individually.",
195-
},
196168
"uninstall-extension": { type: "string[]", description: "Uninstall a VS Code extension by id." },
197169
"show-versions": { type: "boolean", description: "Show VS Code extension versions." },
198170
"proxy-domain": { type: "string[]", description: "Domain used for proxying ports." },
199-
"ignore-last-opened": {
200-
type: "boolean",
201-
short: "e",
202-
description: "Ignore the last opened directory or workspace in favor of an empty window.",
203-
},
204171
"new-window": {
205172
type: "boolean",
206173
short: "n",
@@ -212,7 +179,6 @@ const options: Options<Required<Args>> = {
212179
description: "Force to open a file or folder in an already opened window.",
213180
},
214181

215-
locale: { type: "string" },
216182
log: { type: LogLevel },
217183
verbose: { type: "boolean", short: "vvv", description: "Enable verbose logging." },
218184

@@ -225,6 +191,43 @@ const options: Options<Required<Args>> = {
225191
`,
226192
beta: true,
227193
},
194+
195+
connectionToken: { type: "string" },
196+
"connection-secret": {
197+
type: "string",
198+
description:
199+
"Path to file that contains the connection token. This will require that all incoming connections know the secret.",
200+
},
201+
"socket-path": { type: "string" },
202+
driver: { type: "string" },
203+
"start-server": { type: "boolean" },
204+
"print-startup-performance": { type: "boolean" },
205+
"print-ip-address": { type: "boolean" },
206+
"disable-websocket-compression": { type: "boolean" },
207+
208+
fileWatcherPolling: { type: "string" },
209+
210+
"enable-remote-auto-shutdown": { type: "boolean" },
211+
"remote-auto-shutdown-without-delay": { type: "boolean" },
212+
213+
"without-browser-env-var": { type: "boolean" },
214+
"extensions-download-dir": { type: "string" },
215+
"install-builtin-extension": { type: "string[]" },
216+
217+
category: {
218+
type: "string",
219+
description: "Filters installed extensions by provided category, when using --list-extensions.",
220+
},
221+
"do-not-sync": { type: "boolean" },
222+
"force-disable-user-env": { type: "boolean" },
223+
224+
folder: { type: "string" },
225+
workspace: { type: "string" },
226+
"web-user-data-dir": { type: "string" },
227+
"use-host-proxy": { type: "string" },
228+
"enable-sync": { type: "boolean" },
229+
"github-auth": { type: "string" },
230+
logsPath: { type: "string" },
228231
}
229232

230233
export const optionDescriptions = (): string[] => {
@@ -269,6 +272,14 @@ export function splitOnFirstEquals(str: string): string[] {
269272
return split
270273
}
271274

275+
const createDefaultArgs = (): Args => {
276+
return {
277+
_: [],
278+
workspace: "",
279+
folder: "",
280+
}
281+
}
282+
272283
export const parse = (
273284
argv: string[],
274285
opts?: {
@@ -283,7 +294,8 @@ export const parse = (
283294
return new Error(msg)
284295
}
285296

286-
const args: Args = { _: [] }
297+
// TODO: parse workspace and folder.
298+
const args: Args = createDefaultArgs()
287299
let ended = false
288300

289301
for (let i = 0; i < argv.length; ++i) {
@@ -401,7 +413,7 @@ export interface DefaultedArgs extends ConfigArgs {
401413
value: string
402414
}
403415
host: string
404-
port: number
416+
port: string
405417
"proxy-domain": string[]
406418
verbose: boolean
407419
usingEnvPassword: boolean
@@ -470,15 +482,15 @@ export async function setDefaults(cliArgs: Args, configArgs?: ConfigArgs): Promi
470482
args.auth = AuthType.Password
471483
}
472484

473-
const addr = bindAddrFromAllSources(configArgs || { _: [] }, cliArgs)
485+
const addr = bindAddrFromAllSources(configArgs || createDefaultArgs(), cliArgs)
474486
args.host = addr.host
475-
args.port = addr.port
487+
args.port = addr.port.toString()
476488

477489
// If we're being exposed to the cloud, we listen on a random address and
478490
// disable auth.
479491
if (args.link) {
480492
args.host = "localhost"
481-
args.port = 0
493+
args.port = "0"
482494
args.socket = undefined
483495
args.cert = undefined
484496
args.auth = AuthType.None
@@ -579,7 +591,7 @@ export async function readConfigFile(configPath?: string): Promise<ConfigArgs> {
579591
*/
580592
export function parseConfigFile(configFile: string, configPath: string): ConfigArgs {
581593
if (!configFile) {
582-
return { _: [], config: configPath }
594+
return { ...createDefaultArgs(), config: configPath }
583595
}
584596

585597
const config = yaml.load(configFile, {
@@ -639,7 +651,7 @@ export function bindAddrFromArgs(addr: Addr, args: Args): Addr {
639651
addr.port = parseInt(process.env.PORT, 10)
640652
}
641653
if (args.port !== undefined) {
642-
addr.port = args.port
654+
addr.port = parseInt(args.port, 10)
643655
}
644656
return addr
645657
}

src/node/main.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import { startLink } from "./link"
1212
import { register } from "./routes"
1313
import { humanPath, isFile, loadAMDModule, open } from "./util"
1414

15-
export const shouldSpawnCliProcess = async (args: CodeServerLib.NativeParsedArgs): Promise<boolean> => {
16-
const shouldSpawn = await loadAMDModule<(argv: CodeServerLib.NativeParsedArgs) => boolean>(
17-
"vs/code/node/cli",
18-
"shouldSpawnCliProcess",
15+
export const shouldSpawnCliProcess = async (args: CodeServerLib.ServerParsedArgs): Promise<boolean> => {
16+
return (
17+
!args["start-server"] &&
18+
(!!args["list-extensions"] ||
19+
!!args["install-extension"] ||
20+
!!args["install-builtin-extension"] ||
21+
!!args["uninstall-extension"] ||
22+
!!args["locate-extension"])
1923
)
20-
21-
return shouldSpawn(args)
2224
}
2325

2426
/**

src/node/routes/vscode.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as express from "express"
22
import path from "path"
3-
import { AuthType, DefaultedArgs } from "../cli"
4-
import { version as codeServerVersion, vsRootPath } from "../constants"
3+
import { DefaultedArgs } from "../cli"
4+
import { vsRootPath } from "../constants"
55
import { ensureAuthenticated, authenticated, redirect } from "../http"
66
import { loadAMDModule } from "../util"
77
import { Router as WsRouter, WebsocketRouter } from "../wsRouter"
@@ -10,7 +10,7 @@ import { errorHandler } from "./errors"
1010
export interface VSServerResult {
1111
router: express.Router
1212
wsRouter: WebsocketRouter
13-
codeServerMain: CodeServerLib.IServerProcessMain
13+
codeServerMain: CodeServerLib.IServerAPI
1414
}
1515

1616
export const createVSServerRouter = async (args: DefaultedArgs): Promise<VSServerResult> => {
@@ -37,19 +37,15 @@ export const createVSServerRouter = async (args: DefaultedArgs): Promise<VSServe
3737

3838
// Signal processes that we got launched as CLI
3939
process.env["VSCODE_CLI"] = "1"
40+
// Seems to be necessary to load modules properly.
41+
process.env["VSCODE_DEV"] = "1"
4042

41-
const createVSServer = await loadAMDModule<CodeServerLib.CreateVSServer>("vs/server/entry", "createVSServer")
43+
const createVSServer = await loadAMDModule<CodeServerLib.CreateServer>(
44+
"vs/server/remoteExtensionHostAgentServer",
45+
"createServer",
46+
)
4247

43-
const serverUrl = new URL(`${args.cert ? "https" : "http"}://${args.host}:${args.port}`)
44-
const codeServerMain = await createVSServer({
45-
codeServerVersion,
46-
serverUrl,
47-
args,
48-
authed: args.auth !== AuthType.None,
49-
disableUpdateCheck: !!args["disable-update-check"],
50-
})
51-
52-
const netServer = await codeServerMain.startup({ listenWhenReady: false })
48+
const codeServerMain = await createVSServer(null, { ...args, connectionToken: "0000" }, args["user-data-dir"])
5349

5450
const router = express.Router()
5551
const wsRouter = WsRouter()
@@ -68,11 +64,12 @@ export const createVSServerRouter = async (args: DefaultedArgs): Promise<VSServe
6864
router.all("*", ensureAuthenticated, (req, res, next) => {
6965
req.on("error", (error) => errorHandler(error, req, res, next))
7066

71-
netServer.emit("request", req, res)
67+
codeServerMain.handleRequest(req, res)
7268
})
7369

7470
wsRouter.ws("/", ensureAuthenticated, (req) => {
75-
netServer.emit("upgrade", req, req.socket, req.head)
71+
codeServerMain.handleUpgrade(req, req.socket)
72+
// netServer.emit("upgrade", req, req.socket, req.head)
7673

7774
req.socket.resume()
7875
})

src/node/util.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,14 @@ type AMDModule<T> = { [exportName: string]: T }
506506
* @param exportName Given name of export in the file
507507
*/
508508
export const loadAMDModule = async <T>(amdPath: string, exportName: string): Promise<T> => {
509+
// Set default remote native node modules path, if unset
510+
process.env["VSCODE_INJECT_NODE_MODULE_LOOKUP_PATH"] =
511+
process.env["VSCODE_INJECT_NODE_MODULE_LOOKUP_PATH"] || path.join(vsRootPath, "remote", "node_modules")
512+
513+
require(path.join(vsRootPath, "out/bootstrap-node")).injectNodeModuleLookupPath(
514+
process.env["VSCODE_INJECT_NODE_MODULE_LOOKUP_PATH"],
515+
)
516+
509517
const module = await new Promise<AMDModule<T>>((resolve, reject) => {
510518
require(path.join(vsRootPath, "out/bootstrap-amd")).load(amdPath, resolve, reject)
511519
})

0 commit comments

Comments
 (0)