Like complete but can also returns raw jedi completions as well as the origin of the completion text. This could (and should) be made much cleaner but that will be simpler once we drop the old (and stateful) :any:`complete` API. With current provisional API,
(self, *, cursor_line, cursor_pos, line_buffer=None, text=None,
full_text=None)
| 3571 | ] |
| 3572 | |
| 3573 | def _complete(self, *, cursor_line, cursor_pos, line_buffer=None, text=None, |
| 3574 | full_text=None) -> _CompleteResult: |
| 3575 | """ |
| 3576 | Like complete but can also returns raw jedi completions as well as the |
| 3577 | origin of the completion text. This could (and should) be made much |
| 3578 | cleaner but that will be simpler once we drop the old (and stateful) |
| 3579 | :any:`complete` API. |
| 3580 | |
| 3581 | With current provisional API, cursor_pos act both (depending on the |
| 3582 | caller) as the offset in the ``text`` or ``line_buffer``, or as the |
| 3583 | ``column`` when passing multiline strings this could/should be renamed |
| 3584 | but would add extra noise. |
| 3585 | |
| 3586 | Parameters |
| 3587 | ---------- |
| 3588 | cursor_line |
| 3589 | Index of the line the cursor is on. 0 indexed. |
| 3590 | cursor_pos |
| 3591 | Position of the cursor in the current line/line_buffer/text. 0 |
| 3592 | indexed. |
| 3593 | line_buffer : optional, str |
| 3594 | The current line the cursor is in, this is mostly due to legacy |
| 3595 | reason that readline could only give a us the single current line. |
| 3596 | Prefer `full_text`. |
| 3597 | text : str |
| 3598 | The current "token" the cursor is in, mostly also for historical |
| 3599 | reasons. as the completer would trigger only after the current line |
| 3600 | was parsed. |
| 3601 | full_text : str |
| 3602 | Full text of the current cell. |
| 3603 | |
| 3604 | Returns |
| 3605 | ------- |
| 3606 | An ordered dictionary where keys are identifiers of completion |
| 3607 | matchers and values are ``MatcherResult``s. |
| 3608 | """ |
| 3609 | |
| 3610 | # if the cursor position isn't given, the only sane assumption we can |
| 3611 | # make is that it's at the end of the line (the common case) |
| 3612 | if cursor_pos is None: |
| 3613 | cursor_pos = len(line_buffer) if text is None else len(text) |
| 3614 | |
| 3615 | if self.use_main_ns: |
| 3616 | self.namespace = __main__.__dict__ |
| 3617 | |
| 3618 | # if text is either None or an empty string, rely on the line buffer |
| 3619 | if (not line_buffer) and full_text: |
| 3620 | line_buffer = full_text.split('\n')[cursor_line] |
| 3621 | if not text: # issue #11508: check line_buffer before calling split_line |
| 3622 | text = ( |
| 3623 | self.splitter.split_line(line_buffer, cursor_pos) if line_buffer else "" |
| 3624 | ) |
| 3625 | |
| 3626 | # If no line buffer is given, assume the input text is all there was |
| 3627 | if line_buffer is None: |
| 3628 | line_buffer = text |
| 3629 | |
| 3630 | # deprecated - do not use `line_buffer` in new code. |