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

Method _completions

IPython/core/completer.py:1828–1910  ·  view source on GitHub ↗

Core completion module.Same signature as :any:`completions`, with the extra `timeout` parameter (in seconds). Computing jedi's completion ``.type`` can be quite expensive (it is a lazy property) and can require some warm-up, more warm up than just computing

(self, full_text: str, offset: int, *, _timeout)

Source from the content-addressed store, hash-verified

1826 pass
1827
1828 def _completions(self, full_text: str, offset: int, *, _timeout)->Iterator[Completion]:
1829 """
1830 Core completion module.Same signature as :any:`completions`, with the
1831 extra `timeout` parameter (in seconds).
1832
1833
1834 Computing jedi's completion ``.type`` can be quite expensive (it is a
1835 lazy property) and can require some warm-up, more warm up than just
1836 computing the ``name`` of a completion. The warm-up can be :
1837
1838 - Long warm-up the first time a module is encountered after
1839 install/update: actually build parse/inference tree.
1840
1841 - first time the module is encountered in a session: load tree from
1842 disk.
1843
1844 We don't want to block completions for tens of seconds so we give the
1845 completer a "budget" of ``_timeout`` seconds per invocation to compute
1846 completions types, the completions that have not yet been computed will
1847 be marked as "unknown" an will have a chance to be computed next round
1848 are things get cached.
1849
1850 Keep in mind that Jedi is not the only thing treating the completion so
1851 keep the timeout short-ish as if we take more than 0.3 second we still
1852 have lots of processing to do.
1853
1854 """
1855 deadline = time.monotonic() + _timeout
1856
1857
1858 before = full_text[:offset]
1859 cursor_line, cursor_column = position_to_cursor(full_text, offset)
1860
1861 matched_text, matches, matches_origin, jedi_matches = self._complete(
1862 full_text=full_text, cursor_line=cursor_line, cursor_pos=cursor_column)
1863
1864 iter_jm = iter(jedi_matches)
1865 if _timeout:
1866 for jm in iter_jm:
1867 try:
1868 type_ = jm.type
1869 except Exception:
1870 if self.debug:
1871 print("Error in Jedi getting type of ", jm)
1872 type_ = None
1873 delta = len(jm.name_with_symbols) - len(jm.complete)
1874 if type_ == 'function':
1875 signature = _make_signature(jm)
1876 else:
1877 signature = ''
1878 yield Completion(start=offset - delta,
1879 end=offset,
1880 text=jm.name_with_symbols,
1881 type=type_,
1882 signature=signature,
1883 _origin='jedi')
1884
1885 if time.monotonic() > deadline:

Callers 1

completionsMethod · 0.95

Calls 4

_completeMethod · 0.95
position_to_cursorFunction · 0.85
_make_signatureFunction · 0.85
CompletionClass · 0.85

Tested by

no test coverage detected