Determine whether the cursor is in an attribute or global completion context.
(self, line)
| 2585 | GLOBAL = "global" # For global completion |
| 2586 | |
| 2587 | def _determine_completion_context(self, line): |
| 2588 | """ |
| 2589 | Determine whether the cursor is in an attribute or global completion context. |
| 2590 | """ |
| 2591 | # Cursor in string/comment → GLOBAL. |
| 2592 | is_string, is_in_expression = self._is_in_string_or_comment(line) |
| 2593 | if is_string and not is_in_expression: |
| 2594 | return self._CompletionContextType.GLOBAL |
| 2595 | |
| 2596 | # If we're in a template string expression, handle specially |
| 2597 | if is_string and is_in_expression: |
| 2598 | # Extract the expression part - look for the last { that isn't closed |
| 2599 | expr_start = line.rfind("{") |
| 2600 | if expr_start >= 0: |
| 2601 | # We're looking at the expression inside a template string |
| 2602 | expr = line[expr_start + 1 :] |
| 2603 | # Recursively determine the context of the expression |
| 2604 | return self._determine_completion_context(expr) |
| 2605 | |
| 2606 | # Handle plain number literals - should be global context |
| 2607 | # Ex: 3. -42.14 but not 3.1. |
| 2608 | if re.search(r"(?<!\w)(?<!\d\.)([-+]?\d+\.(\d+)?)(?!\w)$", line): |
| 2609 | return self._CompletionContextType.GLOBAL |
| 2610 | |
| 2611 | # Handle all other attribute matches np.ran, d[0].k, (a,b).count, obj._private |
| 2612 | chain_match = re.search(r".*(.+(?<!\s)\.(?:[a-zA-Z_]\w*)?)$", line) |
| 2613 | if chain_match: |
| 2614 | return self._CompletionContextType.ATTRIBUTE |
| 2615 | |
| 2616 | return self._CompletionContextType.GLOBAL |
| 2617 | |
| 2618 | def _is_completing_in_cli_context(self, text: str) -> bool: |
| 2619 | """ |
no test coverage detected