Skip to content

Commit cb925b2

Browse files
Improve code completion performance (meta control of MultiColumnCompletionsMenu).
Improve rendering performance of the "meta" control of the `MultiColumnCompletionsMenu` when there are many completions.
1 parent 643a66d commit cb925b2

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/prompt_toolkit/layout/menus.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,19 @@ def preferred_width(self, max_available_width: int) -> Optional[int]:
709709
app = get_app()
710710
if app.current_buffer.complete_state:
711711
state = app.current_buffer.complete_state
712-
return 2 + max(get_cwidth(c.display_meta_text) for c in state.completions)
712+
713+
if len(state.completions) >= 30:
714+
# When there are many completions, calling `get_cwidth` for
715+
# every `display_meta_text` is too expensive. In this case,
716+
# just return the max available width. There will be enough
717+
# columns anyway so that the whole screen is filled with
718+
# completions and `create_content` will then take up as much
719+
# space as needed.
720+
return max_available_width
721+
722+
return 2 + max(
723+
get_cwidth(c.display_meta_text) for c in state.completions[:100]
724+
)
713725
else:
714726
return 0
715727

0 commit comments

Comments
 (0)