Uh oh!
There was an error while loading. Please reload this page.
gh-133390: Extend completion for .commands in sqlite3 - #135432
Conversation
There was a problem hiding this comment.
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
commented
Jun 12, 2025
sqlite3 identifiers cannot start with |
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:
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 |
Uh oh!
There was an error while loading. Please reload this page.
encukou
commented
Aug 25, 2025
Thank you! |
@tanloong@encukou