Skip to content

Commit

Permalink
import MySQL completion candidates from pygments
Browse files Browse the repository at this point in the history
 * remove LEN and TOP, which are not MySQL reserved words
 * preserve completion candidates containing space, such as "ORDER BY"
  • Loading branch information
rolandwalker committed Jan 4, 2021
1 parent 4517f49 commit f70c1a9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Features:
* Allow customization of Pygments SQL syntax-highlighting styles.
* Add a `\clip` special command to copy queries to the system clipboard.
* Add a special command `\pipe_once` to pipe output to a subprocess.
* More complete and up-to-date set of MySQL reserved words for completions.


Bug Fixes:
Expand Down
38 changes: 11 additions & 27 deletions mycli/sqlcompleter.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import itertools
import logging
from re import compile, escape
from collections import Counter

from prompt_toolkit.completion import Completer, Completion
from pygments.lexers._mysql_builtins import \
MYSQL_DATATYPES, \
MYSQL_FUNCTIONS, \
MYSQL_KEYWORDS

from .packages.completion_engine import suggest_type
from .packages.parseutils import last_word
Expand All @@ -13,33 +18,12 @@


class SQLCompleter(Completer):
keywords = ['ACCESS', 'ADD', 'ALL', 'ALTER TABLE', 'AND', 'ANY', 'AS',
'ASC', 'AUTO_INCREMENT', 'BEFORE', 'BEGIN', 'BETWEEN',
'BIGINT', 'BINARY', 'BY', 'CASE', 'CHANGE MASTER TO', 'CHAR',
'CHARACTER SET', 'CHECK', 'COLLATE', 'COLUMN', 'COMMENT',
'COMMIT', 'CONSTRAINT', 'CREATE', 'CURRENT',
'CURRENT_TIMESTAMP', 'DATABASE', 'DATE', 'DECIMAL', 'DEFAULT',
'DELETE FROM', 'DESC', 'DESCRIBE', 'DROP',
'ELSE', 'END', 'ENGINE', 'ESCAPE', 'EXISTS', 'FILE', 'FLOAT',
'FOR', 'FOREIGN KEY', 'FORMAT', 'FROM', 'FULL', 'FUNCTION',
'GRANT', 'GROUP BY', 'HAVING', 'HOST', 'IDENTIFIED', 'IN',
'INCREMENT', 'INDEX', 'INSERT INTO', 'INT', 'INTEGER',
'INTERVAL', 'INTO', 'IS', 'JOIN', 'KEY', 'LEFT', 'LEVEL',
'LIKE', 'LIMIT', 'LOCK', 'LOGS', 'LONG', 'MASTER',
'MEDIUMINT', 'MODE', 'MODIFY', 'NOT', 'NULL', 'NUMBER',
'OFFSET', 'ON', 'OPTION', 'OR', 'ORDER BY', 'OUTER', 'OWNER',
'PASSWORD', 'PORT', 'PRIMARY', 'PRIVILEGES', 'PROCESSLIST',
'PURGE', 'REFERENCES', 'REGEXP', 'RENAME', 'REPAIR', 'RESET',
'REVOKE', 'RIGHT', 'ROLLBACK', 'ROW', 'ROWS', 'ROW_FORMAT',
'SAVEPOINT', 'SELECT', 'SESSION', 'SET', 'SHARE', 'SHOW',
'SLAVE', 'SMALLINT', 'SMALLINT', 'START', 'STOP', 'TABLE',
'THEN', 'TINYINT', 'TO', 'TRANSACTION', 'TRIGGER', 'TRUNCATE',
'UNION', 'UNIQUE', 'UNSIGNED', 'UPDATE', 'USE', 'USER',
'USING', 'VALUES', 'VARCHAR', 'VIEW', 'WHEN', 'WHERE', 'WITH']

functions = ['AVG', 'CONCAT', 'COUNT', 'DISTINCT', 'FIRST', 'FORMAT',
'FROM_UNIXTIME', 'LAST', 'LCASE', 'LEN', 'MAX', 'MID',
'MIN', 'NOW', 'ROUND', 'SUM', 'TOP', 'UCASE', 'UNIX_TIMESTAMP']
keywords = [x.upper() for x in itertools.chain.from_iterable([
MYSQL_DATATYPES, MYSQL_KEYWORDS,
['ALTER TABLE', 'CHANGE MASTER TO', 'CHARACTER SET', 'DELETE FROM',
'FOREIGN KEY', 'GROUP BY', 'INSERT INTO', 'ORDER BY']])]

functions = [x.upper() for x in MYSQL_FUNCTIONS]

show_items = []

Expand Down

0 comments on commit f70c1a9

Please sign in to comment.