Skip to content

Commit 720728d

Browse files
authored
fix(mongosh-repl): fix REPL command completion MONGOSH-778 (#891)
1 parent 2305c75 commit 720728d

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

packages/cli-repl/src/mongosh-repl.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,20 @@ describe('MongoshNodeRepl', () => {
352352
await tick();
353353
expect(output).to.include('somelongvariable');
354354
});
355+
it('autocompletes partial repl commands', async() => {
356+
input.write('.e');
357+
await tabtab();
358+
await tick();
359+
expect(output).to.include('editor');
360+
expect(output).to.include('exit');
361+
});
362+
it('autocompletes full repl commands', async() => {
363+
input.write('.ed');
364+
await tabtab();
365+
await tick();
366+
expect(output).to.include('.editor');
367+
expect(output).not.to.include('exit');
368+
});
355369
it('autocompletion during .editor does not reset the prompt', async() => {
356370
input.write('.editor\n');
357371
await tick();

packages/cli-repl/src/mongosh-repl.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class MongoshNodeRepl implements EvaluationListener {
189189
this.insideAutoCompleteOrGetPrompt = true;
190190
try {
191191
// Merge the results from the repl completer and the mongosh completer.
192-
const [ [replResults], [mongoshResults,, mongoshResultsExclusive] ] = await Promise.all([
192+
const [ [replResults, replOrig], [mongoshResults,, mongoshResultsExclusive] ] = await Promise.all([
193193
(async() => await origReplCompleter(text) || [[]])(),
194194
(async() => await mongoshCompleter(text))()
195195
]);
@@ -205,7 +205,10 @@ class MongoshNodeRepl implements EvaluationListener {
205205
// Remove duplicates, because shell API methods might otherwise show
206206
// up in both completions.
207207
const deduped = [...new Set([...replResults, ...mongoshResults])];
208-
return [deduped, text];
208+
209+
// Use the REPL completer's original text when available, because that
210+
// makes a difference for completion of REPL commands like `.editor`.
211+
return [deduped, replOrig ?? text];
209212
} finally {
210213
this.insideAutoCompleteOrGetPrompt = false;
211214
}

0 commit comments

Comments
 (0)