未验证 提交 974d4cb8 编写于 作者: A Asher

Allow specifying a workspace on the command line

Fixes #1535.
上级 29b6115c
......@@ -139,8 +139,8 @@ code-server tries the following in order:
1. The `workspace` query parameter.
2. The `folder` query parameter.
3. The directory passed on the command line.
4. The last opened workspace or folder.
3. The workspace or directory passed on the command line.
4. The last opened workspace or directory.
## Enterprise
......
import { field, logger } from "@coder/logger"
import * as cp from "child_process"
import * as crypto from "crypto"
import * as fs from "fs-extra"
import * as http from "http"
import * as net from "net"
import * as path from "path"
......@@ -209,6 +210,15 @@ export class VscodeHttpProvider extends HttpProvider {
private async getFirstPath(
startPaths: Array<{ url?: string | string[]; workspace?: boolean } | undefined>,
): Promise<StartPath | undefined> {
const isFile = async (path: string): Promise<boolean> => {
try {
const stat = await fs.stat(path)
return stat.isFile()
} catch (error) {
logger.warn(error.message)
return false
}
}
for (let i = 0; i < startPaths.length; ++i) {
const startPath = startPaths[i]
const url =
......@@ -216,7 +226,10 @@ export class VscodeHttpProvider extends HttpProvider {
if (startPath && url) {
return {
url,
workspace: !!startPath.workspace,
// The only time `workspace` is undefined is for the command-line
// argument, in which case it's a path (not a URL) so we can stat it
// without having to parse it.
workspace: typeof startPath.workspace !== "undefined" ? startPath.workspace : await isFile(url),
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册