Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
* Add warnings-count prompt format strings: `\w` and `\W`.
* Handle/document more attributes in the `[colors]` section of `~/.myclirc`.
* Enable customization of table border color/attributes in `~/.myclirc`.
* Complete much more precisely in the "value" position.


Bug Fixes
Expand Down
11 changes: 10 additions & 1 deletion mycli/packages/completion_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,23 @@ def suggest_based_on_last_token(
{"type": "view", "schema": parent},
{"type": "function", "schema": parent},
]
else:
elif is_inside_quotes(text_before_cursor, -1) == 'backtick':
# todo: this should be revised, since we complete too exuberantly within
# backticks, including keywords
aliases = [alias or table for (schema, table, alias) in tables]
return [
{"type": "column", "tables": tables},
{"type": "function", "schema": []},
{"type": "alias", "aliases": aliases},
{"type": "keyword"},
]
else:
aliases = [alias or table for (schema, table, alias) in tables]
return [
{"type": "column", "tables": tables},
{"type": "function", "schema": []},
{"type": "alias", "aliases": aliases},
]
elif (
(token_v.endswith("join") and isinstance(token, Token) and token.is_keyword)
or (token_v in ("copy", "from", "update", "into", "describe", "truncate", "desc", "explain"))
Expand Down
108 changes: 107 additions & 1 deletion mycli/sqlcompleter.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,113 @@ class SQLCompleter(Completer):
"ZEROFILL",
]

functions = [x.upper() for x in MYSQL_FUNCTIONS]
# misclassified as keywords
# do they need to also be subtracted from keywords?
pygments_misclassified_functions = (
'ASCII',
'AVG',
'CHARSET',
'COALESCE',
'COLLATION',
'CONVERT',
'CUME_DIST',
'CURRENT_DATE',
'CURRENT_TIME',
'CURRENT_TIMESTAMP',
'CURRENT_USER',
'DATABASE',
'DAY',
'DEFAULT',
'DENSE_RANK',
'EXISTS',
'FIRST_VALUE',
'FORMAT',
'GEOMCOLLECTION',
'GET_FORMAT',
'GROUPING',
'HOUR',
'IF',
'INSERT',
'INTERVAL',
'JSON_TABLE',
'JSON_VALUE',
'LAG',
'LAST_VALUE',
'LEAD',
'LEFT',
'LOCALTIME',
'LOCALTIMESTAMP',
'MATCH',
'MICROSECOND',
'MINUTE',
'MOD',
'MONTH',
'NTH_VALUE',
'NTILE',
'PERCENT_RANK',
'QUARTER',
'RANK',
'REPEAT',
'REPLACE',
'REVERSE',
'RIGHT',
'ROW_COUNT',
'ROW_NUMBER',
'SCHEMA',
'SECOND',
'TIMESTAMPADD',
'TIMESTAMPDIFF',
'TRUNCATE',
'USER',
'UTC_DATE',
'UTC_TIME',
'UTC_TIMESTAMP',
'VALUES',
'WEEK',
'WEIGHT_STRING',
)

pygments_missing_functions = (
'BINARY', # deprecated function, but available everywhere
'CHAR',
'DATE',
'DISTANCE',
'ETAG',
'GeometryCollection',
'JSON_DUALITY_OBJECT',
'LineString',
'MultiLineString',
'MultiPoint',
'MultiPolygon',
'Point',
'Polygon',
'STRING_TO_VECTOR',
'TIME',
'TIMESTAMP',
'VECTOR_DIM',
'VECTOR_TO_STRING',
'YEAR',
)

# so far an incomplete list
# these should be spun out and completed independently from functions
pygments_value_position_nonfunction_keywords = (
'BETWEEN',
'CASE',
'FALSE',
'NOT',
'NULL',
'TRUE',
)

# should https://dev.mysql.com/doc/refman/9.6/en/loadable-function-reference.html also be added?
functions = sorted({
x.upper()
for x in MYSQL_FUNCTIONS
+ pygments_misclassified_functions
+ pygments_missing_functions
+ pygments_value_position_nonfunction_keywords
})

