diff --git a/packages/autocomplete/index.spec.ts b/packages/autocomplete/index.spec.ts index 22b474805f..3630dfe8f0 100644 --- a/packages/autocomplete/index.spec.ts +++ b/packages/autocomplete/index.spec.ts @@ -533,5 +533,11 @@ describe('completer.completer', () => { expect(await completer(noParams, i)) .to.deep.equal([['exit'], i]); }); + + it('completes with multiple spaces', async() => { + const i = 'show datab'; + expect(await completer(noParams, i)) + .to.deep.equal([['show databases'], i, 'exclusive']); + }); }); }); diff --git a/packages/autocomplete/index.ts b/packages/autocomplete/index.ts index 12956f0efd..1735dad66e 100644 --- a/packages/autocomplete/index.ts +++ b/packages/autocomplete/index.ts @@ -61,21 +61,26 @@ async function completer(params: AutocompleteParameters, line: string): Promise< const CONFIG_COMPLETIONS = shellSignatures.ShellConfig.attributes as TypeSignatureAttributes; const SHARD_COMPLETE = shellSignatures.Shard.attributes as TypeSignatureAttributes; - const splitLineWhitespace = line.split(' '); - const command = splitLineWhitespace[0]; + // 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. + // This split keeps the spaces intact so we can join them back later. + const splitLineWhitespace = line.split(/(? item.trim())) || []; // Adjust to full input, because `completer` only completed the last item // in the line, e.g. ['profile'] -> ['show profile'] - const fullLineHits = hits.map(hit => [...splitLineWhitespace.slice(0, -1), hit].join(' ')); + const fullLineHits = hits.map(hit => [...splitLineWhitespace.slice(0, -1), hit].join('')); return [fullLineHits, line, 'exclusive']; } return [[line], line, 'exclusive'];