MCPcopy Create free account
hub / github.com/ipython/ipython / dispatch_custom_completer

Method dispatch_custom_completer

IPython/core/completer.py:1718–1764  ·  view source on GitHub ↗
(self, text)

Source from the content-addressed store, hash-verified

1716 return u'', []
1717
1718 def dispatch_custom_completer(self, text):
1719 if not self.custom_completers:
1720 return
1721
1722 line = self.line_buffer
1723 if not line.strip():
1724 return None
1725
1726 # Create a little structure to pass all the relevant information about
1727 # the current completion to any custom completer.
1728 event = SimpleNamespace()
1729 event.line = line
1730 event.symbol = text
1731 cmd = line.split(None,1)[0]
1732 event.command = cmd
1733 event.text_until_cursor = self.text_until_cursor
1734
1735 # for foo etc, try also to find completer for %foo
1736 if not cmd.startswith(self.magic_escape):
1737 try_magic = self.custom_completers.s_matches(
1738 self.magic_escape + cmd)
1739 else:
1740 try_magic = []
1741
1742 for c in itertools.chain(self.custom_completers.s_matches(cmd),
1743 try_magic,
1744 self.custom_completers.flat_matches(self.text_until_cursor)):
1745 try:
1746 res = c(event)
1747 if res:
1748 # first, try case sensitive match
1749 withcase = [r for r in res if r.startswith(text)]
1750 if withcase:
1751 return withcase
1752 # if none, then case insensitive ones are ok too
1753 text_low = text.lower()
1754 return [r for r in res if r.lower().startswith(text_low)]
1755 except TryNext:
1756 pass
1757 except KeyboardInterrupt:
1758 """
1759 If custom completer take too long,
1760 let keyboard interrupt abort and return nothing.
1761 """
1762 break
1763
1764 return None
1765
1766 def completions(self, text: str, offset: int)->Iterator[Completion]:
1767 """

Callers 1

_completeMethod · 0.95

Calls 2

s_matchesMethod · 0.80
flat_matchesMethod · 0.80

Tested by

no test coverage detected