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

Method _is_completing_in_cli_context

IPython/core/completer.py:2618–2651  ·  view source on GitHub ↗

Determine if we are completing in a CLI alias, line magic, or bang expression context.

(self, text: str)

Source from the content-addressed store, hash-verified

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 """

Callers 2

file_matcherMethod · 0.95
python_matcherMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected