Skip to content

Commit 02ed52c

Browse files
committed
fixup!: fix broken tests and clean up logic
1 parent 36183d9 commit 02ed52c

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/node/routes/vscode.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export class CodeServerRouteWrapper {
2727
private $root: express.Handler = async (req, res, next) => {
2828
const isAuthenticated = await authenticated(req)
2929
const NO_FOLDER_OR_WORKSPACE_QUERY = !req.query.folder && !req.query.workspace
30+
// Ew means the workspace was closed so clear the last folder/workspace.
31+
const WORKSPACE_WAS_CLOSED = req.query.ew
3032

3133
if (!isAuthenticated) {
3234
const to = self(req)
@@ -35,21 +37,19 @@ export class CodeServerRouteWrapper {
3537
})
3638
}
3739

38-
if (NO_FOLDER_OR_WORKSPACE_QUERY) {
40+
if (NO_FOLDER_OR_WORKSPACE_QUERY && !WORKSPACE_WAS_CLOSED) {
3941
const settings = await req.settings.read()
4042
const lastOpened = settings.query || {}
41-
// Ew means the workspace was closed so clear the last folder/workspace.
42-
const HAS_EW_QUERY = req.query.ew
4343
// This flag disables the last opened behavior
4444
const IGNORE_LAST_OPENED = req.args["ignore-last-opened"]
45-
const HAS_LAST_OPENED_FOLDER_OR_WORKSPACE = lastOpened.folder || lastOpened.workspace
45+
const HAS_LAST_OPENED_FOLDER_OR_WORKSPACE = (!WORKSPACE_WAS_CLOSED && lastOpened.folder) || lastOpened.workspace
4646
const HAS_FOLDER_OR_WORKSPACE_FROM_CLI = req.args._.length > 0
4747
const to = self(req)
4848

4949
let folder = undefined
5050
let workspace = undefined
5151

52-
if (HAS_EW_QUERY) {
52+
if (WORKSPACE_WAS_CLOSED) {
5353
delete lastOpened.folder
5454
delete lastOpened.workspace
5555
}
@@ -69,10 +69,13 @@ export class CodeServerRouteWrapper {
6969
folder = lastEntry
7070
}
7171
}
72-
return redirect(req, res, to, {
73-
folder,
74-
workspace,
75-
})
72+
73+
if (folder || workspace) {
74+
return redirect(req, res, to, {
75+
folder,
76+
workspace,
77+
})
78+
}
7679
}
7780

7881
// Store the query parameters so we can use them on the next load. This

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

+3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ describe("vscode", () => {
6868

6969
const folder = await tmpdir(testName)
7070
const workspace = path.join(await tmpdir(testName), "test.code-workspace")
71+
await fs.writeFile(workspace, "")
7172
let resp = await codeServer.fetch("/", undefined, {
7273
folder,
7374
workspace,
@@ -115,6 +116,8 @@ describe("vscode", () => {
115116

116117
const folder = await tmpdir(testName)
117118
const workspace = path.join(await tmpdir(testName), "test.code-workspace")
119+
await fs.writeFile(workspace, "")
120+
118121
let resp = await codeServer.fetch("/", undefined, {
119122
folder,
120123
workspace,

0 commit comments

Comments
 (0)