MCPcopy Index your code
hub / github.com/coder/code-server / loadVSCode

Function loadVSCode

src/node/routes/vscode.ts:55–76  ·  view source on GitHub ↗

* Load then create the VS Code server.

(req: express.Request)

Source from the content-addressed store, hash-verified

53 * Load then create the VS Code server.
54 */
55async function loadVSCode(req: express.Request): Promise<IVSCodeServerAPI> {
56 // Since server-main.js is an ES module, we have to use `import`. However,
57 // tsc will transpile this to `require` unless we change our module type,
58 // which will also require that we switch to ESM, since a hybrid approach
59 // breaks importing `rotating-file-stream` for some reason. To work around
60 // this, use `eval` for now, but we should consider switching to ESM.
61 let modPath = path.join(vsRootPath, "out/server-main.js")
62 if (os.platform() === "win32") {
63 // On Windows, absolute paths of ESM modules must be a valid file URI.
64 modPath = "file:///" + modPath.replace(/\\/g, "/")
65 }
66 const mod = (await eval(`import("${modPath}")`)) as VSCodeModule
67 const serverModule = await mod.loadCodeWithNls()
68 return serverModule.createServer(null, {
69 ...(await toCodeArgs(req.args)),
70 "accept-server-license-terms": true,
71 // This seems to be used to make the connection token flags optional (when
72 // set to 1.63) but we have always included them.
73 compatibility: "1.64",
74 "without-connection-token": true,
75 })
76}
77
78// To prevent loading the module more than once at a time. We also have the
79// resolved value so you do not need to `await` everywhere.

Callers 1

ensureVSCodeLoadedFunction · 0.85

Calls 1

toCodeArgsFunction · 0.90

Tested by

no test coverage detected