Completion context provided as an argument to matchers in the Matcher API v2.
| 615 | |
| 616 | @dataclass |
| 617 | class CompletionContext: |
| 618 | """Completion context provided as an argument to matchers in the Matcher API v2.""" |
| 619 | |
| 620 | # rationale: many legacy matchers relied on completer state (`self.text_until_cursor`) |
| 621 | # which was not explicitly visible as an argument of the matcher, making any refactor |
| 622 | # prone to errors; by explicitly passing `cursor_position` we can decouple the matchers |
| 623 | # from the completer, and make substituting them in sub-classes easier. |
| 624 | |
| 625 | #: Relevant fragment of code directly preceding the cursor. |
| 626 | #: The extraction of token is implemented via splitter heuristic |
| 627 | #: (following readline behaviour for legacy reasons), which is user configurable |
| 628 | #: (by switching the greedy mode). |
| 629 | token: str |
| 630 | |
| 631 | #: The full available content of the editor or buffer |
| 632 | full_text: str |
| 633 | |
| 634 | #: Cursor position in the line (the same for ``full_text`` and ``text``). |
| 635 | cursor_position: int |
| 636 | |
| 637 | #: Cursor line in ``full_text``. |
| 638 | cursor_line: int |
| 639 | |
| 640 | #: The maximum number of completions that will be used downstream. |
| 641 | #: Matchers can use this information to abort early. |
| 642 | #: The built-in Jedi matcher is currently excepted from this limit. |
| 643 | # If not given, return all possible completions. |
| 644 | limit: Optional[int] |
| 645 | |
| 646 | @cached_property |
| 647 | def text_until_cursor(self) -> str: |
| 648 | return self.line_with_cursor[: self.cursor_position] |
| 649 | |
| 650 | @cached_property |
| 651 | def line_with_cursor(self) -> str: |
| 652 | return self.full_text.split("\n")[self.cursor_line] |
| 653 | |
| 654 | |
| 655 | #: Matcher results for API v2. |
no outgoing calls
no test coverage detected
searching dependent graphs…