# SQL Hint completion problems

**URL:** https://discuss.codemirror.net/t/sql-hint-completion-problems/792
**Category:** Uncategorized
**Created:** [June 23, 2016, 8:01pm UTC](https://discuss.codemirror.net/t/sql-hint-completion-problems/792 "2016-06-23T20:01:33Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![janoonk](https://discuss.codemirror.net/letter_avatar_proxy/v4/letter/j/57b2e6/32.png) [@janoonk](https://discuss.codemirror.net/u/janoonk)
#### Post date: [June 23, 2016, 8:01pm UTC](https://discuss.codemirror.net/t/sql-hint-completion-problems/792/1 "2016-06-23T20:01:33Z")

</div>

I have two problems while using SQL Hint completion:

1. I want to automatically select the last remaining completion item so I used **completeSingle: true** in my hintOptions object that I pass to **editor.setOption(“hintOptions”,hintOptions);**  
But it doesn’t seem to work. I still have to type the complete word.

2. I want to always show the dropdown while typing so I used this:

> ```
> editor.on('keypress', function(cm,e){
> editor.showHint(editor.hintOptions);
> });
> 
> ```

Strange thing is completeSingle now works but the last character I was typing is added after completion. So I have typed **cou** , now the last item COUNT in the dropdown remains. When I now type **n** this item automatically gets choosen (like I wanted/expected since I have set completeSingle option) but the **n** is added after COUNT like this: COUNTn.

What am I doing wrong? Or is this a bug?

---

<div class="post-metadata">

### Author: ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)
#### Post date: [June 24, 2016, 12:58pm UTC](https://discuss.codemirror.net/t/sql-hint-completion-problems/792/2 "2016-06-24T12:58:33Z")

</div>

Keypress handlers fire before the letter is actually typed, so if you run `showHint` this way it’ll take effect, and then the character is inserted, which is not what you want. You could add a timeout or use CodeMirror’s `inputRead` event.
