GeezerVison is showing github.com — gh-133390: Extend completion for .commands in `sqlite3` by StanFromIreland · Pull Request #135432 · python/cpython
Conversation
StanFromIreland
commented
Jun 12, 2025
•
edited by bedevere-app
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
tanloong
left a comment
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this 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()
if origline.startswith("."):
...
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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 reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
tanloong
commented
Jun 12, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
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:
- Complete without dot if there is any number of whitespaces between the dot and the cursor.
sqlite> . |
help
version
quit
- Complete with the dot if cursor is immediately at the right handside of the dot.
sqlite> .|
.help
.version
.quit
- 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_matches
if state == 0:
import readline
origline = readline.get_line_buffer()
if origline.startswith("."):
if origline == text:
text_lstrip = text.lstrip(".")
_completion_matches = [f".{cmd}" for cmd in COMMANDS
if cmd.startswith(text_lstrip)]
elif origline.removeprefix(".").lstrip(" ") == text:
_completion_matches = [cmd for cmd in COMMANDS
if cmd.startswith(text)]
else:
_completion_matches.clear()
else:
text_upper = text.upper()
_completion_matches = [c for c in SQLITE_KEYWORDS if c.startswith(text_upper)]
try:
return _completion_matches[state] + " "
except IndexError:
return None
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
Thank you!
@tanloong, additional improvements are welcome :)
|
tanloong reacted with heart emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
erlend-aasland
Awaiting requested review from erlend-aasland
erlend-aasland is a code owner
encukou
Awaiting requested review from encukou
1 more reviewer
Reviewers whose approvals may not affect merge requirements
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.