33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- import { Disposable } from 'vs/base/common/lifecycle' ;
7- import { IChannel , IServerChannel , getDelayedChannel } from 'vs/base/parts/ipc/common/ipc' ;
8- import { Client } from 'vs/base/parts/ipc/common/ipc.net' ;
96import { IEnvironmentService } from 'vs/platform/environment/common/environment' ;
10- import { connectRemoteAgentManagement , IConnectionOptions } from 'vs/platform/remote/common/remoteAgentConnection' ;
117import { IWindowConfiguration } from 'vs/platform/windows/common/windows' ;
12- import { IRemoteAgentConnection , IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService' ;
8+ import { IRemoteAgentConnection } from 'vs/workbench/services/remote/common/remoteAgentService' ;
139import { IRemoteAuthorityResolverService } from 'vs/platform/remote/common/remoteAuthorityResolver' ;
14- import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle' ;
15- import { RemoteAgentConnectionContext , IRemoteAgentEnvironment } from 'vs/platform/remote/common/remoteAgentEnvironment' ;
16- import { IWorkbenchContribution , IWorkbenchContributionsRegistry , Extensions } from 'vs/workbench/common/contributions' ;
17- import { Registry } from 'vs/platform/registry/common/platform' ;
18- import { RemoteExtensionEnvironmentChannelClient } from 'vs/workbench/services/remote/common/remoteAgentEnvironmentChannel' ;
19- import { INotificationService } from 'vs/platform/notification/common/notification' ;
20- import { localize } from 'vs/nls' ;
2110import product from 'vs/platform/product/node/product' ;
2211import { nodeWebSocketFactory } from 'vs/platform/remote/node/nodeWebSocketFactory' ;
12+ import { AbstractRemoteAgentService , RemoteAgentConnection } from 'vs/workbench/services/remote/common/abstractRemoteAgentService' ;
2313
24- export class RemoteAgentService extends Disposable implements IRemoteAgentService {
25-
26- _serviceBrand : any ;
14+ export class RemoteAgentService extends AbstractRemoteAgentService {
2715
2816 private readonly _connection : IRemoteAgentConnection | null = null ;
29- private _environment : Promise < IRemoteAgentEnvironment | null > | null ;
3017
31- constructor (
32- { remoteAuthority } : IWindowConfiguration ,
33- @IEnvironmentService private readonly _environmentService : IEnvironmentService ,
18+ constructor ( { remoteAuthority } : IWindowConfiguration ,
19+ @IEnvironmentService environmentService : IEnvironmentService ,
3420 @IRemoteAuthorityResolverService remoteAuthorityResolverService : IRemoteAuthorityResolverService
3521 ) {
36- super ( ) ;
22+ super ( environmentService ) ;
3723 if ( remoteAuthority ) {
38- this . _connection = this . _register ( new RemoteAgentConnection ( remoteAuthority , _environmentService , remoteAuthorityResolverService ) ) ;
24+ this . _connection = this . _register ( new RemoteAgentConnection ( remoteAuthority , product . commit , nodeWebSocketFactory , environmentService , remoteAuthorityResolverService ) ) ;
3925 }
4026 }
4127
4228 getConnection ( ) : IRemoteAgentConnection | null {
4329 return this . _connection ;
4430 }
45-
46- getEnvironment ( bail ?: boolean ) : Promise < IRemoteAgentEnvironment | null > {
47- if ( ! this . _environment ) {
48- const connection = this . getConnection ( ) ;
49- if ( connection ) {
50- const client = new RemoteExtensionEnvironmentChannelClient ( connection . getChannel ( 'remoteextensionsenvironment' ) ) ;
51- this . _environment = client . getEnvironmentData ( connection . remoteAuthority , this . _environmentService . extensionDevelopmentLocationURI ) ;
52- } else {
53- this . _environment = Promise . resolve ( null ) ;
54- }
55- }
56- return bail ? this . _environment : this . _environment . then ( undefined , ( ) => null ) ;
57- }
5831}
59-
60- class RemoteAgentConnection extends Disposable implements IRemoteAgentConnection {
61-
62- readonly remoteAuthority : string ;
63- private _connection : Promise < Client < RemoteAgentConnectionContext > > | null ;
64-
65- constructor (
66- remoteAuthority : string ,
67- private _environmentService : IEnvironmentService ,
68- private _remoteAuthorityResolverService : IRemoteAuthorityResolverService
69- ) {
70- super ( ) ;
71- this . remoteAuthority = remoteAuthority ;
72- this . _connection = null ;
73- }
74-
75- getChannel < T extends IChannel > ( channelName : string ) : T {
76- return < T > getDelayedChannel ( this . _getOrCreateConnection ( ) . then ( c => c . getChannel ( channelName ) ) ) ;
77- }
78-
79- registerChannel < T extends IServerChannel < RemoteAgentConnectionContext > > ( channelName : string , channel : T ) : void {
80- this . _getOrCreateConnection ( ) . then ( client => client . registerChannel ( channelName , channel ) ) ;
81- }
82-
83- private _getOrCreateConnection ( ) : Promise < Client < RemoteAgentConnectionContext > > {
84- if ( ! this . _connection ) {
85- this . _connection = this . _createConnection ( ) ;
86- }
87- return this . _connection ;
88- }
89-
90- private async _createConnection ( ) : Promise < Client < RemoteAgentConnectionContext > > {
91- const options : IConnectionOptions = {
92- isBuilt : this . _environmentService . isBuilt ,
93- commit : product . commit ,
94- webSocketFactory : nodeWebSocketFactory ,
95- addressProvider : {
96- getAddress : async ( ) => {
97- const { host, port } = await this . _remoteAuthorityResolverService . resolveAuthority ( this . remoteAuthority ) ;
98- return { host, port } ;
99- }
100- }
101- } ;
102- const connection = await connectRemoteAgentManagement ( options , this . remoteAuthority , `renderer` ) ;
103- this . _register ( connection ) ;
104- return connection . client ;
105- }
106- }
107-
108- class RemoteConnectionFailureNotificationContribution implements IWorkbenchContribution {
109-
110- constructor (
111- @IRemoteAgentService remoteAgentService : RemoteAgentService ,
112- @INotificationService notificationService : INotificationService ,
113- ) {
114- // Let's cover the case where connecting to fetch the remote extension info fails
115- remoteAgentService . getEnvironment ( true )
116- . then ( undefined , err => notificationService . error ( localize ( 'connectionError' , "Failed to connect to the remote extension host agent (Error: {0})" , err ? err . message : '' ) ) ) ;
117- }
118-
119- }
120-
121- const workbenchRegistry = Registry . as < IWorkbenchContributionsRegistry > ( Extensions . Workbench ) ;
122- workbenchRegistry . registerWorkbenchContribution ( RemoteConnectionFailureNotificationContribution , LifecyclePhase . Ready ) ;
0 commit comments