# https://docs.pingcap.com/tidb/dev/tidb-functions
tidb_functions = [
Expand Down
13 changes: 0 additions & 13 deletions test/test_completion_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def test_select_suggests_cols_with_visible_table_scope():
{"type": "alias", "aliases": ["tabl"]},
{"type": "column", "tables": [(None, "tabl", None)]},
{"type": "function", "schema": []},
{"type": "keyword"},
])


Expand All @@ -31,7 +30,6 @@ def test_select_suggests_cols_with_qualified_table_scope():
{"type": "alias", "aliases": ["tabl"]},
{"type": "column", "tables": [("sch", "tabl", None)]},
{"type": "function", "schema": []},
{"type": "keyword"},
])


Expand All @@ -55,7 +53,6 @@ def test_where_suggests_columns_functions(expression):
{"type": "alias", "aliases": ["tabl"]},
{"type": "column", "tables": [(None, "tabl", None)]},
{"type": "function", "schema": []},
{"type": "keyword"},
])


Expand All @@ -67,7 +64,6 @@ def test_where_equals_suggests_enum_values_first():
{"type": "alias", "aliases": ["tabl"]},
{"type": "column", "tables": [(None, "tabl", None)]},
{"type": "function", "schema": []},
{"type": "keyword"},
])


Expand All @@ -84,7 +80,6 @@ def test_where_in_suggests_columns(expression):
{"type": "alias", "aliases": ["tabl"]},
{"type": "column", "tables": [(None, "tabl", None)]},
{"type": "function", "schema": []},
{"type": "keyword"},
])


Expand All @@ -95,7 +90,6 @@ def test_where_equals_any_suggests_columns_or_keywords():
{"type": "alias", "aliases": ["tabl"]},
{"type": "column", "tables": [(None, "tabl", None)]},
{"type": "function", "schema": []},
{"type": "keyword"},
])


Expand All @@ -120,7 +114,6 @@ def test_select_suggests_cols_and_funcs():
{"type": "alias", "aliases": []},
{"type": "column", "tables": []},
{"type": "function", "schema": []},
{"type": "keyword"},
])


Expand Down Expand Up @@ -193,7 +186,6 @@ def test_col_comma_suggests_cols():
{"type": "alias", "aliases": ["tbl"]},
{"type": "column", "tables": [(None, "tbl", None)]},
{"type": "function", "schema": []},
{"type": "keyword"},
])


Expand Down Expand Up @@ -236,7 +228,6 @@ def test_partially_typed_col_name_suggests_col_names():
{"type": "alias", "aliases": ["tabl"]},
{"type": "column", "tables": [(None, "tabl", None)]},
{"type": "function", "schema": []},
{"type": "keyword"},
])


Expand Down Expand Up @@ -331,7 +322,6 @@ def test_sub_select_col_name_completion():
{"type": "alias", "aliases": ["abc"]},
{"type": "column", "tables": [(None, "abc", None)]},
{"type": "function", "schema": []},
{"type": "keyword"},
])


Expand Down Expand Up @@ -484,7 +474,6 @@ def test_2_statements_2nd_current():
{"type": "alias", "aliases": ["b"]},
{"type": "column", "tables": [(None, "b", None)]},
{"type": "function", "schema": []},
{"type": "keyword"},
])

# Should work even if first statement is invalid
Expand All @@ -509,7 +498,6 @@ def test_2_statements_1st_current():
{"type": "alias", "aliases": ["a"]},
{"type": "column", "tables": [(None, "a", None)]},
{"type": "function", "schema": []},
{"type": "keyword"},
])


Expand All @@ -526,7 +514,6 @@ def test_3_statements_2nd_current():
{"type": "alias", "aliases": ["b"]},
{"type": "column", "tables": [(None, "b", None)]},
{"type": "function", "schema": []},
{"type": "keyword"},
])


Expand Down
Loading