Show More
@@ -191,7 +191,8 b' import unicodedata' | |||||
191 | import uuid |
|
191 | import uuid | |
192 | import warnings |
|
192 | import warnings | |
193 | from contextlib import contextmanager |
|
193 | from contextlib import contextmanager | |
194 | from functools import lru_cache, partial |
|
194 | from dataclasses import dataclass | |
|
195 | from functools import cached_property, partial | |||
195 | from importlib import import_module |
|
196 | from importlib import import_module | |
196 | from types import SimpleNamespace |
|
197 | from types import SimpleNamespace | |
197 | from typing import ( |
|
198 | from typing import ( | |
@@ -597,7 +598,8 b' class _JediMatcherResult(_MatcherResultBase):' | |||||
597 | completions: Iterable[_JediCompletionLike] |
|
598 | completions: Iterable[_JediCompletionLike] | |
598 |
|
599 | |||
599 |
|
600 | |||
600 | class CompletionContext(NamedTuple): |
|
601 | @dataclass | |
|
602 | class CompletionContext: | |||
601 | """Completion context provided as an argument to matchers in the Matcher API v2.""" |
|
603 | """Completion context provided as an argument to matchers in the Matcher API v2.""" | |
602 |
|
604 | |||
603 | # rationale: many legacy matchers relied on completer state (`self.text_until_cursor`) |
|
605 | # rationale: many legacy matchers relied on completer state (`self.text_until_cursor`) | |
@@ -626,13 +628,11 b' class CompletionContext(NamedTuple):' | |||||
626 | # If not given, return all possible completions. |
|
628 | # If not given, return all possible completions. | |
627 | limit: Optional[int] |
|
629 | limit: Optional[int] | |
628 |
|
630 | |||
629 | @property |
|
631 | @cached_property | |
630 | @lru_cache(maxsize=None) # TODO change to @cache after dropping Python 3.7 |
|
|||
631 | def text_until_cursor(self) -> str: |
|
632 | def text_until_cursor(self) -> str: | |
632 | return self.line_with_cursor[: self.cursor_position] |
|
633 | return self.line_with_cursor[: self.cursor_position] | |
633 |
|
634 | |||
634 | @property |
|
635 | @cached_property | |
635 | @lru_cache(maxsize=None) # TODO change to @cache after dropping Python 3.7 |
|
|||
636 | def line_with_cursor(self) -> str: |
|
636 | def line_with_cursor(self) -> str: | |
637 | return self.full_text.split("\n")[self.cursor_line] |
|
637 | return self.full_text.split("\n")[self.cursor_line] | |
638 |
|
638 |
General Comments 0
You need to be logged in to leave comments.
Login now