From 5d6280abec643ee80debb03124f8826c0dda0b2f Mon Sep 17 00:00:00 2001 From: lana-k Date: Sun, 2 May 2021 14:04:46 +0200 Subject: [PATCH] add default table in hint options --- src/hint.js | 4 ++++ tests/hint.spec.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/hint.js b/src/hint.js index c584bb8..8f35137 100644 --- a/src/hint.js +++ b/src/hint.js @@ -25,6 +25,10 @@ const hintOptions = { } return tables }, + get defaultTable () { + const schema = store.state.schema + return schema.length === 1 ? schema[0].name : null + }, completeSingle: false, completeOnSingleClick: true, alignWithWord: false diff --git a/tests/hint.spec.js b/tests/hint.spec.js index c059599..e79d14c 100644 --- a/tests/hint.spec.js +++ b/tests/hint.spec.js @@ -49,6 +49,39 @@ describe('hint.js', () => { foo: ['fooId', 'name'], bar: ['barId'] }) + expect(CM.showHint.firstCall.args[2].defaultTable).to.equal(null) + }) + + it('Add default table if there is only one table in schema', () => { + // mock store state + const schema = [ + { + name: 'foo', + columns: [ + { name: 'fooId', type: 'INTEGER' }, + { name: 'name', type: 'NVARCHAR(20)' } + ] + } + ] + sinon.stub(state, 'schema').value(schema) + + // mock showHint and editor + sinon.stub(CM, 'showHint') + const editor = { + getTokenAt () { + return { + string: 'SELECT', + type: 'keyword' + } + }, + getCursor: sinon.stub() + } + + const clock = sinon.useFakeTimers() + hint.show(editor) + clock.tick(500) + + expect(CM.showHint.firstCall.args[2].defaultTable).to.equal('foo') }) it("Doesn't show hint when in string or space, or ';'", () => {