@@ -4,7 +4,9 @@ import { WSChannelHandler } from '@opensumi/ide-connection/lib/browser';
44import { BaseConnection } from '@opensumi/ide-connection/lib/common/connection' ;
55import {
66 AppConfig ,
7+ ContributionProvider ,
78 Deferred ,
9+ Disposable ,
810 DisposableStore ,
911 IApplicationService ,
1012 IExtensionProps ,
@@ -21,6 +23,7 @@ import {
2123} from '../common' ;
2224import { ActivatedExtensionJSON } from '../common/activator' ;
2325import { AbstractNodeExtProcessService } from '../common/extension.service' ;
26+ import { IMainThreadExtenderService , MainThreadExtenderContribution } from '../common/main.thread.extender' ;
2427import { ExtHostAPIIdentifier } from '../common/vscode' ;
2528import { knownProtocols } from '../common/vscode/protocols' ;
2629
@@ -37,7 +40,7 @@ export class NodeExtProcessService implements AbstractNodeExtProcessService<IExt
3740 private readonly appConfig : AppConfig ;
3841
3942 @Autowired ( INJECTOR_TOKEN )
40- private readonly injector : Injector ;
43+ protected readonly injector : Injector ;
4144
4245 @Autowired ( ExtensionNodeServiceServerPath )
4346 private readonly extensionNodeClient : IExtensionNodeClientService ;
@@ -48,6 +51,12 @@ export class NodeExtProcessService implements AbstractNodeExtProcessService<IExt
4851 @Autowired ( WSChannelHandler )
4952 private readonly channelHandler : WSChannelHandler ;
5053
54+ @Autowired ( IMainThreadExtenderService )
55+ private readonly mainThreadExtenderService : IMainThreadExtenderService ;
56+
57+ @Autowired ( MainThreadExtenderContribution )
58+ private readonly mainThreadExtenderContributionProvider : ContributionProvider < MainThreadExtenderContribution > ;
59+
5160 private _apiFactoryDisposables = new DisposableStore ( ) ;
5261
5362 public ready : Deferred < void > = new Deferred ( ) ;
@@ -125,9 +134,31 @@ export class NodeExtProcessService implements AbstractNodeExtProcessService<IExt
125134 this . _apiFactoryDisposables . add ( apiProxy ) ;
126135 this . _apiFactoryDisposables . add ( toDisposable ( initNodeThreadAPIProxy ( this . protocol , this . injector , this ) ) ) ;
127136 this . _apiFactoryDisposables . add ( toDisposable ( createSumiAPIFactory ( this . protocol , this . injector ) ) ) ;
137+ this . _apiFactoryDisposables . add ( this . createExternalSumiAPIFactory ( ) ) ;
128138 await apiProxy . setup ( ) ;
129139 }
130140
141+ /**
142+ * register external main thread class
143+ * @returns disposer
144+ */
145+ private createExternalSumiAPIFactory ( ) {
146+ const disposer = new Disposable ( ) ;
147+ // register main thread extender contribution
148+ const contributions = this . mainThreadExtenderContributionProvider . getContributions ( ) ;
149+ for ( const contribution of contributions ) {
150+ contribution . registerMainThreadExtender ( this . mainThreadExtenderService ) ;
151+ }
152+ // instantiate this MainThreadExtenderClass
153+ const extenders = this . mainThreadExtenderService . getMainThreadExtenders ( ) ;
154+ for ( const extender of extenders ) {
155+ const service = this . injector . get ( extender . serviceClass , [ this . protocol ] ) ;
156+ this . protocol . set ( extender . identifier , service ) ;
157+ disposer . addDispose ( service ) ;
158+ }
159+ return disposer ;
160+ }
161+
131162 public async getActivatedExtensions ( ) : Promise < ActivatedExtensionJSON [ ] > {
132163 const proxy = await this . getProxy ( ) ;
133164 return await proxy . $getActivatedExtensions ( ) ;
0 commit comments