Skip to content

Commit

Permalink
fix(autocomplete): do not act as if input is completion MONGOSH-646 (#…
Browse files Browse the repository at this point in the history
…735)

Passing back the input as a possible completion would prevent
single-tab autocompletion in the shell.
  • Loading branch information
addaleax committed Mar 22, 2021
1 parent f393348 commit 81ff5a5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/autocomplete/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ describe('completer.completer', () => {

it('does not provide anything if there is a function call instead of a collection name', async() => {
const i = 'db.getMongo().find';
expect(await completer(standalone440, i)).to.deep.equal([[i], i]);
expect(await completer(standalone440, i)).to.deep.equal([[], i]);
});

it('provides results if the function call is getCollection', async() => {
Expand Down Expand Up @@ -479,7 +479,7 @@ describe('completer.completer', () => {

it('does not match if it is not .find or .aggregate', async() => {
const i = 'db.shipwrecks.moo({feature_type: "Wrecks - Visible"}).';
expect(await completer(standalone440, i)).to.deep.equal([[i], i]);
expect(await completer(standalone440, i)).to.deep.equal([[], i]);
});
});
});
6 changes: 3 additions & 3 deletions packages/autocomplete/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async function completer(params: AutocompleteParameters, line: string): Promise<
// alphanumeric character. This could be a function call, for example.
// In any case, we can't currently provide reasonable autocompletion
// suggestions for this.
return [[line], line];
return [[], line];
}

if (splitLine.length > 3) {
Expand All @@ -99,7 +99,7 @@ async function completer(params: AutocompleteParameters, line: string): Promise<
return [hits.length ? hits : [], line];
}
// This is something else, and we currently don't know what this is.
return [[line], line];
return [[], line];
}

// complete aggregation and collection queries/stages
Expand Down Expand Up @@ -134,7 +134,7 @@ async function completer(params: AutocompleteParameters, line: string): Promise<
return [hits.length ? hits : [], line];
}

return [[line], line];
return [[], line];
}

function isAcceptable(
Expand Down
11 changes: 10 additions & 1 deletion packages/cli-repl/src/cli-repl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -821,10 +821,19 @@ describe('CliRepl', () => {
await waitEval(cliRepl.bus);
});

it('completes JS value properties properly', async() => {
it('completes JS value properties properly (incomplete, double tab)', async() => {
input.write('JSON.\u0009\u0009');
await waitCompletion(cliRepl.bus);
expect(output).to.include('JSON.parse');
expect(output).to.include('JSON.stringify');
expect(output).not.to.include('rawValue');
});

it('completes JS value properties properly (complete, single tab)', async() => {
input.write('JSON.pa\u0009');
await waitCompletion(cliRepl.bus);
expect(output).to.include('JSON.parse');
expect(output).not.to.include('JSON.stringify');
expect(output).not.to.include('rawValue');
});
});
Expand Down

0 comments on commit 81ff5a5

Please sign in to comment.