Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import MySQL completion candidates from pygments #925

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rolandwalker
Copy link
Contributor

@rolandwalker rolandwalker commented Jan 4, 2021

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

  • removes LEN and TOP, which are not MySQL reserved words
  • preserves extra completion candidates containing space, such as "ORDER BY"

Downsides and bugs:

  • pygments.lexers._mysql_builtins does contain a leading underscore, so we should be aware that the library reserves the right to break this usage. We might consider pinning the library version, but I don't honestly expect there will be a problem.
  • Certain reserved words are duplicated with special commands, so if the first word of a command-line is any of the following, duplicated completions will show, as both upper- and lower-case: exit, help, source, status, system, use. This is fixable, but should we prefer the upper- or lower-case flavor?

Checklist

  • I've added this contribution to the changelog.md.
  • I've added my name to the AUTHORS file (or it's already there).

@rolandwalker rolandwalker requested a review from amjith January 4, 2021 20:24
@rolandwalker rolandwalker self-assigned this Jan 4, 2021
@rolandwalker rolandwalker force-pushed the RW/complete-keywords-functions branch from f70c1a9 to 0fa810d Compare January 4, 2021 23:19
 * remove LEN and TOP, which are not MySQL reserved words
 * preserve completion candidates containing space, such as "ORDER BY"
@rolandwalker rolandwalker force-pushed the RW/complete-keywords-functions branch from 0fa810d to 0d42ed5 Compare January 5, 2021 01:26
@amjith
Copy link
Member

amjith commented Jan 5, 2021

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
Copy link
Contributor Author

That sounds good, will try.

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

@amjith
Copy link
Member

amjith commented Jan 5, 2021

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
Copy link
Member

amjith commented Jan 5, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants