Skip to content

Conversation

@StanFromIreland
Copy link
Member

@StanFromIrelandStanFromIreland commented Jun 12, 2025

Copy link
Contributor

@tanloongtanloong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only commands with a dot at the line beginning is considered dot commands. text is the non-whitespace chars under wherever the cursor is at. This means using text.startswith() enables dot command completion for not only actual dot commands but also any inline word that starts with dot:

sqlite> SELECT .<tab> .help .quit .version sqlite> SELECT . 

Using readline.get_line_buffer() instead is more reasonable. This returns the whole current line and can be used to avoid completion for dot-started inline word:

origline=readline.get_line_buffer() iforigline.startswith("."): ...

@StanFromIreland
Copy link
MemberAuthor

sqlite3 identifiers cannot start with . (OperationalError (SQLITE_ERROR): near ".": syntax error). Calling readline would complicate our imports a bit more, I'm not sure it is worth it. Not much changes, it is invalid just like it was before.

@tanloong
Copy link
Contributor

tanloong commented Jun 12, 2025

I actually also made a local change to add dot commands completion. This is the idea on my local branch, just sharing it for discussion:

  1. Complete without dot if there is any number of whitespaces between the dot and the cursor.
sqlite> . | help version quit 
  1. Complete with the dot if cursor is immediately at the right handside of the dot.
sqlite> .| .help .version .quit 
  1. Complete nothing if there is any non-whitespace chars between the dot and the cursor (as we currently don't have dot commands that receive arguments).
sqlite> . help | # no candidates 
COMMANDS= ("quit", "help", "version") def_complete(text, state): global_completion_matchesifstate==0: importreadlineorigline=readline.get_line_buffer() iforigline.startswith("."): iforigline==text: text_lstrip=text.lstrip(".") _completion_matches= [f".{cmd}"forcmdinCOMMANDSifcmd.startswith(text_lstrip)] eliforigline.removeprefix(".").lstrip(" ") ==text: _completion_matches= [cmdforcmdinCOMMANDSifcmd.startswith(text)] else: _completion_matches.clear() else: text_upper=text.upper() _completion_matches= [cforcinSQLITE_KEYWORDSifc.startswith(text_upper)] try: return_completion_matches[state] +" "exceptIndexError: returnNone

@encukou
Copy link
Member

Thank you!
@tanloong, additional improvements are welcome :)

@encukouencukou merged commit a553065 into python:mainAug 25, 2025
44 checks passed
@StanFromIrelandStanFromIreland deleted the sqlite3-.commands branch August 25, 2025 13:00
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@StanFromIreland@tanloong@encukou