Skip to content

Append dot after database name when completing on a table#1876

Open
rolandwalker wants to merge 1 commit intomainfrom
RW/append-dot-to-database-before-table
Open

Append dot after database name when completing on a table#1876
rolandwalker wants to merge 1 commit intomainfrom
RW/append-dot-to-database-before-table

Conversation

@rolandwalker
Copy link
Copy Markdown
Contributor

Description

Previously, database names were available as candidates when completing a table name, but if completing a database name, the user had to manually enter a trailing dot before typing a table name.

It might be even nicer if the dot was appended after the completion, but did not appear in the candidate menu. It isn't clear how to do that. On the other hand, the dot visually distinguishes which candidates are of which type.

The trailing dot does not appear when a database is completed in a database-only position such as USE.

There is an xfailed test included, since USE <database> is not working correctly under the test suite, but there is related coverage.

Instead of checking the entire Document, we look at only the relevant statement using sqlparse.split(), and that fix is applied in a few other places. Otherwise a separate statement can influence completion candidates.

The above split logic should also apply to document.text_before_cursor, which is including multiple statements. However, that is beyond the scope of this change.

Also, we converge on using "type":"database" instead of "type":"schema" in the completion engine. This somewhat clears up the confusion between "schema" and "database", and more importantly allows database names with a trailing dot to be suggested as completions in DROP TABLE.

Checklist

  • I added this contribution to the changelog.md file.
  • I added my name to the AUTHORS file (or it's already there).
  • To lint and format the code, I ran
    uv run ruff check && uv run ruff format && uv run mypy --install-types .

@rolandwalker rolandwalker self-assigned this May 1, 2026
Previously, database names were available as candidates when completing
a table name, but if completing a database name, the user had to
manually enter a trailing dot before typing a table name.

It might be even nicer if the dot was appended after the completion, but
did not appear in the candidate menu.  It isn't clear how to do that.
On the other hand, the dot visually distinguishes which candidates are
of which type.

The trailing dot does not appear when a database is completed in a
database-only position such as USE.

There is an xfailed test included, since "USE <database>" is not working
correctly under the test suite, but there is related coverage.

Instead of checking the entire Document, we look at only the relevant
statement using sqlparse.split(), and that fix is applied in a few other
places.  Otherwise a separate statement can influence completion
candidates.

The above split logic should also apply to document.text_before_cursor,
which is including multiple statements.  However, that is beyond the
scope of this change.

Also, we converge on using "type":"database" instead of "type":"schema"
in the completion engine.  This somewhat clears up the confusion
between "schema" and "database", and more importantly allows database
names with a trailing dot to be suggested as completions in
"DROP TABLE".
@rolandwalker rolandwalker force-pushed the RW/append-dot-to-database-before-table branch from fc87caf to 5a52b84 Compare May 1, 2026 15:26
@rolandwalker rolandwalker requested review from amjith and scottnemes May 1, 2026 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant