@@ -152,37 +152,47 @@ export class Commands {
152
152
153
153
// A workspace can have multiple agents, but that's handled
154
154
// when opening a workspace unless explicitly specified.
155
- let uri = vscode . Uri . parse ( `vscode-remote:// ssh-remote+${ Remote . Prefix } ${ workspaceOwner } --${ workspaceName } /` )
155
+ const remoteAuthority = ` ssh-remote+${ Remote . Prefix } ${ workspaceOwner } --${ workspaceName } `
156
156
157
157
const output : {
158
158
workspaces : { folderUri : vscode . Uri ; remoteAuthority : string } [ ]
159
159
} = await vscode . commands . executeCommand ( "_workbench.getRecentlyOpened" )
160
160
const opened = output . workspaces . filter (
161
161
// Filter out `/` since that's added below.
162
- ( opened ) => opened . folderUri ?. authority === uri . authority && uri . path !== "/" ,
162
+ ( opened ) => opened . folderUri ?. authority === remoteAuthority ,
163
163
)
164
- // Always add `/` as an option to open. If we don't, it can become hard
165
- // to open multiple VS Code windows.
166
- opened . splice ( 0 , 0 , {
167
- folderUri : uri ,
168
- remoteAuthority : "coder" ,
169
- } )
170
- if ( opened . length > 1 ) {
171
- const items : vscode . QuickPickItem [ ] = opened . map ( ( folder ) : vscode . QuickPickItem => {
172
- return {
173
- label : folder . folderUri . fsPath ,
164
+ if ( opened . length > 0 ) {
165
+ let selected : typeof opened [ 0 ]
166
+
167
+ if ( opened . length > 1 ) {
168
+ const items : vscode . QuickPickItem [ ] = opened . map ( ( folder ) : vscode . QuickPickItem => {
169
+ return {
170
+ label : folder . folderUri . fsPath ,
171
+ }
172
+ } )
173
+ const item = await vscode . window . showQuickPick ( items , {
174
+ title : "Select a recently opened folder" ,
175
+ } )
176
+ if ( ! item ) {
177
+ return
174
178
}
175
- } )
176
- const item = await vscode . window . showQuickPick ( items , {
177
- title : "Select a recently opened folder" ,
178
- } )
179
- if ( ! item ) {
180
- return
179
+ selected = opened [ items . indexOf ( item ) ]
180
+ } else {
181
+ selected = opened [ 0 ]
181
182
}
182
- const selected = opened [ items . indexOf ( item ) ]
183
- uri = vscode . Uri . joinPath ( uri , selected . folderUri . path )
183
+
184
+ await vscode . commands . executeCommand (
185
+ "vscode.openFolder" ,
186
+ vscode . Uri . from ( {
187
+ scheme : "vscode-remote" ,
188
+ authority : remoteAuthority ,
189
+ path : selected . folderUri . path ,
190
+ } ) ,
191
+ )
192
+ return
184
193
}
185
194
186
- await vscode . commands . executeCommand ( "vscode.openFolder" , uri )
195
+ // This opens the workspace without an active folder opened.
196
+ await vscode . commands . executeCommand ( "vscode.newWindow" , { remoteAuthority : remoteAuthority , reuseWindow : true } )
187
197
}
188
198
}
0 commit comments