Skip to content

Commit 974d4cb

Browse files
committedApr 16, 2020
Allow specifying a workspace on the command line
Fixes #1535.
1 parent 29b6115 commit 974d4cb

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed
 

‎doc/FAQ.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ code-server tries the following in order:
139139

140140
1. The `workspace` query parameter.
141141
2. The `folder` query parameter.
142-
3. The directory passed on the command line.
143-
4. The last opened workspace or folder.
142+
3. The workspace or directory passed on the command line.
143+
4. The last opened workspace or directory.
144144

145145
## Enterprise
146146

‎src/node/app/vscode.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { field, logger } from "@coder/logger"
22
import * as cp from "child_process"
33
import * as crypto from "crypto"
4+
import * as fs from "fs-extra"
45
import * as http from "http"
56
import * as net from "net"
67
import * as path from "path"
@@ -209,14 +210,26 @@ export class VscodeHttpProvider extends HttpProvider {
209210
private async getFirstPath(
210211
startPaths: Array<{ url?: string | string[]; workspace?: boolean } | undefined>,
211212
): Promise<StartPath | undefined> {
213+
const isFile = async (path: string): Promise<boolean> => {
214+
try {
215+
const stat = await fs.stat(path)
216+
return stat.isFile()
217+
} catch (error) {
218+
logger.warn(error.message)
219+
return false
220+
}
221+
}
212222
for (let i = 0; i < startPaths.length; ++i) {
213223
const startPath = startPaths[i]
214224
const url =
215225
startPath && (typeof startPath.url === "string" ? [startPath.url] : startPath.url || []).find((p) => !!p)
216226
if (startPath && url) {
217227
return {
218228
url,
219-
workspace: !!startPath.workspace,
229+
// The only time `workspace` is undefined is for the command-line
230+
// argument, in which case it's a path (not a URL) so we can stat it
231+
// without having to parse it.
232+
workspace: typeof startPath.workspace !== "undefined" ? startPath.workspace : await isFile(url),
220233
}
221234
}
222235
}

0 commit comments

Comments
 (0)
Please sign in to comment.