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

Method _completions

IPython/core/completer.py:3350–3480  ·  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

3348 profiler.dump_stats(output_path)
3349
3350 def _completions(self, full_text: str, offset: int, *, _timeout) -> Iterator[Completion]:
3351 """
3352 Core completion module.Same signature as :any:`completions`, with the
3353 extra `timeout` parameter (in seconds).
3354
3355 Computing jedi's completion ``.type`` can be quite expensive (it is a
3356 lazy property) and can require some warm-up, more warm up than just
3357 computing the ``name`` of a completion. The warm-up can be :
3358
3359 - Long warm-up the first time a module is encountered after
3360 install/update: actually build parse/inference tree.
3361
3362 - first time the module is encountered in a session: load tree from
3363 disk.
3364
3365 We don't want to block completions for tens of seconds so we give the
3366 completer a "budget" of ``_timeout`` seconds per invocation to compute
3367 completions types, the completions that have not yet been computed will
3368 be marked as "unknown" an will have a chance to be computed next round
3369 are things get cached.
3370
3371 Keep in mind that Jedi is not the only thing treating the completion so
3372 keep the timeout short-ish as if we take more than 0.3 second we still
3373 have lots of processing to do.
3374
3375 """
3376 deadline = time.monotonic() + _timeout
3377
3378 before = full_text[:offset]
3379 cursor_line, cursor_column = position_to_cursor(full_text, offset)
3380
3381 jedi_matcher_id = _get_matcher_id(self._jedi_matcher)
3382
3383 def is_non_jedi_result(
3384 result: MatcherResult, identifier: str
3385 ) -> TypeGuard[SimpleMatcherResult]:
3386 return identifier != jedi_matcher_id
3387
3388 results = self._complete(
3389 full_text=full_text, cursor_line=cursor_line, cursor_pos=cursor_column
3390 )
3391
3392 non_jedi_results: dict[str, SimpleMatcherResult] = {
3393 identifier: result
3394 for identifier, result in results.items()
3395 if is_non_jedi_result(result, identifier)
3396 }
3397
3398 jedi_matches = (
3399 cast(_JediMatcherResult, results[jedi_matcher_id])["completions"]
3400 if jedi_matcher_id in results
3401 else ()
3402 )
3403
3404 iter_jm = iter(jedi_matches)
3405 if _timeout:
3406 for jm in iter_jm:
3407 try:

Callers 1

completionsMethod · 0.95

Calls 8

_completeMethod · 0.95
_deduplicateMethod · 0.95
_sortMethod · 0.95
position_to_cursorFunction · 0.85
_get_matcher_idFunction · 0.85
_make_signatureFunction · 0.85
CompletionClass · 0.85
getMethod · 0.80

Tested by

no test coverage detected