Skip to content

Commit

Permalink
feat(autocomplete): add autocomplete for streams commands MONGOSH-1661
Browse files Browse the repository at this point in the history
  • Loading branch information
pulkitkalra-mdb authored Apr 19, 2024
1 parent 838e189 commit f93bcfa
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/autocomplete/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
});
});
});
18 changes: 18 additions & 0 deletions packages/autocomplete/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit f93bcfa

Please sign in to comment.