From f93bcfa751cefa5c4b5f5756f1e0c0128bc2c102 Mon Sep 17 00:00:00 2001 From: pulkitkalra-mdb <156152710+pulkitkalra-mdb@users.noreply.github.com> Date: Fri, 19 Apr 2024 22:45:32 +1000 Subject: [PATCH] feat(autocomplete): add autocomplete for streams commands MONGOSH-1661 --- packages/autocomplete/src/index.spec.ts | 18 ++++++++++++++++++ packages/autocomplete/src/index.ts | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/packages/autocomplete/src/index.spec.ts b/packages/autocomplete/src/index.spec.ts index fc9eb1ea8..1e267737e 100644 --- a/packages/autocomplete/src/index.spec.ts +++ b/packages/autocomplete/src/index.spec.ts @@ -836,4 +836,22 @@ describe('completer.completer', function () { expect(await completer(apiStrictParams, i)).to.deep.equal([[], i]); }); }); + + context('with stream processing sp', function () { + it('completes supported methods sp.listStreamProcessor', async function () { + const i = 'sp.listS'; + expect(await completer(apiStrictParams, i)).to.deep.equal([ + ['sp.listStreamProcessors'], + i, + ]); + }); + + it('completes methods on processors like sp.name.drop', async function () { + const i = 'sp.processorName.d'; + expect(await completer(apiStrictParams, i)).to.deep.equal([ + ['sp.processorName.drop'], + i, + ]); + }); + }); }); diff --git a/packages/autocomplete/src/index.ts b/packages/autocomplete/src/index.ts index 00ca0f50f..17dcbca71 100644 --- a/packages/autocomplete/src/index.ts +++ b/packages/autocomplete/src/index.ts @@ -98,6 +98,10 @@ async function completer( .attributes as TypeSignatureAttributes; const SHARD_COMPLETE = shellSignatures.Shard .attributes as TypeSignatureAttributes; + const SP_COMPLETIONS = shellSignatures.Streams + .attributes as TypeSignatureAttributes; + const SP_INSTANCE_COMPLETIONS = shellSignatures.StreamProcessor + .attributes as TypeSignatureAttributes; // Split at space-to-non-space transitions when looking at this as a command, // because multiple spaces (e.g. 'show collections') are valid in commands. @@ -265,6 +269,20 @@ async function completer( splitLine ); return [hits.length ? hits : [], line]; + } else if (/\bsp\b/.exec(firstLineEl)) { + let expressions: TypeSignatureAttributes | undefined; + if (splitLine.length === 2) { + expressions = SP_COMPLETIONS; + } else if (splitLine.length === 3) { + // something like sp.spName.start() + expressions = SP_INSTANCE_COMPLETIONS; + } + + const hits = + expressions && + filterShellAPI(params, expressions, elToComplete, splitLine); + + return [hits?.length ? hits : [], line]; } return [[], line];