@@ -491,7 +491,7 @@ export class Commands {
491
491
} else {
492
492
workspaceOwner = args [ 0 ] as string
493
493
workspaceName = args [ 1 ] as string
494
- workspaceAgent = args [ 2 ] as string
494
+ workspaceAgent = args [ 2 ] as string | undefined
495
495
folderPath = args [ 3 ] as string | undefined
496
496
openRecent = args [ 4 ] as boolean | undefined
497
497
}
@@ -522,11 +522,11 @@ export class Commands {
522
522
523
523
const workspaceOwner = args [ 0 ] as string
524
524
const 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
526
526
const devContainerName = args [ 3 ] as string
527
527
const devContainerFolder = args [ 4 ] as string
528
528
529
- await openDevContainer ( baseUrl , workspaceOwner , workspaceName , workspaceAgent , devContainerName , devContainerFolder )
529
+ await this . openDevContainerInner ( baseUrl , workspaceOwner , workspaceName , workspaceAgent , devContainerName , devContainerFolder )
530
530
}
531
531
532
532
/**
@@ -652,33 +652,61 @@ export class Commands {
652
652
reuseWindow : ! newWindow ,
653
653
} )
654
654
}
655
- }
656
655
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 } `
674
695
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
+ }
684
711
}
712
+
0 commit comments