|
1 | 1 | import { field, logger } from "@coder/logger"
|
2 | 2 | import * as cp from "child_process"
|
| 3 | +import { promises as fs } from "fs" |
| 4 | +import http from "http" |
3 | 5 | import * as path from "path"
|
4 |
| -import { CliMessage } from "../../lib/vscode/src/vs/server/ipc" |
5 |
| -import { plural } from "../common/util" |
| 6 | +import { CliMessage, OpenCommandPipeArgs } from "../../lib/vscode/src/vs/server/ipc" |
6 | 7 | import { LoginHttpProvider } from "./app/login"
|
7 | 8 | import { ProxyHttpProvider } from "./app/proxy"
|
8 | 9 | import { StaticHttpProvider } from "./app/static"
|
@@ -63,9 +64,9 @@ const main = async (args: Args, cliArgs: Args, configArgs: Args): Promise<void>
|
63 | 64 | ...(args.cert && !args.cert.value
|
64 | 65 | ? await generateCertificate()
|
65 | 66 | : {
|
66 |
| - cert: args.cert && args.cert.value, |
67 |
| - certKey: args["cert-key"], |
68 |
| - }), |
| 67 | + cert: args.cert && args.cert.value, |
| 68 | + certKey: args["cert-key"], |
| 69 | + }), |
69 | 70 | }
|
70 | 71 |
|
71 | 72 | if (options.cert && !options.certKey) {
|
@@ -162,6 +163,49 @@ async function entry(): Promise<void> {
|
162 | 163 | console.log(version, commit)
|
163 | 164 | }
|
164 | 165 | process.exit(0)
|
| 166 | + } else if (args["open-in"]) { |
| 167 | + if (!process.env["VSCODE_IPC_HOOK_CLI"]) { |
| 168 | + logger.error("VSCODE_IPC_HOOK_CLI missing from environment, unable to run") |
| 169 | + process.exit(1) |
| 170 | + } |
| 171 | + const pipeArgs: OpenCommandPipeArgs = { type: "open", folderURIs: [] } |
| 172 | + pipeArgs.forceReuseWindow = args["reuse-window"] |
| 173 | + pipeArgs.forceNewWindow = args["new-window"] |
| 174 | + for (const a in args._) { |
| 175 | + if (Object.prototype.hasOwnProperty.call(args._, a)) { |
| 176 | + try { |
| 177 | + const fp = await fs.realpath(args._[a]) |
| 178 | + const st = await fs.stat(fp) |
| 179 | + if (st.isDirectory()) { |
| 180 | + pipeArgs.folderURIs = [...pipeArgs.folderURIs, fp] |
| 181 | + } else { |
| 182 | + pipeArgs.fileURIs = [...(pipeArgs.fileURIs || []), fp] |
| 183 | + } |
| 184 | + } catch (error) { |
| 185 | + pipeArgs.fileURIs = [...(pipeArgs.fileURIs || []), args._[a]] |
| 186 | + } |
| 187 | + } |
| 188 | + } |
| 189 | + if (pipeArgs.forceNewWindow && pipeArgs.fileURIs && pipeArgs.fileURIs.length > 0) { |
| 190 | + logger.error("new-window can only be used with folder paths") |
| 191 | + process.exit(1) |
| 192 | + } |
| 193 | + const vscode = http.request({ |
| 194 | + path: "/", |
| 195 | + method: "POST", |
| 196 | + socketPath: process.env["VSCODE_IPC_HOOK_CLI"], |
| 197 | + }, |
| 198 | + (res) => { |
| 199 | + res.on("data", (message) => { |
| 200 | + logger.debug("Got message from VS Code", field("message", message.toString())) |
| 201 | + }) |
| 202 | + }, |
| 203 | + ) |
| 204 | + vscode.on("error", (err) => { |
| 205 | + logger.debug("Got error from VS Code", field("error", err)) |
| 206 | + }) |
| 207 | + vscode.write(JSON.stringify(pipeArgs)) |
| 208 | + vscode.end() |
165 | 209 | } else if (args["list-extensions"] || args["install-extension"] || args["uninstall-extension"]) {
|
166 | 210 | logger.debug("forking vs code cli...")
|
167 | 211 | const vscode = cp.fork(path.resolve(__dirname, "../../lib/vscode/out/vs/server/fork"), [], {
|
|
0 commit comments