@@ -223,6 +223,7 @@ export class Commands {
223223 treeItem . workspaceName ,
224224 treeItem . workspaceAgent ,
225225 treeItem . workspaceFolderPath ,
226+ true ,
226227 )
227228 }
228229 }
@@ -232,6 +233,7 @@ export class Commands {
232233 let workspaceName : string
233234 let workspaceAgent : string | undefined
234235 let folderPath : string | undefined
236+ let openRecent : boolean | undefined
235237
236238 if ( args . length === 0 ) {
237239 const quickPick = vscode . window . createQuickPick ( )
@@ -340,9 +342,10 @@ export class Commands {
340342 workspaceName = args [ 1 ] as string
341343 // workspaceAgent is reserved for args[2], but multiple agents aren't supported yet.
342344 folderPath = args [ 3 ] as string | undefined
345+ openRecent = args [ 4 ] as boolean | undefined
343346 }
344347
345- await openWorkspace ( workspaceOwner , workspaceName , workspaceAgent , folderPath )
348+ await openWorkspace ( workspaceOwner , workspaceName , workspaceAgent , folderPath , openRecent )
346349 }
347350
348351 public async updateWorkspace ( ) : Promise < void > {
@@ -369,6 +372,7 @@ async function openWorkspace(
369372 workspaceName : string ,
370373 workspaceAgent : string | undefined ,
371374 folderPath : string | undefined ,
375+ openRecent : boolean | undefined ,
372376) {
373377 // A workspace can have multiple agents, but that's handled
374378 // when opening a workspace unless explicitly specified.
@@ -383,36 +387,34 @@ async function openWorkspace(
383387 newWindow = false
384388 }
385389
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 ) {
388393 const output : {
389394 workspaces : { folderUri : vscode . Uri ; remoteAuthority : string } [ ]
390395 } = await vscode . commands . executeCommand ( "_workbench.getRecentlyOpened" )
391396 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.
393402 ( opened ) => opened . folderUri ?. authority === remoteAuthority ,
394403 )
395- if ( opened . length > 0 ) {
396- let selected : ( typeof opened ) [ 0 ]
397404
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
409- }
410- selected = opened [ items . indexOf ( item ) ]
411- } else {
412- selected = opened [ 0 ]
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 = opened . map ( ( f ) => f . folderUri . path )
411+ folderPath = await vscode . window . showQuickPick ( items , {
412+ title : "Select a recently opened folder" ,
413+ } )
414+ if ( ! folderPath ) {
415+ // User aborted.
416+ return
413417 }
414-
415- folderPath = selected . folderUri . path
416418 }
417419 }
418420
0 commit comments