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 @@ -4,6 +4,7 @@ TBD
Features
--------
* More complete and up-to-date set of MySQL reserved words for completions.
* Place exact-leading completions first.
* Allow history file location to be configured.


Expand Down
7 changes: 7 additions & 0 deletions mycli/sqlcompleter.py
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,13 @@ def apply_case(kw: str) -> str:
return kw.upper()
return kw.lower()

def exact_leading_key(item: tuple[int, int, str], text):
if text and item[2].lower().startswith(text):
return -1000 + len(item[2])
return 0

completions = sorted(completions, key=lambda item: exact_leading_key(item, text))

return (Completion(z if casing is None else apply_case(z), -len(text)) for x, y, z in completions)

def get_completions(
Expand Down
72 changes: 36 additions & 36 deletions test/test_smart_completion_public_schema_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,46 @@ def test_function_name_completion(completer, complete_event):
position = len("SELECT MA")
result = completer.get_completions(Document(text=text, cursor_position=position), complete_event)
assert list(result) == [
Completion(text='MAX', start_position=-2),
Completion(text='MAKE_SET', start_position=-2),
Completion(text='MAKEDATE', start_position=-2),
Completion(text='MAKETIME', start_position=-2),
Completion(text='MASTER_POS_WAIT', start_position=-2),
Completion(text='MAX', start_position=-2),
Completion(text='MATCH', start_position=-2),
Completion(text='MASTER', start_position=-2),
Completion(text='MAX_ROWS', start_position=-2),
Completion(text='MAX_SIZE', start_position=-2),
Completion(text='MAXVALUE', start_position=-2),
Completion(text='MASTER_SSL', start_position=-2),
Completion(text='MASTER_BIND', start_position=-2),
Completion(text='MASTER_HOST', start_position=-2),
Completion(text='MASTER_PORT', start_position=-2),
Completion(text='MASTER_USER', start_position=-2),
Completion(text='MASTER_DELAY', start_position=-2),
Completion(text='MASTER_SSL_CA', start_position=-2),
Completion(text='MASTER_LOG_POS', start_position=-2),
Completion(text='MASTER_SSL_CRL', start_position=-2),
Completion(text='MASTER_SSL_KEY', start_position=-2),
Completion(text='MASTER_LOG_FILE', start_position=-2),
Completion(text='MASTER_PASSWORD', start_position=-2),
Completion(text='MASTER_SSL_CERT', start_position=-2),
Completion(text='MASTER_SSL_CAPATH', start_position=-2),
Completion(text='MASTER_SSL_CIPHER', start_position=-2),
Completion(text='MASTER_RETRY_COUNT', start_position=-2),
Completion(text='MASTER_SSL_CRLPATH', start_position=-2),
Completion(text='MASTER_TLS_VERSION', start_position=-2),
Completion(text='MASTER_AUTO_POSITION', start_position=-2),
Completion(text='MASTER_CONNECT_RETRY', start_position=-2),
Completion(text='MAX_QUERIES_PER_HOUR', start_position=-2),
Completion(text='MAX_UPDATES_PER_HOUR', start_position=-2),
Completion(text='MAX_USER_CONNECTIONS', start_position=-2),
Completion(text='MASTER_PUBLIC_KEY_PATH', start_position=-2),
Completion(text='MASTER_HEARTBEAT_PERIOD', start_position=-2),
Completion(text='MASTER_TLS_CIPHERSUITES', start_position=-2),
Completion(text='MAX_CONNECTIONS_PER_HOUR', start_position=-2),
Completion(text='MASTER_COMPRESSION_ALGORITHMS', start_position=-2),
Completion(text='MASTER_SSL_VERIFY_SERVER_CERT', start_position=-2),
Completion(text='MASTER_ZSTD_COMPRESSION_LEVEL', start_position=-2),
Completion(text='DECIMAL', start_position=-2),
Completion(text='SMALLINT', start_position=-2),
Completion(text='TIMESTAMP', start_position=-2),
Expand All @@ -166,41 +201,6 @@ def test_function_name_completion(completer, complete_event):
Completion(text='GET_FORMAT', start_position=-2),
Completion(text='GET_MASTER_PUBLIC_KEY', start_position=-2),
Completion(text='LOCALTIMESTAMP', start_position=-2),
Completion(text='MASTER', start_position=-2),
Completion(text='MASTER_AUTO_POSITION', start_position=-2),
Completion(text='MASTER_BIND', start_position=-2),
Completion(text='MASTER_COMPRESSION_ALGORITHMS', start_position=-2),
Completion(text='MASTER_CONNECT_RETRY', start_position=-2),
Completion(text='MASTER_DELAY', start_position=-2),
Completion(text='MASTER_HEARTBEAT_PERIOD', start_position=-2),
Completion(text='MASTER_HOST', start_position=-2),
Completion(text='MASTER_LOG_FILE', start_position=-2),
Completion(text='MASTER_LOG_POS', start_position=-2),
Completion(text='MASTER_PASSWORD', start_position=-2),
Completion(text='MASTER_PORT', start_position=-2),
Completion(text='MASTER_PUBLIC_KEY_PATH', start_position=-2),
Completion(text='MASTER_RETRY_COUNT', start_position=-2),
Completion(text='MASTER_SSL', start_position=-2),
Completion(text='MASTER_SSL_CA', start_position=-2),
Completion(text='MASTER_SSL_CAPATH', start_position=-2),
Completion(text='MASTER_SSL_CERT', start_position=-2),
Completion(text='MASTER_SSL_CIPHER', start_position=-2),
Completion(text='MASTER_SSL_CRL', start_position=-2),
Completion(text='MASTER_SSL_CRLPATH', start_position=-2),
Completion(text='MASTER_SSL_KEY', start_position=-2),
Completion(text='MASTER_SSL_VERIFY_SERVER_CERT', start_position=-2),
Completion(text='MASTER_TLS_CIPHERSUITES', start_position=-2),
Completion(text='MASTER_TLS_VERSION', start_position=-2),
Completion(text='MASTER_USER', start_position=-2),
Completion(text='MASTER_ZSTD_COMPRESSION_LEVEL', start_position=-2),
Completion(text='MATCH', start_position=-2),
Completion(text='MAX_CONNECTIONS_PER_HOUR', start_position=-2),
Completion(text='MAX_QUERIES_PER_HOUR', start_position=-2),
Completion(text='MAX_ROWS', start_position=-2),
Completion(text='MAX_SIZE', start_position=-2),
Completion(text='MAX_UPDATES_PER_HOUR', start_position=-2),
Completion(text='MAX_USER_CONNECTIONS', start_position=-2),
Completion(text='MAXVALUE', start_position=-2),
Completion(text='MESSAGE_TEXT', start_position=-2),
Completion(text='MIGRATE', start_position=-2),
Completion(text='NETWORK_NAMESPACE', start_position=-2),
Expand Down