@@ -49,7 +49,6 @@ interface SSHConnectionParams {
49
49
}
50
50
51
51
interface SSHConnectionInfo extends SSHConnectionParams {
52
- isFirstConnection : boolean ;
53
52
}
54
53
55
54
interface WorkspaceRestartInfo {
@@ -144,12 +143,13 @@ export default class RemoteConnector extends Disposable {
144
143
) {
145
144
super ( ) ;
146
145
147
- if ( isGitpodRemoteWindow ( context ) ) {
146
+ const remoteConnectionInfo = getGitpodRemoteWindow ( context ) ;
147
+ if ( remoteConnectionInfo ) {
148
148
this . _register ( vscode . commands . registerCommand ( 'gitpod.api.autoTunnel' , this . autoTunnelCommand , this ) ) ;
149
149
150
150
// Don't await this on purpose so it doesn't block extension activation.
151
151
// Internally requesting a Gitpod Session requires the extension to be already activated.
152
- this . onGitpodRemoteConnection ( ) ;
152
+ this . onGitpodRemoteConnection ( remoteConnectionInfo ) ;
153
153
} else {
154
154
this . checkForStoppedWorkspaces ( ) ;
155
155
}
@@ -833,7 +833,7 @@ export default class RemoteConnector extends Disposable {
833
833
834
834
await this . updateRemoteSSHConfig ( usingSSHGateway , localAppSSHConfigPath ) ;
835
835
836
- await this . context . globalState . update ( `${ RemoteConnector . SSH_DEST_KEY } ${ sshDestination ! . toRemoteSSHString ( ) } ` , { ...params , isFirstConnection : true } as SSHConnectionParams ) ;
836
+ await this . context . globalState . update ( `${ RemoteConnector . SSH_DEST_KEY } ${ sshDestination ! . toRemoteSSHString ( ) } ` , { ...params } as SSHConnectionParams ) ;
837
837
838
838
const forceNewWindow = this . context . extensionMode === vscode . ExtensionMode . Production ;
839
839
@@ -888,7 +888,7 @@ export default class RemoteConnector extends Disposable {
888
888
return ;
889
889
}
890
890
891
- this . heartbeatManager = new HeartbeatManager ( connectionInfo . gitpodHost , connectionInfo . workspaceId , connectionInfo . instanceId , ! ! connectionInfo . debugWorkspace , session . accessToken , this . publicApi , this . logger , this . telemetry ) ;
891
+ this . heartbeatManager = new HeartbeatManager ( connectionInfo . gitpodHost , connectionInfo . workspaceId , connectionInfo . instanceId , ! ! connectionInfo . debugWorkspace , session , this . publicApi , this . logger , this . telemetry ) ;
892
892
893
893
try {
894
894
// TODO: remove this in the future, gitpod-remote no longer has the heartbeat logic, it's just here until users
@@ -1016,70 +1016,63 @@ export default class RemoteConnector extends Disposable {
1016
1016
}
1017
1017
}
1018
1018
1019
- private async onGitpodRemoteConnection ( ) {
1020
- const remoteUri = vscode . workspace . workspaceFile || vscode . workspace . workspaceFolders ?. [ 0 ] . uri ;
1021
- if ( ! remoteUri ) {
1022
- return ;
1023
- }
1019
+ private async onGitpodRemoteConnection ( { remoteAuthority, connectionInfo } : { remoteAuthority : string ; connectionInfo : SSHConnectionInfo } ) {
1020
+ let session : vscode . AuthenticationSession | undefined ;
1021
+ try {
1022
+ session = await this . getGitpodSession ( connectionInfo . gitpodHost ) ;
1023
+ if ( ! session ) {
1024
+ throw new Error ( 'No Gitpod session available' ) ;
1025
+ }
1024
1026
1025
- const [ , sshDestStr ] = remoteUri . authority . split ( '+' ) ;
1026
- const connectionInfo = this . context . globalState . get < SSHConnectionInfo > ( `${ RemoteConnector . SSH_DEST_KEY } ${ sshDestStr } ` ) ;
1027
- if ( ! connectionInfo ) {
1028
- return ;
1029
- }
1027
+ const workspaceInfo = await withServerApi ( session . accessToken , connectionInfo . gitpodHost , service => service . server . getWorkspace ( connectionInfo . workspaceId ) , this . logger ) ;
1028
+ if ( workspaceInfo . latestInstance ?. status ?. phase !== 'running' ) {
1029
+ throw new NoRunningInstanceError ( connectionInfo . workspaceId ) ;
1030
+ }
1030
1031
1031
- const session = await this . getGitpodSession ( connectionInfo . gitpodHost ) ;
1032
- if ( ! session ) {
1033
- return ;
1034
- }
1032
+ if ( workspaceInfo . latestInstance . id !== connectionInfo . instanceId ) {
1033
+ this . logger . info ( `Updating workspace ${ connectionInfo . workspaceId } latest instance id ${ connectionInfo . instanceId } => ${ workspaceInfo . latestInstance . id } ` ) ;
1034
+ connectionInfo . instanceId = workspaceInfo . latestInstance . id ;
1035
+ }
1035
1036
1036
- const workspaceInfo = await withServerApi ( session . accessToken , connectionInfo . gitpodHost , service => service . server . getWorkspace ( connectionInfo . workspaceId ) , this . logger ) ;
1037
- if ( workspaceInfo . latestInstance ?. status ?. phase !== 'running' ) {
1038
- return ;
1039
- }
1037
+ const [ , sshDestStr ] = remoteAuthority . split ( '+' ) ;
1038
+ await this . context . globalState . update ( `${ RemoteConnector . SSH_DEST_KEY } ${ sshDestStr } ` , { ...connectionInfo } as SSHConnectionParams ) ;
1040
1039
1041
- if ( workspaceInfo . latestInstance . id !== connectionInfo . instanceId ) {
1042
- this . logger . info ( `Updating workspace ${ connectionInfo . workspaceId } latest instance id ${ connectionInfo . instanceId } => ${ workspaceInfo . latestInstance . id } ` ) ;
1043
- connectionInfo . instanceId = workspaceInfo . latestInstance . id ;
1044
- }
1040
+ const gitpodVersion = await getGitpodVersion ( connectionInfo . gitpodHost , this . logger ) ;
1045
1041
1046
- await this . context . globalState . update ( ` ${ RemoteConnector . SSH_DEST_KEY } ${ sshDestStr } ` , { ... connectionInfo , isFirstConnection : false } as SSHConnectionParams ) ;
1042
+ await this . initPublicApi ( session , connectionInfo . gitpodHost ) ;
1047
1043
1048
- const gitpodVersion = await getGitpodVersion ( connectionInfo . gitpodHost , this . logger ) ;
1044
+ if ( this . publicApi ) {
1045
+ this . workspaceState = new WorkspaceState ( connectionInfo . workspaceId , this . publicApi , this . logger ) ;
1049
1046
1050
- await this . initPublicApi ( session , connectionInfo . gitpodHost ) ;
1047
+ let handled = false ;
1048
+ this . _register ( this . workspaceState . onWorkspaceStatusChanged ( async ( ) => {
1049
+ if ( ! this . workspaceState ! . isWorkspaceRunning ( ) && ! handled ) {
1050
+ handled = true ;
1051
+ await this . context . globalState . update ( `${ RemoteConnector . WORKSPACE_STOPPED_PREFIX } ${ connectionInfo . workspaceId } ` , { workspaceId : connectionInfo . workspaceId , gitpodHost : connectionInfo . gitpodHost } as WorkspaceRestartInfo ) ;
1052
+ vscode . commands . executeCommand ( 'workbench.action.remote.close' ) ;
1053
+ }
1054
+ } ) ) ;
1055
+ }
1051
1056
1052
- if ( this . publicApi ) {
1053
- this . workspaceState = new WorkspaceState ( connectionInfo . workspaceId , this . publicApi , this . logger ) ;
1054
-
1055
- let handled = false ;
1056
- this . _register ( this . workspaceState . onWorkspaceStatusChanged ( async ( ) => {
1057
- if ( ! this . workspaceState ! . isWorkspaceRunning ( ) && ! handled ) {
1058
- handled = true ;
1059
- await this . context . globalState . update ( `${ RemoteConnector . WORKSPACE_STOPPED_PREFIX } ${ connectionInfo . workspaceId } ` , { workspaceId : connectionInfo . workspaceId , gitpodHost : connectionInfo . gitpodHost } as WorkspaceRestartInfo ) ;
1060
- vscode . commands . executeCommand ( 'workbench.action.remote.close' ) ;
1061
- }
1057
+ const heartbeatSupported = session . scopes . includes ( ScopeFeature . LocalHeartbeat ) ;
1058
+ if ( heartbeatSupported ) {
1059
+ this . startHeartBeat ( session , connectionInfo ) ;
1060
+ } else {
1061
+ this . logger . warn ( `Local heartbeat not supported in ${ connectionInfo . gitpodHost } , using version ${ gitpodVersion . raw } ` ) ;
1062
+ }
1063
+
1064
+ const syncExtFlow = { ...connectionInfo , gitpodVersion : gitpodVersion . raw , userId : session . account . id , flow : 'sync_local_extensions' } ;
1065
+ this . initializeRemoteExtensions ( { ...syncExtFlow , quiet : true , flowId : uuid ( ) } ) ;
1066
+ this . context . subscriptions . push ( vscode . commands . registerCommand ( 'gitpod.installLocalExtensions' , ( ) => {
1067
+ this . initializeRemoteExtensions ( { ...syncExtFlow , quiet : false , flowId : uuid ( ) } ) ;
1062
1068
} ) ) ;
1063
- }
1064
1069
1065
- const heartbeatSupported = session . scopes . includes ( ScopeFeature . LocalHeartbeat ) ;
1066
- if ( heartbeatSupported ) {
1067
- this . startHeartBeat ( session , connectionInfo ) ;
1068
- } else {
1069
- this . logger . warn ( `Local heartbeat not supported in ${ connectionInfo . gitpodHost } , using version ${ gitpodVersion . raw } ` ) ;
1070
+ vscode . commands . executeCommand ( 'setContext' , 'gitpod.inWorkspace' , true ) ;
1071
+ } catch ( e ) {
1072
+ e . message = `Failed to resolve whole gitpod remote connection process: ${ e . message } ` ;
1073
+ this . logger . error ( e ) ;
1074
+ this . telemetry . sendTelemetryException ( e , { workspaceId : connectionInfo . workspaceId , instanceId : connectionInfo . instanceId , userId : session ?. account . id || '' } ) ;
1070
1075
}
1071
-
1072
- const syncExtFlow = { ...connectionInfo , gitpodVersion : gitpodVersion . raw , userId : session . account . id , flow : 'sync_local_extensions' } ;
1073
- this . initializeRemoteExtensions ( { ...syncExtFlow , quiet : true , flowId : uuid ( ) } ) ;
1074
- this . context . subscriptions . push ( vscode . commands . registerCommand ( 'gitpod.installLocalExtensions' , ( ) => {
1075
- this . initializeRemoteExtensions ( { ...syncExtFlow , quiet : false , flowId : uuid ( ) } ) ;
1076
- } ) ) ;
1077
-
1078
- this . _register ( vscode . commands . registerCommand ( '__gitpod.workspaceShutdown' , ( ) => {
1079
- this . logger . warn ( '__gitpod.workspaceShutdown command executed' ) ;
1080
- } ) ) ;
1081
-
1082
- vscode . commands . executeCommand ( 'setContext' , 'gitpod.inWorkspace' , true ) ;
1083
1076
}
1084
1077
1085
1078
private async showWsNotRunningDialog ( workspaceId : string , workspaceUrl : string , flow : UserFlowTelemetry ) {
@@ -1125,16 +1118,17 @@ export default class RemoteConnector extends Disposable {
1125
1118
}
1126
1119
}
1127
1120
1128
- function isGitpodRemoteWindow ( context : vscode . ExtensionContext ) {
1121
+ function getGitpodRemoteWindow ( context : vscode . ExtensionContext ) : { remoteAuthority : string ; connectionInfo : SSHConnectionInfo } | undefined {
1129
1122
const remoteUri = vscode . workspace . workspaceFile || vscode . workspace . workspaceFolders ?. [ 0 ] . uri ;
1130
1123
if ( vscode . env . remoteName === 'ssh-remote' && context . extension . extensionKind === vscode . ExtensionKind . UI && remoteUri ) {
1131
1124
const [ , sshDestStr ] = remoteUri . authority . split ( '+' ) ;
1132
1125
const connectionInfo = context . globalState . get < SSHConnectionInfo > ( `${ RemoteConnector . SSH_DEST_KEY } ${ sshDestStr } ` ) ;
1133
-
1134
- return ! ! connectionInfo ;
1126
+ if ( connectionInfo ) {
1127
+ return { remoteAuthority : remoteUri . authority , connectionInfo } ;
1128
+ }
1135
1129
}
1136
1130
1137
- return false ;
1131
+ return undefined ;
1138
1132
}
1139
1133
1140
1134
function getServiceURL ( gitpodHost : string ) : string {
0 commit comments