Skip to content

Prioritize common functions in the value position#1669

Open
rolandwalker wants to merge 1 commit intomainfrom
RW/add-favorite-functions
Open

Prioritize common functions in the value position#1669
rolandwalker wants to merge 1 commit intomainfrom
RW/add-favorite-functions

Conversation

@rolandwalker
Copy link
Contributor

@rolandwalker rolandwalker commented Mar 2, 2026

Description

Like favorite_keywords, add a list of favorite_functions which should be ordered ahead when completing function names in the value position.

Currently the only real effect this has is to suggest JSON_VALUE() ahead of JSON_VALID(), resolving a small common annoyance. But we should further curate the list of favorites.

Another longstanding idea is to have dynamic frecency govern the list of favorites.

There happened to be a test case for JSON_VALUE/JSON_VALID already.

Since MySQL styles some functions as title case, we incidentally start to make some allowances for that here, but it doesn't yet show up in the UI. Ideally it would.

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 Mar 2, 2026
@github-actions
Copy link

github-actions bot commented Mar 2, 2026

  1. Correctness regression: function-name escaping is now case-sensitive for some builtins
    In sqlcompleter.py:846 the PR stopped uppercasing all function names before building self.functions. But escape_name() still checks name.upper() in self.functions.
    For mixed-case entries introduced via pygments_missing_functions (e.g. LineString, GeometryCollection), this check now fails, so identifiers that should be escaped as reserved function names may no longer be escaped (behavioral regression).
    Action: either normalize self.functions to a canonical case for membership checks, or maintain a separate folded/upper set used by escape_name().

  2. Missing regression test around escaping with mixed-case builtin functions
    The updated tests in test_smart_completion_public_schema_only.py validate ordering/casing for completion output, but don’t cover the escape_name() path impacted by mixed-case function entries.
    Action: add a test asserting names colliding with mixed-case builtins (e.g. linestring) are still escaped consistently.

No direct security issues found in this diff.

@rolandwalker
Copy link
Contributor Author

Correctness regression: function-name escaping is now case-sensitive for some builtins
In sqlcompleter.py:846 the PR stopped uppercasing all function names before building self.functions. But escape_name() still checks name.upper() in self.functions

The bot makes a good point! The half-implementation of case-folding is too much incomplete.

@rolandwalker rolandwalker force-pushed the RW/add-favorite-functions branch from de44d39 to 2875c7b Compare March 3, 2026 09:31
Like favorite_keywords, add a list of favorite_functions which should be
ordered ahead when completing function names in the value position.

Currently the only real effect this has is to suggest JSON_VALUE() ahead
of JSON_VALID(), resolving a small common annoyance.  But we should
further curate the list of favorites.

Another longstanding idea is to have dynamic frecency govern the list of
favorites.

There happened to be a test case for JSON_VALUE/JSON_VALID already.
@rolandwalker rolandwalker force-pushed the RW/add-favorite-functions branch from 2875c7b to 97a6ed3 Compare March 3, 2026 09:43
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