Skip to content

Commit

Permalink
Abbreviate completian meta information for dictionary completer if mu…
Browse files Browse the repository at this point in the history
…ltiline or too long.
  • Loading branch information
jonathanslenders committed Sep 25, 2020
1 parent 54849cb commit 9f7819e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ptpython/completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 9f7819e

Please sign in to comment.