1- import completer from '@mongosh/autocomplete' ;
1+ import type { CompletionResults } from '@mongosh/autocomplete' ;
2+ import { completer , initNewAutocompleter } from '@mongosh/autocomplete' ;
23import { MongoshInternalError , MongoshWarning } from '@mongosh/errors' ;
34import { changeHistory } from '@mongosh/history' ;
45import type {
@@ -49,8 +50,6 @@ import { Script, createContext, runInContext } from 'vm';
4950import { installPasteSupport } from './repl-paste-support' ;
5051import util from 'util' ;
5152
52- import type { MongoDBAutocompleter } from '@mongodb-js/mongodb-ts-autocomplete' ;
53-
5453declare const __non_webpack_require__ : any ;
5554
5655/**
@@ -133,13 +132,6 @@ type Mutable<T> = {
133132 - readonly [ P in keyof T ] : T [ P ] ;
134133} ;
135134
136- function transformAutocompleteResults (
137- line : string ,
138- results : { result : string } [ ]
139- ) : [ string [ ] , string ] {
140- return [ results . map ( ( result ) => result . result ) , line ] ;
141- }
142-
143135/**
144136 * An instance of a `mongosh` REPL, without any of the actual I/O.
145137 * Specifically, code called by this class should not do any
@@ -440,18 +432,14 @@ class MongoshNodeRepl implements EvaluationListener {
440432
441433 const origReplCompleter = promisify ( repl . completer . bind ( repl ) ) ; // repl.completer is callback-style
442434
443- let newMongoshCompleter : MongoDBAutocompleter | undefined ;
444- let oldMongoshCompleter : (
445- line : string
446- ) => Promise < [ string [ ] , string , 'exclusive' ] | [ string [ ] , string ] > ;
435+ let newMongoshCompleter : ( line : string ) => Promise < CompletionResults > ;
436+ let oldMongoshCompleter : ( line : string ) => Promise < CompletionResults > ;
447437
448438 if ( process . env . USE_NEW_AUTOCOMPLETE ) {
449439 // we will lazily instantiate the new autocompleter on first use
450440 } else {
451- oldMongoshCompleter = completer . bind (
452- null ,
453- instanceState . getAutocompleteParameters ( )
454- ) ;
441+ const autocompleteParams = instanceState . getAutocompleteParameters ( ) ;
442+ oldMongoshCompleter = completer . bind ( null , autocompleteParams ) ;
455443 }
456444
457445 const innerCompleter = async (
@@ -469,22 +457,10 @@ class MongoshNodeRepl implements EvaluationListener {
469457 ( async ( ) => {
470458 if ( process . env . USE_NEW_AUTOCOMPLETE ) {
471459 if ( ! newMongoshCompleter ) {
472- // only import the autocompleter code the first time we need it to
473- // hide the time it takes from the initial startup time
474- const { MongoDBAutocompleter } = await import (
475- '@mongodb-js/mongodb-ts-autocomplete'
476- ) ;
477-
478- const autocompletionContext =
479- instanceState . getAutocompletionContext ( ) ;
480- newMongoshCompleter = new MongoDBAutocompleter ( {
481- context : autocompletionContext ,
482- } ) ;
460+ newMongoshCompleter = await initNewAutocompleter ( instanceState ) ;
483461 }
484462
485- const results = await newMongoshCompleter . autocomplete ( text ) ;
486- const transformed = transformAutocompleteResults ( text , results ) ;
487- return transformed ;
463+ return newMongoshCompleter ( text ) ;
488464 } else {
489465 return oldMongoshCompleter ( text ) ;
490466 }
0 commit comments