Private equivalent of get_completions() use only for unit_testing.
(self, body, offset, cursor_position, ipyc)
| 133 | print('Unrecoverable Error in completions') |
| 134 | |
| 135 | def _get_completions(self, body, offset, cursor_position, ipyc): |
| 136 | """ |
| 137 | Private equivalent of get_completions() use only for unit_testing. |
| 138 | """ |
| 139 | debug = getattr(ipyc, 'debug', False) |
| 140 | completions = _deduplicate_completions( |
| 141 | body, ipyc.completions(body, offset)) |
| 142 | for c in completions: |
| 143 | if not c.text: |
| 144 | # Guard against completion machinery giving us an empty string. |
| 145 | continue |
| 146 | text = unicodedata.normalize('NFC', c.text) |
| 147 | # When the first character of the completion has a zero length, |
| 148 | # then it's probably a decomposed unicode character. E.g. caused by |
| 149 | # the "\dot" completion. Try to compose again with the previous |
| 150 | # character. |
| 151 | if wcwidth(text[0]) == 0: |
| 152 | if cursor_position + c.start > 0: |
| 153 | char_before = body[c.start - 1] |
| 154 | fixed_text = unicodedata.normalize( |
| 155 | 'NFC', char_before + text) |
| 156 | |
| 157 | # Yield the modified completion instead, if this worked. |
| 158 | if wcwidth(text[0:1]) == 1: |
| 159 | yield Completion(fixed_text, start_position=c.start - offset - 1) |
| 160 | continue |
| 161 | |
| 162 | # TODO: Use Jedi to determine meta_text |
| 163 | # (Jedi currently has a bug that results in incorrect information.) |
| 164 | # meta_text = '' |
| 165 | # yield Completion(m, start_position=start_pos, |
| 166 | # display_meta=meta_text) |
| 167 | display_text = c.text |
| 168 | |
| 169 | adjusted_text = _adjust_completion_text_based_on_context( |
| 170 | c.text, body, offset |
| 171 | ) |
| 172 | min_elide = 30 if self.shell is None else self.shell.min_elide |
| 173 | if c.type == "function": |
| 174 | yield Completion( |
| 175 | adjusted_text, |
| 176 | start_position=c.start - offset, |
| 177 | display=_elide( |
| 178 | display_text + "()", |
| 179 | body[c.start : c.end], |
| 180 | min_elide=min_elide, |
| 181 | ), |
| 182 | display_meta=c.type + c.signature, |
| 183 | ) |
| 184 | else: |
| 185 | yield Completion( |
| 186 | adjusted_text, |
| 187 | start_position=c.start - offset, |
| 188 | display=_elide( |
| 189 | display_text, |
| 190 | body[c.start : c.end], |
| 191 | min_elide=min_elide, |
| 192 | ), |
no test coverage detected