From 6b9d0c6a7e8aa087a247edbaa25e601849a4677c Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Tue, 3 Mar 2026 04:30:54 -0500 Subject: [PATCH] prioritize common functions in the value position Like favorite_keywords, add a list of favorite_functions which should be ordered ahead when completing function names in the value position. Currently the only real effect this has is to suggest JSON_VALUE() ahead of JSON_VALID(), resolving a small common annoyance. But we should further curate the list of favorites. Another longstanding idea is to have dynamic frecency govern the list of favorites. There happened to be a test case for JSON_VALUE/JSON_VALID already. --- changelog.md | 8 +++++ mycli/sqlcompleter.py | 35 +++++++++++-------- ...est_smart_completion_public_schema_only.py | 2 +- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/changelog.md b/changelog.md index 12e4af1c..46dd0702 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,11 @@ +Upcoming (TBD) +============== + +Features +--------- +* Prioritize common functions in the "value" position. + + 1.59.0 (2026/03/03) ============== diff --git a/mycli/sqlcompleter.py b/mycli/sqlcompleter.py index 130b7996..3e39a007 100644 --- a/mycli/sqlcompleter.py +++ b/mycli/sqlcompleter.py @@ -745,7 +745,7 @@ class SQLCompleter(Completer): # misclassified as keywords # do they need to also be subtracted from keywords? - pygments_misclassified_functions = ( + pygments_misclassified_functions = [ 'ASCII', 'AVG', 'CHARSET', @@ -807,9 +807,10 @@ class SQLCompleter(Completer): 'VALUES', 'WEEK', 'WEIGHT_STRING', - ) + ] - pygments_missing_functions = ( + # should case be respected for functions styled as CamelCase? + pygments_missing_functions = [ 'BINARY', # deprecated function, but available everywhere 'CHAR', 'DATE', @@ -829,27 +830,33 @@ class SQLCompleter(Completer): '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 = ( + # these should be spun out and completed independently from functions in the value position + 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 - }) + pygments_functions_supplemented = sorted( + [x.upper() for x in MYSQL_FUNCTIONS] + + [x.upper() for x in pygments_misclassified_functions] + + [x.upper() for x in pygments_missing_functions] + + [x.upper() for x in pygments_value_position_nonfunction_keywords] + ) + + favorite_functions = [ + 'JSON_EXTRACT', + 'JSON_VALUE', + ] + functions_raw = favorite_functions + pygments_functions_supplemented + functions = list(dict.fromkeys(functions_raw)) # https://docs.pingcap.com/tidb/dev/tidb-functions tidb_functions = [ diff --git a/test/test_smart_completion_public_schema_only.py b/test/test_smart_completion_public_schema_only.py index b0326a5b..8e741054 100644 --- a/test/test_smart_completion_public_schema_only.py +++ b/test/test_smart_completion_public_schema_only.py @@ -583,8 +583,8 @@ def test_auto_case_heuristic(completer, complete_event): position = len("select json_v") result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event)) assert [x.text for x in result] == [ - 'json_valid', 'json_value', + 'json_valid', ]