MCPcopy Index your code
hub / github.com/ipython/ipython / CompletionContext

Class CompletionContext

IPython/core/completer.py:617–652  ·  view source on GitHub ↗

Completion context provided as an argument to matchers in the Matcher API v2.

Source from the content-addressed store, hash-verified

615
616@dataclass
617class 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.

Callers 1

_completeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…