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
7 changes: 7 additions & 0 deletions packages/cli-repl/src/cli-repl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,13 @@ describe('CliRepl', () => {
await waitCompletion(cliRepl.bus);
expect(output).to.include('use admin');
});

it('completes query operators', async() => {
input.write('db.movies.find({year: {$g');
await tabtab();
await waitCompletion(cliRepl.bus);
expect(output).to.include('db.movies.find({year: {$gte');
});
});
}
});
Expand Down
17 changes: 13 additions & 4 deletions packages/cli-repl/src/mongosh-repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,22 @@ class MongoshNodeRepl implements EvaluationListener {
if (mongoshResultsExclusive) {
return [mongoshResults, text];
}

// The REPL completer may not complete the entire string; for example,
// when completing ".ed" to ".editor", it reports as having completed
// only the last piece ("ed"), or when completing "{ $g", it completes
// only "$g" and not the entire result.
// The mongosh completer always completes on the entire string.
// In order to align them, we always extend the REPL results to include
// the full string prefix.
const replResultPrefix = replOrig ? text.substr(0, text.lastIndexOf(replOrig)) : '';
const longReplResults = replResults.map((result: string) => replResultPrefix + result);

// Remove duplicates, because shell API methods might otherwise show
// up in both completions.
const deduped = [...new Set([...replResults, ...mongoshResults])];
const deduped = [...new Set([...longReplResults, ...mongoshResults])];

// 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];
return [deduped, text];
} finally {
this.insideAutoCompleteOrGetPrompt = false;
}
Expand Down