MCPcopy Create free account
hub / github.com/ipython/ipython / _get_completions

Method _get_completions

IPython/terminal/ptutils.py:122–160  ·  view source on GitHub ↗

Private equivalent of get_completions() use only for unit_testing.

(body, offset, cursor_position, ipyc)

Source from the content-addressed store, hash-verified

120
121 @staticmethod
122 def _get_completions(body, offset, cursor_position, ipyc):
123 """
124 Private equivalent of get_completions() use only for unit_testing.
125 """
126 debug = getattr(ipyc, 'debug', False)
127 completions = _deduplicate_completions(
128 body, ipyc.completions(body, offset))
129 for c in completions:
130 if not c.text:
131 # Guard against completion machinery giving us an empty string.
132 continue
133 text = unicodedata.normalize('NFC', c.text)
134 # When the first character of the completion has a zero length,
135 # then it's probably a decomposed unicode character. E.g. caused by
136 # the "\dot" completion. Try to compose again with the previous
137 # character.
138 if wcwidth(text[0]) == 0:
139 if cursor_position + c.start > 0:
140 char_before = body[c.start - 1]
141 fixed_text = unicodedata.normalize(
142 'NFC', char_before + text)
143
144 # Yield the modified completion instead, if this worked.
145 if wcwidth(text[0:1]) == 1:
146 yield Completion(fixed_text, start_position=c.start - offset - 1)
147 continue
148
149 # TODO: Use Jedi to determine meta_text
150 # (Jedi currently has a bug that results in incorrect information.)
151 # meta_text = ''
152 # yield Completion(m, start_position=start_pos,
153 # display_meta=meta_text)
154 display_text = c.text
155
156 adjusted_text = _adjust_completion_text_based_on_context(c.text, body, offset)
157 if c.type == 'function':
158 yield Completion(adjusted_text, start_position=c.start - offset, display=_elide(display_text+'()', body[c.start:c.end]), display_meta=c.type+c.signature)
159 else:
160 yield Completion(adjusted_text, start_position=c.start - offset, display=_elide(display_text, body[c.start:c.end]), display_meta=c.type)
161
162class IPythonPTLexer(Lexer):
163 """

Callers 1

get_completionsMethod · 0.95

Calls 5

_deduplicate_completionsFunction · 0.90
CompletionClass · 0.85
_elideFunction · 0.85
completionsMethod · 0.80

Tested by

no test coverage detected