@@ -80,13 +80,9 @@ export default class PlaygroundController {
80
80
) ;
81
81
82
82
vscode . window . onDidChangeActiveTextEditor ( ( editor ) => {
83
- if (
84
- editor &&
85
- editor . document &&
86
- editor . document . languageId === 'mongodb'
87
- ) {
83
+ if ( editor ?. document . languageId !== 'Log' ) {
88
84
this . _activeTextEditor = editor ;
89
- log . info ( 'Active editor path' , editor . document . uri ?. path ) ;
85
+ log . info ( 'Active editor path' , editor ? .document . uri ?. path ) ;
90
86
}
91
87
} ) ;
92
88
@@ -320,52 +316,79 @@ export default class PlaygroundController {
320
316
}
321
317
322
318
public runSelectedPlaygroundBlocks ( ) : Promise < boolean > {
323
- if ( this . _activeTextEditor && this . _activeTextEditor . document ) {
324
- const selections = this . _activeTextEditor . selections ;
319
+ if (
320
+ ! this . _activeTextEditor ||
321
+ this . _activeTextEditor . document . languageId !== 'mongodb'
322
+ ) {
323
+ vscode . window . showErrorMessage (
324
+ `Please open a '.mongodb' playground file before running it.`
325
+ ) ;
325
326
326
- if (
327
- ! selections ||
328
- ! Array . isArray ( selections ) ||
329
- ( selections . length === 1 && this . getSelectedText ( selections [ 0 ] ) === '' )
330
- ) {
331
- vscode . window . showInformationMessage (
332
- 'Please select one or more lines in the playground.'
333
- ) ;
327
+ return Promise . resolve ( false ) ;
328
+ }
334
329
335
- return Promise . resolve ( true ) ;
336
- } else if ( this . _selectedText ) {
337
- this . _isPartialRun = true ;
338
- this . _codeToEvaluate = this . _selectedText ;
339
- }
330
+ const selections = this . _activeTextEditor . selections ;
331
+
332
+ if (
333
+ ! selections ||
334
+ ! Array . isArray ( selections ) ||
335
+ ( selections . length === 1 && this . getSelectedText ( selections [ 0 ] ) === '' )
336
+ ) {
337
+ vscode . window . showInformationMessage (
338
+ 'Please select one or more lines in the playground.'
339
+ ) ;
340
+
341
+ return Promise . resolve ( true ) ;
342
+ } else if ( this . _selectedText ) {
343
+ this . _isPartialRun = true ;
344
+ this . _codeToEvaluate = this . _selectedText ;
340
345
}
341
346
342
347
return this . evaluatePlayground ( ) ;
343
348
}
344
349
345
350
public runAllPlaygroundBlocks ( ) : Promise < boolean > {
346
- if ( this . _activeTextEditor ) {
347
- this . _isPartialRun = false ;
348
- this . _codeToEvaluate = this . getAllText ( ) ;
351
+ if (
352
+ ! this . _activeTextEditor ||
353
+ this . _activeTextEditor . document . languageId !== 'mongodb'
354
+ ) {
355
+ vscode . window . showErrorMessage (
356
+ `Please open a '.mongodb' playground file before running it.`
357
+ ) ;
358
+
359
+ return Promise . resolve ( false ) ;
349
360
}
350
361
362
+ this . _isPartialRun = false ;
363
+ this . _codeToEvaluate = this . getAllText ( ) ;
364
+
351
365
return this . evaluatePlayground ( ) ;
352
366
}
353
367
354
368
public runAllOrSelectedPlaygroundBlocks ( ) : Promise < boolean > {
355
- if ( this . _activeTextEditor && this . _activeTextEditor . document ) {
356
- const selections = this . _activeTextEditor . selections ;
369
+ if (
370
+ ! this . _activeTextEditor ||
371
+ this . _activeTextEditor . document . languageId !== 'mongodb'
372
+ ) {
373
+ vscode . window . showErrorMessage (
374
+ `Please open a '.mongodb' playground file before running it.`
375
+ ) ;
357
376
358
- if (
359
- ! selections ||
360
- ! Array . isArray ( selections ) ||
361
- ( selections . length === 1 && this . getSelectedText ( selections [ 0 ] ) === '' )
362
- ) {
363
- this . _isPartialRun = false ;
364
- this . _codeToEvaluate = this . getAllText ( ) ;
365
- } else if ( this . _selectedText ) {
366
- this . _isPartialRun = true ;
367
- this . _codeToEvaluate = this . _selectedText ;
368
- }
377
+ return Promise . resolve ( false ) ;
378
+ }
379
+
380
+ const selections = this . _activeTextEditor . selections ;
381
+
382
+ if (
383
+ ! selections ||
384
+ ! Array . isArray ( selections ) ||
385
+ ( selections . length === 1 && this . getSelectedText ( selections [ 0 ] ) === '' )
386
+ ) {
387
+ this . _isPartialRun = false ;
388
+ this . _codeToEvaluate = this . getAllText ( ) ;
389
+ } else if ( this . _selectedText ) {
390
+ this . _isPartialRun = true ;
391
+ this . _codeToEvaluate = this . _selectedText ;
369
392
}
370
393
371
394
return this . evaluatePlayground ( ) ;
0 commit comments