Skip to content

Complete more precisely in the "value" position#1665

Open
rolandwalker wants to merge 1 commit intomainfrom
RW/complete-better-in-the-value-position
Open

Complete more precisely in the "value" position#1665
rolandwalker wants to merge 1 commit intomainfrom
RW/complete-better-in-the-value-position

Conversation

@rolandwalker
Copy link
Contributor

@rolandwalker rolandwalker commented Feb 28, 2026

Description

When in the "value" position, that is, where a value may be referred to such as a literal, function name, or column name, don't offer all keywords, but instead limit keywords to function names and function-alikes.

Pygments has some errors in its designations of keywords vs functions, such as classifying JSON_VALUE() as a keyword, and some missing functions as well, so we amend the values imported from Pygments. At a certain point the amendments would be large enough that we should consider maintaining our own categorical lists. But the amendments are so far not too extensive.

(We might also consider adding loadable function names.)

Since we have made the list of function names more accurate, we can then remove {"type": "keyword"} from the completion candidates when we are in the "value" position (keeping {"type": "function"} which is already present.

Now, functions such as JSON_VALUE() complete in the "value" position, eg, after a SELECT, but mere keywords such as SELECT do not. We no longer suggest SELECT SELECT!

An exception was made here for completions within backticks, which are still not great, and need future work, because the choices are too many. Backtick completions are left in the current state.

As a comment notes, we should better also define "value position" keywords such as CASE and make a separate completion set for them, rather than lumping them into the list of functions as is done here.

There are other edge cases such as CURRENT_TIME, which can occur in the value position but does not take parentheses, and weird ones such as MEMBER OF(), a midfix function which also contains a space in the name.

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 Feb 28, 2026
@github-actions
Copy link

  1. Correctness regression: value-position literals/operators are no longer completable
  • In the select/where/having branch, non-backtick value positions now return only column, function, and alias, with keyword removed (completion_engine.py:362, completion_engine.py:385).
  • This drops completion for valid value-position tokens that are not functions, e.g. NULL, TRUE, FALSE, NOT, BETWEEN, etc. (only CASE was re-added indirectly via functions) (sqlcompleter.py:836).
  • Action: keep a dedicated “value-position keywords/literals” set (separate from function names) and include it in this branch.
  1. Test gap: no guard for the above regression

No security issues found in this PR.

I could not execute tests in this environment because pytest/uv are unavailable.

When in the "value" position, that is, where a value may be referred to
such as a literal, function name, or column name, don't offer all
keywords, but instead limit keywords to function names and function-
alikes.

Pygments has some errors in its designations of keywords vs functions,
such as classifying JSON_VALUE() as a keyword, and some missing
functions as well, so we amend the values imported from Pygments.  At a
certain point the amendments would be large enough that we should
consider maintaining our own categorical lists.  But the amendments are
so far not too extensive.

(We might also consider adding loadable function names.)

Since we have made the list of function names more accurate, we can then
remove '{"type": "keyword"}' from the completion candidates when we are
in the "value" position (keeping '{"type": "function"}' which is already
present.

Now, functions such as JSON_VALUE() complete in the "value" position,
_eg_, after a SELECT, but mere keywords such as SELECT do not.  We no
longer suggest "SELECT SELECT"!

An exception was made here for completions within backticks, which are
still not great, and need future work, because the choices are too
many.  Backtick completions are left in the current state.

As a comment notes, we should better also define "value position"
keywords such as CASE and make a separate completion set for them,
rather than lumping them into the list of functions as is done here.

There are other edge cases such as CURRENT_TIME, which can occur in the
value position but does not take parentheses, and weird ones such as
MEMBER OF(), a midfix function which also contains a space in the name.
@rolandwalker rolandwalker force-pushed the RW/complete-better-in-the-value-position branch from ba8cf46 to a341e6c Compare March 1, 2026 00:08
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