Skip to content

Commit bfb2bef

Browse files
authored
fix(cli-repl): properly autocomplete JS value properties MONGOSH-598 (#687)
1 parent e75aa21 commit bfb2bef

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,13 @@ describe('CliRepl', () => {
513513
input.write(`db.${collname}.drop()\n`);
514514
await waitEval(cliRepl.bus);
515515
});
516+
517+
it('completes JS value properties properly', async() => {
518+
input.write('JSON.\u0009\u0009');
519+
await waitCompletion(cliRepl.bus);
520+
expect(output).to.include('JSON.parse');
521+
expect(output).not.to.include('rawValue');
522+
});
516523
});
517524
}
518525
});

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,16 @@ class MongoshNodeRepl implements EvaluationListener {
298298
const { internalState, repl, shellEvaluator } = this.runtimeState();
299299

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

0 commit comments

Comments
 (0)