From 8407a3003182be8936c692b44c7a96c29b0198a4 Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Sat, 24 Jan 2026 10:23:26 -0500 Subject: [PATCH] Better keyword_casing=auto heuristic. Consider both the first and last letter of the user's text when choosing case for completion candidates when keyword_casing=auto. The issue is that when the last character typed is non-alphabetic such as underscore, then islower() is False. Better to check both the first and last character of the user's text. If either of them is lowercase then we complete with lowercase. --- changelog.md | 5 +++++ mycli/sqlcompleter.py | 2 +- test/test_smart_completion_public_schema_only.py | 12 ++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index b961d394..1e333ee4 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,11 @@ Features * Right-align numeric columns, and make the behavior configurable. +Bug Fixes +-------- +* Better respect case when `keyword_casing` is `auto`. + + 1.47.0 (2026/01/24) ============== diff --git a/mycli/sqlcompleter.py b/mycli/sqlcompleter.py index 4834d22c..3d20ffeb 100644 --- a/mycli/sqlcompleter.py +++ b/mycli/sqlcompleter.py @@ -1027,7 +1027,7 @@ def find_matches( completions.append(item) if casing == "auto": - casing = "lower" if last and last[-1].islower() else "upper" + casing = "lower" if last and (last[0].islower() or last[-1].islower()) else "upper" def apply_case(kw: str) -> str: if casing == "upper": diff --git a/test/test_smart_completion_public_schema_only.py b/test/test_smart_completion_public_schema_only.py index 30aba328..ae220b0a 100644 --- a/test/test_smart_completion_public_schema_only.py +++ b/test/test_smart_completion_public_schema_only.py @@ -544,3 +544,15 @@ def test_file_name_completion(completer, complete_event, text, expected): result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event)) expected = [Completion(txt, pos) for txt, pos in expected] assert result == expected + + +def test_auto_case_heuristic(completer, complete_event): + text = "select jon_" + position = len("select jon_") + result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event)) + assert [x.text for x in result] == [ + 'json_table', + 'json_value', + 'join', + 'json', + ]