@@ -134,6 +134,7 @@ class CadenceEditor extends React.Component<
134
134
languageClient ?: MonacoLanguageClient ;
135
135
_subscription : any ;
136
136
editorStates : { [ key : string ] : EditorState } ;
137
+ clients : { [ key : string ] : MonacoLanguageClient }
137
138
private callbacks : Callbacks ;
138
139
139
140
constructor ( props : {
@@ -150,6 +151,7 @@ class CadenceEditor extends React.Component<
150
151
super ( props ) ;
151
152
152
153
this . editorStates = { } ;
154
+ this . clients = { } ;
153
155
this . handleResize = this . handleResize . bind ( this ) ;
154
156
window . addEventListener ( 'resize' , this . handleResize ) ;
155
157
configureCadence ( ) ;
@@ -197,21 +199,26 @@ class CadenceEditor extends React.Component<
197
199
198
200
private async loadLanguageClient ( ) {
199
201
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 ( )
204
207
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
+ } ,
213
216
) ;
214
- } ) ;
217
+ this . clients [ clientId ] = this . languageClient ;
218
+ } else {
219
+ this . languageClient = this . clients [ clientId ]
220
+ }
221
+
215
222
}
216
223
217
224
private async getParameters ( ) {
@@ -317,6 +324,7 @@ class CadenceEditor extends React.Component<
317
324
const serverStatusChanged = this . props . serverReady !== prevProps . serverReady
318
325
const activeIdChanged = this . props . activeId !== prevProps . activeId
319
326
const typeChanged = this . props . type !== prevProps . type
327
+
320
328
if ( serverStatusChanged || activeIdChanged || typeChanged ) {
321
329
if ( this . props . callbacks . toServer !== null ) {
322
330
await this . loadLanguageClient ( )
@@ -344,8 +352,6 @@ class CadenceEditor extends React.Component<
344
352
}
345
353
346
354
extract ( code : string , keyWord : string ) : string [ ] {
347
- // TODO: add different processors for contract, scripts and transactions
348
-
349
355
const target = code
350
356
. split ( / \r \n | \n | \r / )
351
357
. find ( ( line ) => line . includes ( keyWord ) ) ;
0 commit comments