diff --git a/packages/cli-repl/src/cli-repl.spec.ts b/packages/cli-repl/src/cli-repl.spec.ts index d01b3aeb10..f4a8fdd935 100644 --- a/packages/cli-repl/src/cli-repl.spec.ts +++ b/packages/cli-repl/src/cli-repl.spec.ts @@ -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'); + }); }); } }); diff --git a/packages/cli-repl/src/mongosh-repl.ts b/packages/cli-repl/src/mongosh-repl.ts index baa4750fb6..a72daa958b 100644 --- a/packages/cli-repl/src/mongosh-repl.ts +++ b/packages/cli-repl/src/mongosh-repl.ts @@ -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));