@@ -397,20 +397,13 @@ export class Commands {
397397 throw new Error ( "You are not logged in" )
398398 }
399399
400- const agent = treeItem . workspaceAgent
401- if ( ! agent ) {
402- // `openFromSidebar` is only callable on agents or single-agent workspaces,
403- // where this will always be set.
404- return
405- }
406-
407400 try {
408401 await openWorkspace (
409402 this . restClient ,
410403 baseUrl ,
411404 treeItem . workspaceOwner ,
412405 treeItem . workspaceName ,
413- agent ,
406+ treeItem . workspaceAgent ,
414407 treeItem . workspaceFolderPath ,
415408 true ,
416409 )
@@ -592,37 +585,41 @@ async function openWorkspace(
592585 baseUrl : string ,
593586 workspaceOwner : string ,
594587 workspaceName : string ,
595- workspaceAgent : string ,
588+ workspaceAgent : string | undefined ,
596589 folderPath : string | undefined ,
597590 openRecent : boolean | undefined ,
598591) {
599592 let remoteAuthority = toRemoteAuthority ( baseUrl , workspaceOwner , workspaceName , workspaceAgent )
600593
601- let hostnameSuffix = "coder"
602- try {
603- const sshConfig = await restClient . getDeploymentSSHConfig ( )
604- // If the field is undefined, it's an older server, and always 'coder'
605- hostnameSuffix = sshConfig . hostname_suffix ?? hostnameSuffix
606- } catch ( error ) {
607- if ( ! isAxiosError ( error ) ) {
608- throw error
609- }
610- switch ( error . response ?. status ) {
611- case 404 : {
612- // Likely a very old deployment, just use the default.
613- break
614- }
615- case 401 : {
594+ // When called from `openFromSidebar`, the workspaceAgent will only not be set
595+ // if the workspace is stopped, in which case we can't use Coder Connect
596+ // When called from `open`, the workspaceAgent will always be set.
597+ if ( workspaceAgent ) {
598+ let hostnameSuffix = "coder"
599+ try {
600+ const sshConfig = await restClient . getDeploymentSSHConfig ( )
601+ // If the field is undefined, it's an older server, and always 'coder'
602+ hostnameSuffix = sshConfig . hostname_suffix ?? hostnameSuffix
603+ } catch ( error ) {
604+ if ( ! isAxiosError ( error ) ) {
616605 throw error
617606 }
618- default :
619- throw error
607+ switch ( error . response ?. status ) {
608+ case 404 : {
609+ // Likely a very old deployment, just use the default.
610+ break
611+ }
612+ case 401 : {
613+ throw error
614+ }
615+ default :
616+ throw error
617+ }
618+ }
619+ const coderConnectAddr = await maybeCoderConnectAddr ( workspaceAgent , workspaceName , workspaceOwner , hostnameSuffix )
620+ if ( coderConnectAddr ) {
621+ remoteAuthority = `ssh-remote+${ coderConnectAddr } `
620622 }
621- }
622-
623- const coderConnectAddr = await maybeCoderConnectAddr ( workspaceAgent , workspaceName , workspaceOwner , hostnameSuffix )
624- if ( coderConnectAddr ) {
625- remoteAuthority = `ssh-remote+${ coderConnectAddr } `
626623 }
627624
628625 let newWindow = true
0 commit comments