Skip to content

Commit efc1c29

Browse files
committed
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.
1 parent 2d97cd2 commit efc1c29

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
TBD
2+
==============
3+
4+
Bug Fixes
5+
--------
6+
* Better respect case when `keyword_casing` is `auto`.
7+
8+
19
1.47.0 (2026/01/24)
210
==============
311

mycli/sqlcompleter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ def find_matches(
10271027
completions.append(item)
10281028

10291029
if casing == "auto":
1030-
casing = "lower" if last and last[-1].islower() else "upper"
1030+
casing = "lower" if last and (last[0].islower() or last[-1].islower()) else "upper"
10311031

10321032
def apply_case(kw: str) -> str:
10331033
if casing == "upper":

test/test_smart_completion_public_schema_only.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,3 +544,15 @@ def test_file_name_completion(completer, complete_event, text, expected):
544544
result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event))
545545
expected = [Completion(txt, pos) for txt, pos in expected]
546546
assert result == expected
547+
548+
549+
def test_auto_case_heuristic(completer, complete_event):
550+
text = "select jon_"
551+
position = len("select jon_")
552+
result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event))
553+
assert [x.text for x in result] == [
554+
'json_table',
555+
'json_value',
556+
'join',
557+
'json',
558+
]

0 commit comments

Comments
 (0)