Skip to content

Commit 386477a

Browse files
Limit number of completions in buffer to 10k by default.
1 parent 491b5e8 commit 386477a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Diff for: src/prompt_toolkit/buffer.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ class Buffer:
179179
In case of a `PromptSession` for instance, we want to keep the text,
180180
because we will exit the application, and only reset it during the next
181181
run.
182+
:param max_number_of_completions: Never display more than this number of
183+
completions, even when the completer can produce more (limited by
184+
default to 10k for performance).
182185
183186
Events:
184187
@@ -225,12 +228,13 @@ def __init__(
225228
accept_handler: BufferAcceptHandler | None = None,
226229
read_only: FilterOrBool = False,
227230
multiline: FilterOrBool = True,
231+
max_number_of_completions: int = 10000,
228232
on_text_changed: BufferEventHandler | None = None,
229233
on_text_insert: BufferEventHandler | None = None,
230234
on_cursor_position_changed: BufferEventHandler | None = None,
231235
on_completions_changed: BufferEventHandler | None = None,
232236
on_suggestion_set: BufferEventHandler | None = None,
233-
):
237+
) -> None:
234238
# Accept both filters and booleans as input.
235239
enable_history_search = to_filter(enable_history_search)
236240
complete_while_typing = to_filter(complete_while_typing)
@@ -252,6 +256,7 @@ def __init__(
252256
self.enable_history_search = enable_history_search
253257
self.read_only = read_only
254258
self.multiline = multiline
259+
self.max_number_of_completions = max_number_of_completions
255260

256261
# Text width. (For wrapping, used by the Vi 'gq' operator.)
257262
self.text_width = 0
@@ -1739,6 +1744,13 @@ async def refresh_while_loading() -> None:
17391744
# If the input text changes, abort.
17401745
if not proceed():
17411746
break
1747+
1748+
# Always stop at 10k completions.
1749+
if (
1750+
len(complete_state.completions)
1751+
>= self.max_number_of_completions
1752+
):
1753+
break
17421754
finally:
17431755
refresh_task.cancel()
17441756

0 commit comments

Comments
 (0)