@@ -179,6 +179,9 @@ class Buffer:
179
179
In case of a `PromptSession` for instance, we want to keep the text,
180
180
because we will exit the application, and only reset it during the next
181
181
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).
182
185
183
186
Events:
184
187
@@ -225,12 +228,13 @@ def __init__(
225
228
accept_handler : BufferAcceptHandler | None = None ,
226
229
read_only : FilterOrBool = False ,
227
230
multiline : FilterOrBool = True ,
231
+ max_number_of_completions : int = 10000 ,
228
232
on_text_changed : BufferEventHandler | None = None ,
229
233
on_text_insert : BufferEventHandler | None = None ,
230
234
on_cursor_position_changed : BufferEventHandler | None = None ,
231
235
on_completions_changed : BufferEventHandler | None = None ,
232
236
on_suggestion_set : BufferEventHandler | None = None ,
233
- ):
237
+ ) -> None :
234
238
# Accept both filters and booleans as input.
235
239
enable_history_search = to_filter (enable_history_search )
236
240
complete_while_typing = to_filter (complete_while_typing )
@@ -252,6 +256,7 @@ def __init__(
252
256
self .enable_history_search = enable_history_search
253
257
self .read_only = read_only
254
258
self .multiline = multiline
259
+ self .max_number_of_completions = max_number_of_completions
255
260
256
261
# Text width. (For wrapping, used by the Vi 'gq' operator.)
257
262
self .text_width = 0
@@ -1739,6 +1744,13 @@ async def refresh_while_loading() -> None:
1739
1744
# If the input text changes, abort.
1740
1745
if not proceed ():
1741
1746
break
1747
+
1748
+ # Always stop at 10k completions.
1749
+ if (
1750
+ len (complete_state .completions )
1751
+ >= self .max_number_of_completions
1752
+ ):
1753
+ break
1742
1754
finally :
1743
1755
refresh_task .cancel ()
1744
1756
0 commit comments