Skip to content

Limit number of completions in buffer to 10k by default. #1872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/prompt_toolkit/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ class Buffer:
In case of a `PromptSession` for instance, we want to keep the text,
because we will exit the application, and only reset it during the next
run.
:param max_number_of_completions: Never display more than this number of
completions, even when the completer can produce more (limited by
default to 10k for performance).

Events:

Expand Down Expand Up @@ -225,12 +228,13 @@ def __init__(
accept_handler: BufferAcceptHandler | None = None,
read_only: FilterOrBool = False,
multiline: FilterOrBool = True,
max_number_of_completions: int = 10000,
on_text_changed: BufferEventHandler | None = None,
on_text_insert: BufferEventHandler | None = None,
on_cursor_position_changed: BufferEventHandler | None = None,
on_completions_changed: BufferEventHandler | None = None,
on_suggestion_set: BufferEventHandler | None = None,
):
) -> None:
# Accept both filters and booleans as input.
enable_history_search = to_filter(enable_history_search)
complete_while_typing = to_filter(complete_while_typing)
Expand All @@ -252,6 +256,7 @@ def __init__(
self.enable_history_search = enable_history_search
self.read_only = read_only
self.multiline = multiline
self.max_number_of_completions = max_number_of_completions

# Text width. (For wrapping, used by the Vi 'gq' operator.)
self.text_width = 0
Expand Down Expand Up @@ -1739,6 +1744,13 @@ async def refresh_while_loading() -> None:
# If the input text changes, abort.
if not proceed():
break

# Always stop at 10k completions.
if (
len(complete_state.completions)
>= self.max_number_of_completions
):
break
finally:
refresh_task.cancel()

Expand Down
Loading