Determine if we are completing in a CLI alias, line magic, or bang expression context.
(self, text: str)
| 2616 | return self._CompletionContextType.GLOBAL |
| 2617 | |
| 2618 | def _is_completing_in_cli_context(self, text: str) -> bool: |
| 2619 | """ |
| 2620 | Determine if we are completing in a CLI alias, line magic, or bang expression context. |
| 2621 | """ |
| 2622 | stripped = text.lstrip() |
| 2623 | if stripped.startswith("!") or stripped.startswith("%"): |
| 2624 | return True |
| 2625 | # Check for CLI aliases |
| 2626 | try: |
| 2627 | tokens = stripped.split(None, 1) |
| 2628 | if not tokens: |
| 2629 | return False |
| 2630 | first_token = tokens[0] |
| 2631 | |
| 2632 | # Must have arguments after the command for this to apply |
| 2633 | if len(tokens) < 2: |
| 2634 | return False |
| 2635 | |
| 2636 | # Check if first token is a known alias |
| 2637 | if not any( |
| 2638 | alias[0] == first_token for alias in self.shell.alias_manager.aliases |
| 2639 | ): |
| 2640 | return False |
| 2641 | |
| 2642 | try: |
| 2643 | if first_token in self.shell.user_ns: |
| 2644 | # There's a variable defined, so the alias is overshadowed |
| 2645 | return False |
| 2646 | except (AttributeError, KeyError): |
| 2647 | pass |
| 2648 | |
| 2649 | return True |
| 2650 | except Exception: |
| 2651 | return False |
| 2652 | |
| 2653 | def _is_in_string_or_comment(self, text): |
| 2654 | """ |
no outgoing calls
no test coverage detected