Hinting on braces from SQL mode

I’m trying to add a way to show the autocomplete popup with auto-complete suggestions that begin with braces. Specifically I’m trying to match in SQL mode where there are mustache-like variables in the SQL (i.e. SELECT * FROM MYTABLE WHERE column1 = {{ my_template_variable }}) . And I want a hint popup for ‘{{ my_template_variable}}’ to trigger when they type the brace { . However it seems that all brackets and braces are special and don’t trigger the hints. I’m able to get the pop-up working with my own list for other characters, tried playing with customKeys and extraKeys but no luck. Is this possible?

I think the way the sql-hint addon looks for completions makes assumptions about what kind of token can be part of a completion (see the line that includes token.string.match(/^[."\w@]\w*$/)`), and braces aren’t part of that.

@marijn Thanks for this explanation. Any way to override this behavior without changing the sql mode code itself? Would prefer not to fork and instead find a workaround. I really appreciate the help. Thanks!

I don’t think so—I didn’t write sql-hint.js, it was contributed, and I’m not adding new features to it. If you want to dive into the code and submit a coherent pull request that makes this configurable, I’d be willing to take a look, though.

@marijn. I actually don’t think the issue is in sql-hint.js. I tried many other modes and dialects and can’t get the hint function to trigger on a {. I also just wrote my own custom hint function and it doesn’t trigger on {. Here is the stack trace:

at hint (mycode.js?497b:149)
at fetchHints (show-hint.js?8d07:390)
at Completion.update (show-hint.js?8d07:117)
at CodeMirror.eval [as showHint] (show-hint.js?8d07:46)
at eval (mycode.js?497b:146)
at signal (codemirror.js?f14e:549)
at signalDOMEvent (codemirror.js?f14e:558)
at CodeMirror.onKeyPress (codemirror.js?f14e:7252)
at HTMLTextAreaElement.eval (codemirror.js?f14e:3908)

sql-hint is not in the path. This code path triggers for spaces, letters, etc but not with { as the token. So is there a way to configure show-hint to trigger on a {?

Thanks again!

@marijn Can you confirm the above that it’s actually the show-hint code and not the sql-hint code that is is not triggering the hint for { ? Thanks and really appreciate it.

I’m not sure—it’s been a while since I looked at this code, so I’m afraid you’ll have to debug it yourself.