@@ -134,6 +134,7 @@ class CadenceEditor extends React.Component<
134134 languageClient ?: MonacoLanguageClient ;
135135 _subscription : any ;
136136 editorStates : { [ key : string ] : EditorState } ;
137+ clients : { [ key : string ] : MonacoLanguageClient }
137138 private callbacks : Callbacks ;
138139
139140 constructor ( props : {
@@ -150,6 +151,7 @@ class CadenceEditor extends React.Component<
150151 super ( props ) ;
151152
152153 this . editorStates = { } ;
154+ this . clients = { } ;
153155 this . handleResize = this . handleResize . bind ( this ) ;
154156 window . addEventListener ( 'resize' , this . handleResize ) ;
155157 configureCadence ( ) ;
@@ -197,21 +199,26 @@ class CadenceEditor extends React.Component<
197199
198200 private async loadLanguageClient ( ) {
199201 this . callbacks = this . props . callbacks ;
200-
201- this . languageClient = createCadenceLanguageClient ( this . callbacks ) ;
202- this . languageClient . start ( ) ;
203- this . languageClient . onReady ( ) . then ( ( ) => {
202+ const clientId = this . props . activeId ;
203+ if ( ! this . clients [ clientId ] ) {
204+ this . languageClient = createCadenceLanguageClient ( this . callbacks ) ;
205+ this . languageClient . start ( ) ;
206+ await this . languageClient . onReady ( )
204207 this . languageClient . onNotification (
205- CadenceCheckCompleted . methodName ,
206- async ( result : CadenceCheckCompleted . Params ) => {
207- if ( result . valid ) {
208- const params = await this . getParameters ( ) ;
209- this . setExecutionArguments ( params ) ;
210- }
211- this . processMarkers ( ) ;
212- } ,
208+ CadenceCheckCompleted . methodName ,
209+ async ( result : CadenceCheckCompleted . Params ) => {
210+ if ( result . valid ) {
211+ const params = await this . getParameters ( ) ;
212+ this . setExecutionArguments ( params ) ;
213+ }
214+ this . processMarkers ( ) ;
215+ } ,
213216 ) ;
214- } ) ;
217+ this . clients [ clientId ] = this . languageClient ;
218+ } else {
219+ this . languageClient = this . clients [ clientId ]
220+ }
221+
215222 }
216223
217224 private async getParameters ( ) {
@@ -317,6 +324,7 @@ class CadenceEditor extends React.Component<
317324 const serverStatusChanged = this . props . serverReady !== prevProps . serverReady
318325 const activeIdChanged = this . props . activeId !== prevProps . activeId
319326 const typeChanged = this . props . type !== prevProps . type
327+
320328 if ( serverStatusChanged || activeIdChanged || typeChanged ) {
321329 if ( this . props . callbacks . toServer !== null ) {
322330 await this . loadLanguageClient ( )
@@ -344,8 +352,6 @@ class CadenceEditor extends React.Component<
344352 }
345353
346354 extract ( code : string , keyWord : string ) : string [ ] {
347- // TODO: add different processors for contract, scripts and transactions
348-
349355 const target = code
350356 . split ( / \r \n | \n | \r / )
351357 . find ( ( line ) => line . includes ( keyWord ) ) ;
0 commit comments