@@ -204,13 +204,22 @@ class MongoshNodeRepl implements EvaluationListener {
204
204
if ( mongoshResultsExclusive ) {
205
205
return [ mongoshResults , text ] ;
206
206
}
207
+
208
+ // The REPL completer may not complete the entire string; for example,
209
+ // when completing ".ed" to ".editor", it reports as having completed
210
+ // only the last piece ("ed"), or when completing "{ $g", it completes
211
+ // only "$g" and not the entire result.
212
+ // The mongosh completer always completes on the entire string.
213
+ // In order to align them, we always extend the REPL results to include
214
+ // the full string prefix.
215
+ const replResultPrefix = replOrig ? text . substr ( 0 , text . lastIndexOf ( replOrig ) ) : '' ;
216
+ const longReplResults = replResults . map ( ( result : string ) => replResultPrefix + result ) ;
217
+
207
218
// Remove duplicates, because shell API methods might otherwise show
208
219
// up in both completions.
209
- const deduped = [ ...new Set ( [ ...replResults , ...mongoshResults ] ) ] ;
220
+ const deduped = [ ...new Set ( [ ...longReplResults , ...mongoshResults ] ) ] ;
210
221
211
- // Use the REPL completer's original text when available, because that
212
- // makes a difference for completion of REPL commands like `.editor`.
213
- return [ deduped , replOrig ?? text ] ;
222
+ return [ deduped , text ] ;
214
223
} finally {
215
224
this . insideAutoCompleteOrGetPrompt = false ;
216
225
}
0 commit comments