Skip to content

Commit 92865f2

Browse files
committed
Implement last opened functionality
Fixes coder#4619
1 parent 73e0b79 commit 92865f2

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ implementation (#4414).
3838
vscode-remote-resource endpoint still can.
3939
- OpenVSX has been made the default marketplace. However this means web
4040
extensions like Vim may be broken.
41+
- The last opened folder/workspace is no longer stored separately in the
42+
settings file (we rely on the already-existing query object instead).
4143

4244
### Deprecated
4345

src/node/routes/vscode.ts

+25
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { WebsocketRequest } from "../../../typings/pluginapi"
44
import { logError } from "../../common/util"
55
import { isDevMode } from "../constants"
66
import { toVsCodeArgs } from "../cli"
7+
import { settings } from "../settings"
78
import { ensureAuthenticated, authenticated, redirect } from "../http"
89
import { loadAMDModule, readCompilationStats } from "../util"
910
import { Router as WsRouter } from "../wsRouter"
@@ -31,6 +32,30 @@ export class CodeServerRouteWrapper {
3132
})
3233
}
3334

35+
// Ew means the workspace was closed so clear the last folder/workspace.
36+
const { query } = await settings.read()
37+
if (req.query.ew) {
38+
delete query.folder
39+
delete query.workspace
40+
}
41+
42+
// Redirect to the last folder/workspace if nothing else is opened.
43+
if (
44+
!req.query.folder &&
45+
!req.query.workspace &&
46+
(query.folder || query.workspace) &&
47+
!req.args["ignore-last-opened"] // This flag disables this behavior.
48+
) {
49+
return redirect(req, res, "", {
50+
folder: query.folder,
51+
workspace: query.workspace,
52+
})
53+
}
54+
55+
// Store the query parameters so we can use them on the next load. This
56+
// also allows users to create functionality around query parameters.
57+
settings.write({ query: req.query })
58+
3459
next()
3560
}
3661

0 commit comments

Comments
 (0)