##// END OF EJS Templates
Try to elide long completion based on user input....
Matthias Bussonnier -
Show More
@@ -2217,7 +2217,7 b' class InteractiveShell(SingletonConfigurable):'
2217 2217 The position argument (defaults to 0) is the index in the completers
2218 2218 list where you want the completer to be inserted."""
2219 2219
2220 newcomp = types.MethodType(completer,self.Completer)
2220 newcomp = types.MethodType(completer, self.Completer)
2221 2221 self.Completer.custom_matchers.insert(pos,newcomp)
2222 2222
2223 2223 def set_completer_frame(self, frame=None):
@@ -23,7 +23,7 b' import os'
23 23
24 24 _completion_sentinel = object()
25 25
26 def _elide(string, *, min_elide=30):
26 def _elide_point(string, *, min_elide=30):
27 27 """
28 28 If a string is long enough, and has at least 3 dots,
29 29 replace the middle part with ellipses.
@@ -53,6 +53,24 b' def _elide(string, *, min_elide=30):'
53 53
54 54 return string
55 55
56 def _elide_typed(string, typed, *, min_elide=30):
57 """
58 Elide the middle of a long string if the beginning has already been typed.
59 """
60
61 if len(string) < min_elide:
62 return string
63 cut_how_much = len(typed)-3
64 if string.startswith(typed) and len(string)> len(typed):
65 return f"{string[:3]}\N{HORIZONTAL ELLIPSIS}{string[cut_how_much:]}"
66 return string
67
68 def _elide(string, typed, min_elide=30):
69 return _elide_typed(
70 _elide_point(string, min_elide=min_elide),
71 typed, min_elide=min_elide)
72
73
56 74
57 75 def _adjust_completion_text_based_on_context(text, body, offset):
58 76 if text.endswith('=') and len(body) > offset and body[offset] == '=':
@@ -89,7 +107,11 b' class IPythonPTCompleter(Completer):'
89 107 cursor_col = document.cursor_position_col
90 108 cursor_position = document.cursor_position
91 109 offset = cursor_to_position(body, cursor_row, cursor_col)
92 yield from self._get_completions(body, offset, cursor_position, self.ipy_completer)
110 try:
111 yield from self._get_completions(body, offset, cursor_position, self.ipy_completer)
112 except Exception as e:
113 from traceback import print_tb
114 print_tb(e)
93 115
94 116 @staticmethod
95 117 def _get_completions(body, offset, cursor_position, ipyc):
@@ -128,9 +150,9 b' class IPythonPTCompleter(Completer):'
128 150
129 151 adjusted_text = _adjust_completion_text_based_on_context(c.text, body, offset)
130 152 if c.type == 'function':
131 yield Completion(adjusted_text, start_position=c.start - offset, display=_elide(display_text+'()'), display_meta=c.type+c.signature)
153 yield Completion(adjusted_text, start_position=c.start - offset, display=_elide(display_text+'()', body[c.start:c.end]), display_meta=c.type+c.signature)
132 154 else:
133 yield Completion(adjusted_text, start_position=c.start - offset, display=_elide(display_text), display_meta=c.type)
155 yield Completion(adjusted_text, start_position=c.start - offset, display=_elide(display_text, body[c.start:c.end]), display_meta=c.type)
134 156
135 157 class IPythonPTLexer(Lexer):
136 158 """
General Comments 0
You need to be logged in to leave comments. Login now