diff --git a/packages/cli-repl/src/mongosh-repl.spec.ts b/packages/cli-repl/src/mongosh-repl.spec.ts index 15fdf8b506..c7a099c31e 100644 --- a/packages/cli-repl/src/mongosh-repl.spec.ts +++ b/packages/cli-repl/src/mongosh-repl.spec.ts @@ -352,6 +352,20 @@ describe('MongoshNodeRepl', () => { await tick(); expect(output).to.include('somelongvariable'); }); + it('autocompletes partial repl commands', async() => { + input.write('.e'); + await tabtab(); + await tick(); + expect(output).to.include('editor'); + expect(output).to.include('exit'); + }); + it('autocompletes full repl commands', async() => { + input.write('.ed'); + await tabtab(); + await tick(); + expect(output).to.include('.editor'); + expect(output).not.to.include('exit'); + }); it('autocompletion during .editor does not reset the prompt', async() => { input.write('.editor\n'); await tick(); diff --git a/packages/cli-repl/src/mongosh-repl.ts b/packages/cli-repl/src/mongosh-repl.ts index ebd9e0d564..6f3b804947 100644 --- a/packages/cli-repl/src/mongosh-repl.ts +++ b/packages/cli-repl/src/mongosh-repl.ts @@ -185,7 +185,7 @@ class MongoshNodeRepl implements EvaluationListener { this.insideAutoCompleteOrGetPrompt = true; try { // Merge the results from the repl completer and the mongosh completer. - const [ [replResults], [mongoshResults,, mongoshResultsExclusive] ] = await Promise.all([ + const [ [replResults, replOrig], [mongoshResults,, mongoshResultsExclusive] ] = await Promise.all([ (async() => await origReplCompleter(text) || [[]])(), (async() => await mongoshCompleter(text))() ]); @@ -201,7 +201,10 @@ class MongoshNodeRepl implements EvaluationListener { // Remove duplicates, because shell API methods might otherwise show // up in both completions. const deduped = [...new Set([...replResults, ...mongoshResults])]; - return [deduped, text]; + + // Use the REPL completer's original text when available, because that + // makes a difference for completion of REPL commands like `.editor`. + return [deduped, replOrig ?? text]; } finally { this.insideAutoCompleteOrGetPrompt = false; }