dbcli / mycli

A Terminal Client for MySQL with AutoCompletion and Syntax Highlighting.
http://mycli.net
Other
11.42k stars 661 forks source link

Import MySQL completion candidates from pygments #925

Open rolandwalker opened 3 years ago

rolandwalker commented 3 years ago

Description

Since the pygments library is already required, why not use its list of reserved words for completions?

This fixes #767 and should keep us up-to-date. It's really great to have the new JSON_* functions.

Compared to the previous code, this PR

Downsides and bugs:

Checklist

amjith commented 3 years ago

Two things:

  1. The mysql keyword lexer is only available in newer versions of Pygments, so we should update setup.py to pin the min version of pygments to something more recent.
  2. The previous way of defining the keywords allowed us to control the order of the suggestions in the completion menu. For example, the SELECT keyword is higher up in the list and so is the FROM keyword. So they show up in the list higher so it is easier for the user to select them with fewer keystrokes. Maybe we can define a list of most common keywords in a separate list and have them prepended to the lexer's keywords and remove the sorting. We can also uniqe the list to ensure we remove the duplicates.

Thoughts?

rolandwalker commented 3 years ago

That sounds good, will try.

Ideally, we'd form that most-common list dynamically from the user's own history.

amjith commented 3 years ago

Ideally, we'd form that most-common list dynamically from the user's own history.

I believe we have that feature, I can't tell if it is in pgcli or mycli. Let me look it up.

amjith commented 3 years ago

https://github.com/dbcli/pgcli/blob/master/pgcli/packages/prioritization.py