Skip to content

Conversation

@rolandwalker
Copy link
Contributor

@rolandwalker rolandwalker commented Jan 31, 2026

Description

Instead of going only in the order of for suggestion in suggestions:, retain the implied rank of the order of suggestion types, and the fuzziness of the match from find_matches(), and sort by all of fuzziness, rank, and leading match.

Primarily this allows the fuzzy matches to always be demoted to the bottom of the list of candidates.

The sort-key algorithm takes into account fuzziness, suggestion-rank, and leading-match, but how exactly depends on whether the completion string is empty, or the completion string is a leading match.

To implement this, sorting must be moved out of find_matches().

A special case rigid_sort is provided so that directories continue to be forced to last in filename sorts. This could be improved in the future.

The motivation is to make #1497 more able to combine column names and keywords.

The tests are pretty broken in this draft, part of which is expected. fixed.

Checklist

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

@rolandwalker rolandwalker force-pushed the RW/refactor-completion-candidate-sorting branch from dc0f2b2 to 0e997dd Compare January 31, 2026 18:56
@rolandwalker rolandwalker force-pushed the RW/refactor-completion-candidate-sorting branch 3 times, most recently from c0ec4a3 to 1247721 Compare January 31, 2026 20:00
Instead of going only in the order of "for suggestion in suggestions:",
retain the implied rank of the order of suggestion types, and the
fuzziness of the match from find_matches(), and sort by all of
fuzziness, rank, and leading match.

Primarily this allows the fuzzy matches to always be demoted to the
bottom of the list of candidates.

The sort-key algorithm takes into account fuzziness, suggestion-rank,
and leading-match, but how exactly depends on whether the completion
string is empty, or the completion string is a leading match.

To implement this, sorting must be moved out of find_matches().

A special case "rigid_sort" is provided so that directories continue
to be forced to last in filename sorts.  This could be improved in the
future.
@rolandwalker rolandwalker force-pushed the RW/refactor-completion-candidate-sorting branch from 1247721 to ca43541 Compare January 31, 2026 20:05
@rolandwalker rolandwalker marked this pull request as ready for review January 31, 2026 20:07
@rolandwalker rolandwalker changed the title WIP: refactor completion candidate sorting Refactor completion candidate sorting Jan 31, 2026
@rolandwalker rolandwalker self-assigned this Jan 31, 2026
Copy link
Contributor

@scottnemes scottnemes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice that was a lot to tie together! Verified completions with more exact matches seem to come back first now for normal / camel case / snake case columns and functions/keywords.

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.

3 participants