Skip to content

Commit 6b4af4e

Browse files
Improve code completion performance (CompletionsMenuControl)
When there are many completions, compute the width of the "meta" column in the completion menu based on the first 200 completions, otherwise this can be very slow.
1 parent 94d5d6e commit 6b4af4e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/prompt_toolkit/layout/menus.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,13 @@ def meta_width(completion: Completion) -> int:
164164
return get_cwidth(completion.display_meta_text)
165165

166166
if self._show_meta(complete_state):
167-
return min(
168-
max_width, max(meta_width(c) for c in complete_state.completions) + 2
169-
)
167+
# If the amount of completions is over 200, compute the width based
168+
# on the first 200 completions, otherwise this can be very slow.
169+
completions = complete_state.completions
170+
if len(completions) > 200:
171+
completions = completions[:200]
172+
173+
return min(max_width, max(meta_width(c) for c in completions) + 2)
170174
else:
171175
return 0
172176

0 commit comments

Comments
 (0)