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 @@ -513,6 +513,13 @@ describe('CliRepl', () => {
input.write(`db.${collname}.drop()\n`);
await waitEval(cliRepl.bus);
});

it('completes JS value properties properly', async() => {
input.write('JSON.\u0009\u0009');
await waitCompletion(cliRepl.bus);
expect(output).to.include('JSON.parse');
expect(output).not.to.include('rawValue');
});
});
}
});
Expand Down
11 changes: 10 additions & 1 deletion packages/cli-repl/src/mongosh-repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,16 @@ class MongoshNodeRepl implements EvaluationListener {
const { internalState, repl, shellEvaluator } = this.runtimeState();

try {
return await shellEvaluator.customEval(originalEval, input, context, filename);
const shellResult = await shellEvaluator.customEval(originalEval, input, context, filename);
if (!this.insideAutoComplete) {
return shellResult;
}
// The Node.js auto completion needs to access the raw values in order
// to be able to autocomplete their properties properly. One catch is
// that we peform some filtering of mongosh methods depending on
// topology, server version, etc., so for those, we do not autocomplete
// at all and instead leave that to the @mongosh/autocomplete package.
return shellResult.type !== null ? null : shellResult.rawValue;
} finally {
if (!this.insideAutoComplete) {
repl.setPrompt(await this.getShellPrompt(internalState));
Expand Down