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

Function runCodeCli

src/node/main.ts:52–76  ·  view source on GitHub ↗
(args: DefaultedArgs)

Source from the content-addressed store, hash-verified

50 * Run Code's CLI for things like managing extensions.
51 */
52export const runCodeCli = async (args: DefaultedArgs): Promise<void> => {
53 logger.debug("Running Code CLI")
54 try {
55 // See vscode.loadVSCode for more on this jank.
56 process.env.CODE_SERVER_PARENT_PID = process.pid.toString()
57 let modPath = path.join(vsRootPath, "out/server-main.js")
58 if (os.platform() === "win32") {
59 // On Windows, absolute paths of ESM modules must be a valid file URI.
60 modPath = "file:///" + modPath.replace(/\\/g, "/")
61 }
62 const mod = (await eval(`import("${modPath}")`)) as VSCodeModule
63 const serverModule = await mod.loadCodeWithNls()
64 await serverModule.spawnCli(await toCodeArgs(args))
65 // Rather than have the caller handle errors and exit, spawnCli will exit
66 // itself. Additionally, it does this on a timeout set to 0. So, try
67 // waiting for VS Code to exit before giving up and doing it ourselves.
68 await new Promise((r) => setTimeout(r, 1000))
69 logger.warn("Code never exited")
70 process.exit(0)
71 } catch (error: any) {
72 // spawnCli catches all errors, but just in case that changes.
73 logger.error("Got error from Code", error)
74 process.exit(1)
75 }
76}
77
78export const openInExistingInstance = async (args: DefaultedArgs, socketPath: string): Promise<void> => {
79 const pipeArgs: OpenCommandPipeArgs & { fileURIs: string[] } = {

Callers 1

entryFunction · 0.90

Calls 1

toCodeArgsFunction · 0.90

Tested by

no test coverage detected