@@ -152,7 +152,7 @@ export default class PlaygroundController {
152
152
this . _connectionController . addEventListener (
153
153
DataServiceEventTypes . ACTIVE_CONNECTION_CHANGED ,
154
154
( ) => {
155
- void this . _connectToServiceProvider ( ) ;
155
+ void this . _activeConnectionChanged ( ) ;
156
156
}
157
157
) ;
158
158
@@ -163,22 +163,26 @@ export default class PlaygroundController {
163
163
this . _playgroundResultViewColumn = editor . viewColumn ;
164
164
this . _playgroundResultTextDocument = editor ?. document ;
165
165
}
166
+ const isPlaygroundEditor = isPlayground ( editor ?. document . uri ) ;
166
167
167
168
void vscode . commands . executeCommand (
168
169
'setContext' ,
169
170
'mdb.isPlayground' ,
170
- isPlayground ( editor ?. document . uri )
171
+ isPlaygroundEditor
171
172
) ;
172
173
173
- if ( editor ?. document . languageId !== 'Log' ) {
174
+ if ( isPlaygroundEditor ) {
174
175
this . _activeTextEditor = editor ;
175
176
this . _activeConnectionCodeLensProvider . setActiveTextEditor (
176
177
this . _activeTextEditor
177
178
) ;
178
179
this . _playgroundSelectedCodeActionProvider . setActiveTextEditor (
179
180
this . _activeTextEditor
180
181
) ;
181
- log . info ( 'Active editor path' , editor ?. document . uri ?. path ) ;
182
+ log . info ( 'Active editor' , {
183
+ documentPath : editor ?. document . uri ?. path ,
184
+ documentLanguageId : editor ?. document . languageId ,
185
+ } ) ;
182
186
}
183
187
} ;
184
188
@@ -245,35 +249,24 @@ export default class PlaygroundController {
245
249
) ;
246
250
}
247
251
248
- async _connectToServiceProvider ( ) : Promise < void > {
249
- // Disconnect if already connected.
250
- await this . _languageServerController . disconnectFromServiceProvider ( ) ;
251
-
252
+ async _activeConnectionChanged ( ) : Promise < void > {
252
253
const dataService = this . _connectionController . getActiveDataService ( ) ;
253
254
const connectionId = this . _connectionController . getActiveConnectionId ( ) ;
255
+ let mongoClientOption ;
254
256
255
- if ( ! dataService || ! connectionId ) {
256
- this . _activeConnectionCodeLensProvider . refresh ( ) ;
257
-
258
- return ;
259
- }
260
-
261
- const mongoClientOption =
262
- this . _connectionController . getMongoClientConnectionOptions ( ) ;
263
-
264
- if ( ! mongoClientOption ) {
265
- this . _activeConnectionCodeLensProvider . refresh ( ) ;
257
+ this . _activeConnectionCodeLensProvider . refresh ( ) ;
266
258
267
- return ;
259
+ if ( dataService && connectionId ) {
260
+ mongoClientOption =
261
+ this . _connectionController . getMongoClientConnectionOptions ( ) ;
268
262
}
269
263
270
- await this . _languageServerController . connectToServiceProvider ( {
264
+ // The connectionId is null when disconnecting.
265
+ await this . _languageServerController . activeConnectionChanged ( {
271
266
connectionId,
272
- connectionString : mongoClientOption . url ,
273
- connectionOptions : mongoClientOption . options ,
267
+ connectionString : mongoClientOption ? .url ,
268
+ connectionOptions : mongoClientOption ? .options ,
274
269
} ) ;
275
-
276
- this . _activeConnectionCodeLensProvider . refresh ( ) ;
277
270
}
278
271
279
272
async _createPlaygroundFileWithContent (
@@ -420,36 +413,28 @@ export default class PlaygroundController {
420
413
421
414
this . _statusView . showMessage ( 'Getting results...' ) ;
422
415
416
+ let result : ShellEvaluateResult ;
423
417
try {
424
418
// Send a request to the language server to execute scripts from a playground.
425
- const result : ShellEvaluateResult =
426
- await this . _languageServerController . evaluate ( {
427
- codeToEvaluate,
428
- connectionId,
429
- } ) ;
430
-
431
- this . _statusView . hideMessage ( ) ;
432
- this . _telemetryService . trackPlaygroundCodeExecuted (
433
- result ,
434
- this . _isPartialRun ,
435
- result ? false : true
436
- ) ;
437
-
438
- return result ;
439
- } catch ( err : any ) {
440
- // We re-initialize the language server when we encounter an error.
441
- // This happens when the language server worker runs out of memory, can't be revitalized, and restarts.
442
- if ( err ?. code === - 32097 ) {
443
- void vscode . window . showErrorMessage (
444
- 'An error occurred when running the playground. This can occur when the playground runner runs out of memory.'
445
- ) ;
419
+ result = await this . _languageServerController . evaluate ( {
420
+ codeToEvaluate,
421
+ connectionId,
422
+ } ) ;
423
+ } catch ( error ) {
424
+ const msg =
425
+ 'An internal error has occurred. The playground services have been restored. This can occur when the playground runner runs out of memory.' ;
426
+ log . error ( msg , error ) ;
427
+ void vscode . window . showErrorMessage ( msg ) ;
428
+ }
446
429
447
- await this . _languageServerController . startLanguageServer ( ) ;
448
- void this . _connectToServiceProvider ( ) ;
449
- }
430
+ this . _statusView . hideMessage ( ) ;
431
+ this . _telemetryService . trackPlaygroundCodeExecuted (
432
+ result ,
433
+ this . _isPartialRun ,
434
+ result ? false : true
435
+ ) ;
450
436
451
- throw err ;
452
- }
437
+ return result ;
453
438
}
454
439
455
440
_getAllText ( ) : string {
0 commit comments