Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/cli-repl/src/mongosh-repl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,20 @@ describe('MongoshNodeRepl', () => {
await tick();
expect(output).to.include('somelongvariable');
});
it('autocompletes partial repl commands', async() => {
input.write('.e');
await tabtab();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't noticed these helpers before, nice method names 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They haven’t been around for too long, but @mcasimir’s brought this up as an idea during PR review :)

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();
Expand Down
7 changes: 5 additions & 2 deletions packages/cli-repl/src/mongosh-repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))()
]);
Expand All @@ -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;
}
Expand Down