Match attributes or global python names
(self, context: CompletionContext)
| 2768 | |
| 2769 | @context_matcher() |
| 2770 | def python_matcher(self, context: CompletionContext) -> SimpleMatcherResult: |
| 2771 | """Match attributes or global python names""" |
| 2772 | text = context.text_until_cursor |
| 2773 | text = self._extract_code(text) |
| 2774 | in_cli_context = self._is_completing_in_cli_context(text) |
| 2775 | if in_cli_context: |
| 2776 | completion_type = self._CompletionContextType.GLOBAL |
| 2777 | else: |
| 2778 | completion_type = self._determine_completion_context(text) |
| 2779 | if completion_type == self._CompletionContextType.ATTRIBUTE: |
| 2780 | try: |
| 2781 | matches, fragment = self._attr_matches( |
| 2782 | text, include_prefix=False, context=context |
| 2783 | ) |
| 2784 | if text.endswith(".") and self.omit__names: |
| 2785 | if self.omit__names == 1: |
| 2786 | # true if txt is _not_ a __ name, false otherwise: |
| 2787 | no__name = lambda txt: re.match(r".*\.__.*?__", txt) is None |
| 2788 | else: |
| 2789 | # true if txt is _not_ a _ name, false otherwise: |
| 2790 | no__name = ( |
| 2791 | lambda txt: re.match(r"\._.*?", txt[txt.rindex(".") :]) |
| 2792 | is None |
| 2793 | ) |
| 2794 | matches = filter(no__name, matches) |
| 2795 | matches = _convert_matcher_v1_result_to_v2( |
| 2796 | matches, type="attribute", fragment=fragment |
| 2797 | ) |
| 2798 | return matches |
| 2799 | except NameError: |
| 2800 | # catches <undefined attributes>.<tab> |
| 2801 | return SimpleMatcherResult(completions=[], suppress=False) |
| 2802 | else: |
| 2803 | try: |
| 2804 | matches = self.global_matches(context.token, context=context) |
| 2805 | except TypeError: |
| 2806 | matches = self.global_matches(context.token) |
| 2807 | # TODO: maybe distinguish between functions, modules and just "variables" |
| 2808 | return SimpleMatcherResult( |
| 2809 | completions=[ |
| 2810 | SimpleCompletion(text=match, type="variable") for match in matches |
| 2811 | ], |
| 2812 | suppress=False, |
| 2813 | ) |
| 2814 | |
| 2815 | @completion_matcher(api_version=1) |
| 2816 | def python_matches(self, text: str) -> Iterable[str]: |
nothing calls this directly
no test coverage detected