@@ -28,7 +28,7 @@ export default class MongoDBService {
28
28
_cachedFields : object ;
29
29
_cachedDatabases : [ ] ;
30
30
_cachedCollections : object ;
31
- _cachedShellSymbols : object ;
31
+ _cachedShellSymbols : any ;
32
32
_extensionPath ?: string ;
33
33
_visitor : Visitor ;
34
34
@@ -185,21 +185,21 @@ export default class MongoDBService {
185
185
worker . postMessage ( ServerCommands . EXECUTE_ALL_FROM_PLAYGROUND ) ;
186
186
187
187
// Listen for results from the worker thread.
188
- worker . on ( 'message' , ( [ error , result ] ) => {
188
+ worker . on ( 'message' , async ( [ error , result ] ) => {
189
189
if ( error ) {
190
190
this . _connection . console . log (
191
191
`MONGOSH execute all error: ${ util . inspect ( error ) } `
192
192
) ;
193
193
this . _connection . sendNotification ( 'showErrorMessage' , error . message ) ;
194
194
}
195
195
196
- worker . terminate ( ) . then ( ( ) => {
197
- return resolve ( result ) ;
198
- } ) ;
196
+ await worker . terminate ( ) ;
197
+
198
+ return resolve ( result ) ;
199
199
} ) ;
200
200
201
201
// Listen for cancellation request from the language server client.
202
- token . onCancellationRequested ( ( ) => {
202
+ token . onCancellationRequested ( async ( ) => {
203
203
this . _connection . console . log ( 'PLAYGROUND cancellation requested' ) ;
204
204
this . _connection . sendNotification (
205
205
'showInformationMessage' ,
@@ -221,13 +221,9 @@ export default class MongoDBService {
221
221
222
222
// Stop the worker and all JavaScript execution
223
223
// in the worker thread as soon as possible.
224
- worker . terminate ( ) . then ( ( status ) => {
225
- this . _connection . console . log (
226
- `PLAYGROUND canceled with status: ${ status } `
227
- ) ;
224
+ await worker . terminate ( ) ;
228
225
229
- return resolve ( [ ] ) ;
230
- } ) ;
226
+ return resolve ( [ ] ) ;
231
227
} ) ;
232
228
} ) ;
233
229
}
@@ -247,19 +243,19 @@ export default class MongoDBService {
247
243
this . _connection . console . log ( 'MONGOSH get list databases...' ) ;
248
244
worker . postMessage ( ServerCommands . GET_LIST_DATABASES ) ;
249
245
250
- worker . on ( 'message' , ( [ error , result ] ) => {
246
+ worker . on ( 'message' , async ( [ error , result ] ) => {
251
247
if ( error ) {
252
248
this . _connection . console . log (
253
249
`MONGOSH get list databases error: ${ util . inspect ( error ) } `
254
250
) ;
255
251
}
256
252
257
- worker . terminate ( ) . then ( ( ) => {
258
- this . _connection . console . log (
259
- `MONGOSH found ${ result . length } databases`
260
- ) ;
261
- this . updateCurrentSessionDatabases ( result ) ;
262
- } ) ;
253
+ await worker . terminate ( ) ;
254
+
255
+ this . _connection . console . log (
256
+ `MONGOSH found ${ result . length } databases`
257
+ ) ;
258
+ this . updateCurrentSessionDatabases ( result ) ;
263
259
} ) ;
264
260
}
265
261
@@ -279,21 +275,21 @@ export default class MongoDBService {
279
275
this . _connection . console . log ( 'MONGOSH get list collections...' ) ;
280
276
worker . postMessage ( ServerCommands . GET_LIST_COLLECTIONS ) ;
281
277
282
- worker . on ( 'message' , ( [ error , result ] ) => {
278
+ worker . on ( 'message' , async ( [ error , result ] ) => {
283
279
if ( error ) {
284
280
this . _connection . console . log (
285
281
`MONGOSH get list collections error: ${ util . inspect ( error ) } `
286
282
) ;
287
283
}
288
284
289
- worker . terminate ( ) . then ( ( ) => {
290
- this . _connection . console . log (
291
- `MONGOSH found ${ result . length } collections`
292
- ) ;
293
- this . updateCurrentSessionCollections ( databaseName , result ) ;
285
+ await worker . terminate ( ) ;
294
286
295
- return resolve ( true ) ;
296
- } ) ;
287
+ this . _connection . console . log (
288
+ `MONGOSH found ${ result . length } collections`
289
+ ) ;
290
+ this . updateCurrentSessionCollections ( databaseName , result ) ;
291
+
292
+ return resolve ( true ) ;
297
293
} ) ;
298
294
} ) ;
299
295
}
@@ -319,17 +315,17 @@ export default class MongoDBService {
319
315
this . _connection . console . log ( `SCHEMA for namespace: "${ namespace } "` ) ;
320
316
worker . postMessage ( ServerCommands . GET_FIELDS_FROM_SCHEMA ) ;
321
317
322
- worker . on ( 'message' , ( [ error , fields ] ) => {
318
+ worker . on ( 'message' , async ( [ error , fields ] ) => {
323
319
if ( error ) {
324
320
this . _connection . console . log ( `SCHEMA error: ${ util . inspect ( error ) } ` ) ;
325
321
}
326
322
327
- worker . terminate ( ) . then ( ( ) => {
328
- this . _connection . console . log ( `SCHEMA found ${ fields . length } fields` ) ;
329
- this . updateCurrentSessionFields ( namespace , fields ) ;
323
+ await worker . terminate ( ) ;
324
+
325
+ this . _connection . console . log ( `SCHEMA found ${ fields . length } fields` ) ;
326
+ this . updateCurrentSessionFields ( namespace , fields ) ;
330
327
331
- return resolve ( true ) ;
332
- } ) ;
328
+ return resolve ( true ) ;
333
329
} ) ;
334
330
} ) ;
335
331
}
@@ -353,7 +349,7 @@ export default class MongoDBService {
353
349
// ------ COMPLETION ------ //
354
350
355
351
// Check if string is a valid property name
356
- private isValidPropertyName ( str ) {
352
+ private isValidPropertyName ( str ) : boolean {
357
353
return / ^ (? ! [ 0 - 9 ] ) [ a - z A - Z 0 - 9 $ _ ] + $ / . test ( str ) ;
358
354
}
359
355
@@ -409,6 +405,7 @@ export default class MongoDBService {
409
405
textFromEditor : string ,
410
406
position : { line : number ; character : number }
411
407
) : Promise < [ ] > {
408
+ // eslint-disable-next-line complexity
412
409
return new Promise ( async ( resolve ) => {
413
410
this . _connection . console . log (
414
411
`LS text from editor: ${ util . inspect ( textFromEditor ) } `
@@ -449,27 +446,27 @@ export default class MongoDBService {
449
446
'VISITOR found shell collection methods completion'
450
447
) ;
451
448
452
- return resolve ( this . _cachedShellSymbols [ ' Collection' ] ) ;
449
+ return resolve ( this . _cachedShellSymbols . Collection ) ;
453
450
}
454
451
455
452
if ( state . isAggregationCursor ) {
456
453
this . _connection . console . log (
457
454
'VISITOR found shell aggregation cursor methods completion'
458
455
) ;
459
456
460
- return resolve ( this . _cachedShellSymbols [ ' AggregationCursor' ] ) ;
457
+ return resolve ( this . _cachedShellSymbols . AggregationCursor ) ;
461
458
}
462
459
463
460
if ( state . isFindCursor ) {
464
461
this . _connection . console . log (
465
462
'VISITOR found shell cursor methods completion'
466
463
) ;
467
464
468
- return resolve ( this . _cachedShellSymbols [ ' Cursor' ] ) ;
465
+ return resolve ( this . _cachedShellSymbols . Cursor ) ;
469
466
}
470
467
471
468
if ( state . isDbCallExpression ) {
472
- let dbCompletions : any = [ ...this . _cachedShellSymbols [ ' Database' ] ] ;
469
+ let dbCompletions : any = [ ...this . _cachedShellSymbols . Database ] ;
473
470
474
471
if ( state . databaseName ) {
475
472
this . _connection . console . log (
@@ -561,7 +558,7 @@ export default class MongoDBService {
561
558
return [ ] ;
562
559
}
563
560
564
- public clearCurrentSessionConnection ( ) {
561
+ public clearCurrentSessionConnection ( ) : void {
565
562
this . _serviceProvider = undefined ;
566
563
this . _runtime = undefined ;
567
564
this . _connectionString = undefined ;
0 commit comments