Skip to content

Optionally defer completions until N characters have been typed#1547

Merged
rolandwalker merged 1 commit intomainfrom
RW/min-characters-completions-trigger
Feb 16, 2026
Merged

Optionally defer completions until N characters have been typed#1547
rolandwalker merged 1 commit intomainfrom
RW/min-characters-completions-trigger

Conversation

@rolandwalker
Copy link
Contributor

@rolandwalker rolandwalker commented Feb 14, 2026

Description

A strong effort is taken for efficiency on reading the trailing characters, since this prompt_toolkit Filter will run on every keystroke. Though the cost of running the Pygments lexer on every keystroke surely dwarfs this.

If fewer than N characters have been typed, the suggestions can still be summoned by control-space (does not advance into the candidates) or tab (does immediately advance into the candidates).

The motivation is to both reduce distractions and to reduce lag when typing.

There is another way to do this by passing thresholds into mycli/sqlcompleter.py, but it doesn't preserve the ability to summon completions when below the trigger threshold.

Tests are a challenge again because we would need a custom myclirc.

I could almost be convinced to change the default trigger threshold to 3 for all users. It's better! But changing defaults is a bad practice in principle.

xref #1548

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 14, 2026
@rolandwalker rolandwalker force-pushed the RW/min-characters-completions-trigger branch from 391c1ba to ed2f090 Compare February 14, 2026 11:14
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.

Good option for anyone who wants to change it anyway! Tested out various values of the new option and works as expected.

have been typed.

A strong effort is taken for efficiency on reading the trailing
characters, since this prompt_toolkit Filter will run on every
keystroke.  Though the cost of running the Pygments lexer on every
keystroke surely dwarfs this.

If fewer than N characters have been typed, the suggestions can still
be summoned by control-space (does not advance into the candidates) or
tab (does immediately advance into the candidates).

The motivation is to both reduce distractions and to reduce lag when
typing.

There is another way to do this by passing thresholds into
`mycli/sqlcompleter.py`, but it doesn't preserve the ability to summon
completions when below the trigger threshold.
@rolandwalker rolandwalker force-pushed the RW/min-characters-completions-trigger branch from ed2f090 to 735fbb8 Compare February 16, 2026 08:50
@github-actions
Copy link

Findings

  1. Potential cross-instance behavior leak (minor correctness).
    MIN_COMPLETION_TRIGGER is a module global that gets overwritten in each MyCli init. If multiple MyCli instances exist in one process (tests, embedded use), the last-initialized instance controls behavior for all. Consider making complete_while_typing_filter an instance-bound Condition or closing over self.min_completion_trigger so each session is isolated.
    File: mycli/main.py

  2. Missing tests for the new filter logic and config behavior.
    This PR changes completion behavior based on a config value and special-cases source/\.. There are no tests to cover:

  • min_completion_trigger > 1 enabling/disabling auto-complete.
  • The source/\. path punctuation rule.
  • Regression that completions can still be triggered via tab/ctrl-space below threshold (behavior described in PR, but untested).
    Files: mycli/main.py, test/myclirc

Open questions / assumptions

  • Is it acceptable for min_completion_trigger <= 1 to always enable auto-complete (no validation)? If the intended range is >= 1, consider clamping or documenting.
    File: mycli/main.py

If you want, I can suggest a minimal test strategy that avoids full prompt_toolkit integration.

@rolandwalker rolandwalker merged commit f9f4392 into main Feb 16, 2026
10 checks passed
@rolandwalker rolandwalker deleted the RW/min-characters-completions-trigger branch February 16, 2026 08:57
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.

2 participants