@@ -223,6 +223,7 @@ export class Commands {
223
223
treeItem . workspaceName ,
224
224
treeItem . workspaceAgent ,
225
225
treeItem . workspaceFolderPath ,
226
+ true ,
226
227
)
227
228
}
228
229
}
@@ -232,6 +233,7 @@ export class Commands {
232
233
let workspaceName : string
233
234
let workspaceAgent : string | undefined
234
235
let folderPath : string | undefined
236
+ let openRecent : boolean | undefined
235
237
236
238
if ( args . length === 0 ) {
237
239
const quickPick = vscode . window . createQuickPick ( )
@@ -340,9 +342,10 @@ export class Commands {
340
342
workspaceName = args [ 1 ] as string
341
343
// workspaceAgent is reserved for args[2], but multiple agents aren't supported yet.
342
344
folderPath = args [ 3 ] as string | undefined
345
+ openRecent = args [ 4 ] as boolean | undefined
343
346
}
344
347
345
- await openWorkspace ( workspaceOwner , workspaceName , workspaceAgent , folderPath )
348
+ await openWorkspace ( workspaceOwner , workspaceName , workspaceAgent , folderPath , openRecent )
346
349
}
347
350
348
351
public async updateWorkspace ( ) : Promise < void > {
@@ -369,6 +372,7 @@ async function openWorkspace(
369
372
workspaceName : string ,
370
373
workspaceAgent : string | undefined ,
371
374
folderPath : string | undefined ,
375
+ openRecent : boolean | undefined ,
372
376
) {
373
377
// A workspace can have multiple agents, but that's handled
374
378
// when opening a workspace unless explicitly specified.
@@ -383,36 +387,38 @@ async function openWorkspace(
383
387
newWindow = false
384
388
}
385
389
386
- // If a folder isn't specified, we can try to open a recently opened folder.
387
- if ( ! folderPath ) {
390
+ // If a folder isn't specified or we have been asked to open the most recent,
391
+ // we can try to open a recently opened folder/workspace.
392
+ if ( ! folderPath || openRecent ) {
388
393
const output : {
389
394
workspaces : { folderUri : vscode . Uri ; remoteAuthority : string } [ ]
390
395
} = await vscode . commands . executeCommand ( "_workbench.getRecentlyOpened" )
391
396
const opened = output . workspaces . filter (
392
- // Filter out `/` since that's added below.
397
+ // Remove recents that do not belong to this connection. The remote
398
+ // authority maps to a workspace or workspace/agent combination (using the
399
+ // SSH host name). This means, at the moment, you can have a different
400
+ // set of recents for a workspace versus workspace/agent combination, even
401
+ // if that agent is the default for the workspace.
393
402
( opened ) => opened . folderUri ?. authority === remoteAuthority ,
394
403
)
395
- if ( opened . length > 0 ) {
396
- let selected : ( typeof opened ) [ 0 ]
397
404
398
- if ( opened . length > 1 ) {
399
- const items : vscode . QuickPickItem [ ] = opened . map ( ( folder ) : vscode . QuickPickItem => {
400
- return {
401
- label : folder . folderUri . path ,
402
- }
403
- } )
404
- const item = await vscode . window . showQuickPick ( items , {
405
- title : "Select a recently opened folder" ,
406
- } )
407
- if ( ! item ) {
408
- return
405
+ // openRecent will always use the most recent. Otherwise, if there are
406
+ // multiple we ask the user which to use.
407
+ if ( opened . length === 1 || ( opened . length > 1 && openRecent ) ) {
408
+ folderPath = opened [ 0 ] . folderUri . path
409
+ } else if ( opened . length > 1 ) {
410
+ const items : vscode . QuickPickItem [ ] = opened . map ( ( folder ) : vscode . QuickPickItem => {
411
+ return {
412
+ label : folder . folderUri . path ,
409
413
}
410
- selected = opened [ items . indexOf ( item ) ]
411
- } else {
412
- selected = opened [ 0 ]
414
+ } )
415
+ const item = await vscode . window . showQuickPick ( items , {
416
+ title : "Select a recently opened folder" ,
417
+ } )
418
+ if ( ! item ) {
419
+ return
413
420
}
414
-
415
- folderPath = selected . folderUri . path
421
+ folderPath = opened [ items . indexOf ( item ) ] . folderUri . path
416
422
}
417
423
}
418
424
0 commit comments