Skip to content

Commit 41a9313

Browse files
committed
feat(vscode): redirect to folder from cli
1 parent f74cba7 commit 41a9313

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

src/node/cli.ts

+2-10
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,7 @@ import { promises as fs } from "fs"
33
import yaml from "js-yaml"
44
import * as os from "os"
55
import * as path from "path"
6-
import {
7-
canConnect,
8-
generateCertificate,
9-
generatePassword,
10-
humanPath,
11-
paths,
12-
isNodeJSErrnoException,
13-
isFile,
14-
} from "./util"
6+
import { canConnect, generateCertificate, generatePassword, humanPath, paths, isNodeJSErrnoException } from "./util"
157

168
const DEFAULT_SOCKET_PATH = path.join(os.tmpdir(), "vscode-ipc")
179

@@ -434,7 +426,7 @@ export interface DefaultedArgs extends ConfigArgs {
434426
"extensions-dir": string
435427
"user-data-dir": string
436428
/* Positional arguments. */
437-
_: []
429+
_: string[] | []
438430
}
439431

440432
/**

src/node/routes/vscode.ts

+16
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ export class CodeServerRouteWrapper {
3434
}
3535

3636
const { query } = await req.settings.read()
37+
38+
if (!query && req.args["_"].length > 0) {
39+
// TODO@jsjoeio - we alos need to check for workspace arg
40+
const folder = req.args["_"][0]
41+
42+
await req.settings.write({
43+
query: {
44+
folder,
45+
},
46+
})
47+
48+
const to = self(req)
49+
return redirect(req, res, to, {
50+
folder,
51+
})
52+
}
3753
if (query) {
3854
// Ew means the workspace was closed so clear the last folder/workspace.
3955
if (req.query.ew) {

test/unit/node/routes/vscode.test.ts

+14
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,20 @@ describe("vscode", () => {
136136
await resp.text()
137137
})
138138

139+
it.only("should add the folder as a query param maintaining the slashes", async () => {
140+
const folder = await tmpdir(testName)
141+
codeServer = await integration.setup(["--auth=none", folder], "")
142+
143+
let resp = await codeServer.fetch("/", undefined)
144+
145+
expect(resp.status).toBe(200)
146+
const url = new URL(resp.url)
147+
expect(url.search).toBe(`?folder=${folder}`)
148+
await resp.text()
149+
})
150+
151+
// TODO@jsjoeio - what about workspace?
152+
139153
it("should not redirect when last opened is ignored", async () => {
140154
codeServer = await integration.setup(["--auth=none", "--ignore-last-opened"], "")
141155

0 commit comments

Comments
 (0)