@@ -26,6 +26,7 @@ export class CodeServerRouteWrapper {
26
26
27
27
private $root : express . Handler = async ( req , res , next ) => {
28
28
const isAuthenticated = await authenticated ( req )
29
+ const NO_FOLDER_OR_WORKSPACE_QUERY = ! req . query . folder && ! req . query . workspace
29
30
30
31
if ( ! isAuthenticated ) {
31
32
const to = self ( req )
@@ -34,30 +35,35 @@ export class CodeServerRouteWrapper {
34
35
} )
35
36
}
36
37
37
- if ( ! req . query . folder && ! req . query . workspace ) {
38
+ if ( NO_FOLDER_OR_WORKSPACE_QUERY ) {
38
39
const settings = await req . settings . read ( )
39
40
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
43
+ // This flag disables the last opened behavior
44
+ const IGNORE_LAST_OPENED = req . args [ "ignore-last-opened" ]
45
+ const HAS_LAST_OPENED_FOLDER_OR_WORKSPACE = lastOpened . folder || lastOpened . workspace
46
+ const HAS_FOLDER_OR_WORKSPACE_FROM_CLI = req . args . _ . length > 0
47
+ const to = self ( req )
48
+
40
49
let folder = undefined
41
50
let workspace = undefined
42
- const to = self ( req )
43
51
44
- // Ew means the workspace was closed so clear the last folder/workspace.
45
- if ( req . query . ew ) {
52
+ if ( HAS_EW_QUERY ) {
46
53
delete lastOpened . folder
47
54
delete lastOpened . workspace
48
55
}
49
56
50
57
// Redirect to the last folder/workspace if nothing else is opened.
51
- if (
52
- ( lastOpened . folder || lastOpened . workspace ) &&
53
- ! req . args [ "ignore-last-opened" ] // This flag disables this behavior.
54
- ) {
58
+ if ( HAS_LAST_OPENED_FOLDER_OR_WORKSPACE && ! IGNORE_LAST_OPENED ) {
55
59
folder = lastOpened . folder
56
60
workspace = lastOpened . workspace
57
- } else if ( req . args . _ . length > 0 ) {
61
+ } else if ( HAS_FOLDER_OR_WORKSPACE_FROM_CLI ) {
58
62
const lastEntry = path . resolve ( req . args . _ [ req . args . _ . length - 1 ] )
59
63
const entryIsFile = await isFile ( lastEntry )
60
- if ( entryIsFile && path . extname ( lastEntry ) === ".code-workspace" ) {
64
+ const IS_WORKSPACE_FILE = entryIsFile && path . extname ( lastEntry ) === ".code-workspace"
65
+
66
+ if ( IS_WORKSPACE_FILE ) {
61
67
workspace = lastEntry
62
68
} else if ( ! entryIsFile ) {
63
69
folder = lastEntry
0 commit comments