@@ -9,6 +9,7 @@ import PartialExecutionCodeLensProvider from './partialExecutionCodeLensProvider
9
9
import { OutputChannel , ProgressLocation , TextEditor } from 'vscode' ;
10
10
import playgroundTemplate from '../templates/playgroundTemplate' ;
11
11
import playgroundSearchTemplate from '../templates/playgroundSearchTemplate' ;
12
+ import playgroundCreateIndexTemplate from '../templates/playgroundCreateIndexTemplate' ;
12
13
import { createLogger } from '../logging' ;
13
14
14
15
const log = createLogger ( 'playground controller' ) ;
@@ -96,7 +97,7 @@ export default class PlaygroundController {
96
97
editor . textEditor . document &&
97
98
editor . textEditor . document . languageId === 'mongodb'
98
99
) {
99
- this . _selectedText = ( editor . selections as Array < any > )
100
+ this . _selectedText = ( editor . selections as Array < vscode . Selection > )
100
101
. sort ( ( a , b ) => ( a . start . line > b . start . line ? 1 : - 1 ) ) // Sort lines selected as alt+click
101
102
. map ( ( item , index ) => {
102
103
if ( index === editor . selections . length - 1 ) {
@@ -153,15 +154,10 @@ export default class PlaygroundController {
153
154
return this . _languageServerController . disconnectFromServiceProvider ( ) ;
154
155
}
155
156
156
- public createPlaygroundForSearch (
157
- databaseName : string ,
158
- collectionName : string
157
+ private createPlaygroundFileWithContent (
158
+ content : string | undefined
159
159
) : Promise < boolean > {
160
160
return new Promise ( ( resolve , reject ) => {
161
- const content = playgroundSearchTemplate
162
- . replace ( 'CURRENT_DATABASE' , databaseName )
163
- . replace ( 'CURRENT_COLLECTION' , collectionName ) ;
164
-
165
161
vscode . workspace
166
162
. openTextDocument ( {
167
163
language : 'mongodb' ,
@@ -175,6 +171,28 @@ export default class PlaygroundController {
175
171
} ) ;
176
172
}
177
173
174
+ public createPlaygroundForSearch (
175
+ databaseName : string ,
176
+ collectionName : string
177
+ ) : Promise < boolean > {
178
+ const content = playgroundSearchTemplate
179
+ . replace ( 'CURRENT_DATABASE' , databaseName )
180
+ . replace ( 'CURRENT_COLLECTION' , collectionName ) ;
181
+
182
+ return this . createPlaygroundFileWithContent ( content ) ;
183
+ }
184
+
185
+ public createPlaygroundForNewIndex (
186
+ databaseName : string ,
187
+ collectionName : string
188
+ ) : Promise < boolean > {
189
+ const content = playgroundCreateIndexTemplate
190
+ . replace ( 'CURRENT_DATABASE' , databaseName )
191
+ . replace ( 'CURRENT_COLLECTION' , collectionName ) ;
192
+
193
+ return this . createPlaygroundFileWithContent ( content ) ;
194
+ }
195
+
178
196
public createPlayground ( ) : Promise < boolean > {
179
197
const useDefaultTemplate = ! ! vscode . workspace
180
198
. getConfiguration ( 'mdb' )
@@ -214,7 +232,7 @@ export default class PlaygroundController {
214
232
return this . _activeTextEditor ?. document . getText ( ) || '' ;
215
233
}
216
234
217
- private getSelectedText ( selection : any ) : string {
235
+ private getSelectedText ( selection : vscode . Range ) : string {
218
236
return this . _activeTextEditor ?. document . getText ( selection ) || '' ;
219
237
}
220
238
@@ -234,7 +252,7 @@ export default class PlaygroundController {
234
252
cancellable : true
235
253
} ,
236
254
async ( progress , token ) => {
237
- token . onCancellationRequested ( async ( ) => {
255
+ token . onCancellationRequested ( ( ) => {
238
256
// If a user clicked the cancel button terminate all playground scripts.
239
257
this . _languageServerController . cancelAll ( ) ;
240
258
this . _outputChannel . clear ( ) ;
@@ -301,7 +319,7 @@ export default class PlaygroundController {
301
319
} ) ;
302
320
}
303
321
304
- public runSelectedPlaygroundBlocks ( ) {
322
+ public runSelectedPlaygroundBlocks ( ) : Promise < boolean > {
305
323
if ( this . _activeTextEditor && this . _activeTextEditor . document ) {
306
324
const selections = this . _activeTextEditor . selections ;
307
325
@@ -324,7 +342,7 @@ export default class PlaygroundController {
324
342
return this . evaluatePlayground ( ) ;
325
343
}
326
344
327
- public runAllPlaygroundBlocks ( ) {
345
+ public runAllPlaygroundBlocks ( ) : Promise < boolean > {
328
346
if ( this . _activeTextEditor ) {
329
347
this . _isPartialRun = false ;
330
348
this . _codeToEvaluate = this . getAllText ( ) ;
@@ -333,7 +351,7 @@ export default class PlaygroundController {
333
351
return this . evaluatePlayground ( ) ;
334
352
}
335
353
336
- public runAllOrSelectedPlaygroundBlocks ( ) {
354
+ public runAllOrSelectedPlaygroundBlocks ( ) : Promise < boolean > {
337
355
if ( this . _activeTextEditor && this . _activeTextEditor . document ) {
338
356
const selections = this . _activeTextEditor . selections ;
339
357
0 commit comments