@@ -65,6 +65,7 @@ class MongoshNodeRepl implements EvaluationListener {
65
65
shellCliOptions : Partial < MongoshCliOptions > ;
66
66
configProvider : MongoshConfigProvider ;
67
67
onClearCommand ?: EvaluationListener [ 'onClearCommand' ] ;
68
+ insideAutoComplete : boolean ;
68
69
69
70
constructor ( options : MongoshNodeReplOptions ) {
70
71
this . input = options . input ;
@@ -74,6 +75,7 @@ class MongoshNodeRepl implements EvaluationListener {
74
75
this . nodeReplOptions = options . nodeReplOptions || { } ;
75
76
this . shellCliOptions = options . shellCliOptions || { } ;
76
77
this . configProvider = options . configProvider ;
78
+ this . insideAutoComplete = false ;
77
79
this . _runtimeState = null ;
78
80
}
79
81
@@ -123,16 +125,21 @@ class MongoshNodeRepl implements EvaluationListener {
123
125
completer . bind ( null , internalState . getAutocompleteParameters ( ) ) ;
124
126
( repl as Mutable < typeof repl > ) . completer =
125
127
callbackify ( async ( text : string ) : Promise < [ string [ ] , string ] > => {
126
- // Merge the results from the repl completer and the mongosh completer.
127
- const [ [ replResults ] , [ mongoshResults ] ] = await Promise . all ( [
128
- ( async ( ) => await origReplCompleter ( text ) || [ [ ] ] ) ( ) ,
129
- ( async ( ) => await mongoshCompleter ( text ) ) ( )
130
- ] ) ;
131
- this . bus . emit ( 'mongosh:autocompletion-complete' ) ; // For testing.
132
- // Remove duplicates, because shell API methods might otherwise show
133
- // up in both completions.
134
- const deduped = [ ...new Set ( [ ...replResults , ...mongoshResults ] ) ] ;
135
- return [ deduped , text ] ;
128
+ this . insideAutoComplete = true ;
129
+ try {
130
+ // Merge the results from the repl completer and the mongosh completer.
131
+ const [ [ replResults ] , [ mongoshResults ] ] = await Promise . all ( [
132
+ ( async ( ) => await origReplCompleter ( text ) || [ [ ] ] ) ( ) ,
133
+ ( async ( ) => await mongoshCompleter ( text ) ) ( )
134
+ ] ) ;
135
+ this . bus . emit ( 'mongosh:autocompletion-complete' ) ; // For testing.
136
+ // Remove duplicates, because shell API methods might otherwise show
137
+ // up in both completions.
138
+ const deduped = [ ...new Set ( [ ...replResults , ...mongoshResults ] ) ] ;
139
+ return [ deduped , text ] ;
140
+ } finally {
141
+ this . insideAutoComplete = false ;
142
+ }
136
143
} ) ;
137
144
138
145
const originalDisplayPrompt = repl . displayPrompt . bind ( repl ) ;
@@ -284,13 +291,18 @@ class MongoshNodeRepl implements EvaluationListener {
284
291
}
285
292
286
293
async eval ( originalEval : asyncRepl . OriginalEvalFunction , input : string , context : any , filename : string ) : Promise < any > {
287
- this . lineByLineInput . enableBlockOnNewLine ( ) ;
294
+ if ( ! this . insideAutoComplete ) {
295
+ this . lineByLineInput . enableBlockOnNewLine ( ) ;
296
+ }
297
+
288
298
const { internalState, repl, shellEvaluator } = this . runtimeState ( ) ;
289
299
290
300
try {
291
301
return await shellEvaluator . customEval ( originalEval , input , context , filename ) ;
292
302
} finally {
293
- repl . setPrompt ( await this . getShellPrompt ( internalState ) ) ;
303
+ if ( ! this . insideAutoComplete ) {
304
+ repl . setPrompt ( await this . getShellPrompt ( internalState ) ) ;
305
+ }
294
306
this . bus . emit ( 'mongosh:eval-complete' ) ; // For testing purposes.
295
307
}
296
308
}
0 commit comments