@@ -491,7 +491,7 @@ export class Commands {
491491} else {
492492workspaceOwner = args [ 0 ] as string
493493workspaceName = args [ 1 ] as string
494- workspaceAgent = args [ 2 ] as string
494+ workspaceAgent = args [ 2 ] as string | undefined
495495folderPath = args [ 3 ] as string | undefined
496496openRecent = args [ 4 ] as boolean | undefined
497497}
@@ -522,11 +522,11 @@ export class Commands {
522522
523523const workspaceOwner = args [ 0 ] as string
524524const workspaceName = args [ 1 ] as string
525- const workspaceAgent = undefined // args[2]is reserved, but we do not support multiple agents yet.
525+ const workspaceAgent = args [ 2 ] as string | undefined
526526const devContainerName = args [ 3 ] as string
527527const devContainerFolder = args [ 4 ] as string
528528
529- await openDevContainer ( baseUrl , workspaceOwner , workspaceName , workspaceAgent , devContainerName , devContainerFolder )
529+ await this . openDevContainerInner ( baseUrl , workspaceOwner , workspaceName , workspaceAgent , devContainerName , devContainerFolder )
530530}
531531
532532/**
@@ -652,33 +652,61 @@ export class Commands {
652652reuseWindow :! newWindow ,
653653} )
654654}
655- }
656655
657- async function openDevContainer (
658- baseUrl :string ,
659- workspaceOwner :string ,
660- workspaceName :string ,
661- workspaceAgent :string | undefined ,
662- devContainerName :string ,
663- devContainerFolder :string ,
664- ) {
665- const remoteAuthority = toRemoteAuthority ( baseUrl , workspaceOwner , workspaceName , workspaceAgent )
666-
667- const devContainer = Buffer . from ( JSON . stringify ( { containerName :devContainerName } ) , "utf-8" ) . toString ( "hex" )
668- const devContainerAuthority = `attached-container+${ devContainer } @${ remoteAuthority } `
669-
670- let newWindow = true
671- if ( ! vscode . workspace . workspaceFolders ?. length ) {
672- newWindow = false
673- }
656+ private async openDevContainerInner (
657+ baseUrl :string ,
658+ workspaceOwner :string ,
659+ workspaceName :string ,
660+ workspaceAgent :string | undefined ,
661+ devContainerName :string ,
662+ devContainerFolder :string ,
663+ ) {
664+ let remoteAuthority = toRemoteAuthority ( baseUrl , workspaceOwner , workspaceName , workspaceAgent )
665+
666+ if ( workspaceAgent ) {
667+ let sshConfig
668+ try {
669+ // Fetch (or get defaults) for the SSH config.
670+ sshConfig = await fetchSSHConfig ( this . restClient , this . vscodeProposed )
671+ } catch ( error ) {
672+ const message = getErrorMessage ( error , "no response from the server" )
673+ this . storage . writeToCoderOutputChannel ( `Failed to open workspace:${ message } ` )
674+ this . vscodeProposed . window . showErrorMessage ( "Failed to open workspace" , {
675+ detail :message ,
676+ modal :true ,
677+ useCustom :true ,
678+ } )
679+ return
680+ }
681+
682+ const coderConnectAddr = await maybeCoderConnectAddr (
683+ workspaceAgent ,
684+ workspaceName ,
685+ workspaceOwner ,
686+ sshConfig . hostname_suffix ,
687+ )
688+ if ( coderConnectAddr ) {
689+ remoteAuthority = `ssh-remote+${ coderConnectAddr } `
690+ }
691+ }
692+
693+ const devContainer = Buffer . from ( JSON . stringify ( { containerName :devContainerName } ) , "utf-8" ) . toString ( "hex" )
694+ const devContainerAuthority = `attached-container+${ devContainer } @${ remoteAuthority } `
674695
675- await vscode . commands . executeCommand (
676- "vscode.openFolder" ,
677- vscode . Uri . from ( {
678- scheme :"vscode-remote" ,
679- authority :devContainerAuthority ,
680- path :devContainerFolder ,
681- } ) ,
682- newWindow ,
683- )
696+ let newWindow = true
697+ if ( ! vscode . workspace . workspaceFolders ?. length ) {
698+ newWindow = false
699+ }
700+
701+ await vscode . commands . executeCommand (
702+ "vscode.openFolder" ,
703+ vscode . Uri . from ( {
704+ scheme :"vscode-remote" ,
705+ authority :devContainerAuthority ,
706+ path :devContainerFolder ,
707+ } ) ,
708+ newWindow ,
709+ )
710+ }
684711}
712+