From 9f7819ea4a0df5d7da633a63f1e387c218d216a0 Mon Sep 17 00:00:00 2001 From: Jonathan Slenders Date: Fri, 25 Sep 2020 16:25:39 +0200 Subject: [PATCH] Abbreviate completian meta information for dictionary completer if multiline or too long. --- ptpython/completer.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ptpython/completer.py b/ptpython/completer.py index 9912d743..e4b43fc0 100644 --- a/ptpython/completer.py +++ b/ptpython/completer.py @@ -368,6 +368,16 @@ def _get_item_lookup_completions( """ Complete dictionary keys. """ + + def abbr_meta(text: str) -> str: + " Abbreviate meta text, make sure it fits on one line. " + # Take first line, if multiple lines. + if len(text) > 20: + text = text[:20] + "..." + if "\n" in text: + text = text.split("\n", 1)[0] + "..." + return text + match = self.item_lookup_pattern.search(document.text_before_cursor) if match is not None: object_var, key = match.groups() @@ -395,7 +405,7 @@ def _get_item_lookup_completions( k_repr + "]", -len(key), display=f"[{k_repr}]", - display_meta=self._do_repr(result[k]), + display_meta=abbr_meta(self._do_repr(result[k])), ) except ReprFailedError: pass @@ -411,7 +421,7 @@ def _get_item_lookup_completions( k_repr + "]", -len(key), display=f"[{k_repr}]", - display_meta=self._do_repr(result[k]), + display_meta=abbr_meta(self._do_repr(result[k])), ) except ReprFailedError: pass