diff --git a/doc/FAQ.md b/doc/FAQ.md index 0aff1886..e44f698c 100644 --- a/doc/FAQ.md +++ b/doc/FAQ.md @@ -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 diff --git a/src/node/app/vscode.ts b/src/node/app/vscode.ts index ece990dc..9ecdcd80 100644 --- a/src/node/app/vscode.ts +++ b/src/node/app/vscode.ts @@ -1,6 +1,7 @@ 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 { + const isFile = async (path: string): Promise => { + 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), } } }