Show More
@@ -62,6 +62,7 b' skip_doctest = True' | |||
|
62 | 62 | import __main__ |
|
63 | 63 | import builtins as builtin_mod |
|
64 | 64 | import glob |
|
65 | import time | |
|
65 | 66 | import inspect |
|
66 | 67 | import itertools |
|
67 | 68 | import keyword |
@@ -1508,16 +1509,52 b' class IPCompleter(Completer):' | |||
|
1508 | 1509 | yield c |
|
1509 | 1510 | seen.add(c) |
|
1510 | 1511 | |
|
1511 | def _completions(self, full_text: str, offset: int)->Iterator[Completion]: | |
|
1512 | def _completions(self, full_text: str, offset: int, *, _timeout=0.4)->Iterator[Completion]: | |
|
1513 | """ | |
|
1514 | Core completion module.Same signature as :any:`completions`, with the | |
|
1515 | extra `timeout` parameter (in seconds). | |
|
1516 | ||
|
1517 | ||
|
1518 | Computing jedi's completion ``.type`` can be quite expensive (it is a | |
|
1519 | lazy property) and can require some warm-up, more warm up than just | |
|
1520 | computing the ``name`` of a completion. The warm-up can be : | |
|
1521 | ||
|
1522 | - Long warm-up the fisrt time a module is encountered after | |
|
1523 | install/update: actually build parse/inference tree. | |
|
1524 | ||
|
1525 | - first time the module is encountered in a session: load tree from | |
|
1526 | disk. | |
|
1527 | ||
|
1528 | We don't want to block completions for tens of seconds so we give the | |
|
1529 | completer a "budget" of ``_timeout`` seconds per invocation to compute | |
|
1530 | completions types, the completions that have not yet been computed will | |
|
1531 | be marked as "unknown" an will have a chance to be computed next round | |
|
1532 | are things get cached. | |
|
1533 | ||
|
1534 | Keep in mind that Jedi is not the only thing treating the completion so | |
|
1535 | keep the timeout short-ish as if we take more than 0.3 second we still | |
|
1536 | have lots of processing to do. | |
|
1537 | ||
|
1538 | """ | |
|
1539 | deadline = time.monotonic() + _timeout | |
|
1540 | ||
|
1541 | ||
|
1512 | 1542 | before = full_text[:offset] |
|
1513 | 1543 | cursor_line, cursor_column = position_to_cursor(full_text, offset) |
|
1514 | 1544 | |
|
1515 | 1545 | matched_text, matches, matches_origin, jedi_matches = self._complete( |
|
1516 | 1546 | full_text=full_text, cursor_line=cursor_line, cursor_pos=cursor_column) |
|
1517 | 1547 | |
|
1518 |
|
|
|
1548 | iter_jm = iter(jedi_matches) | |
|
1549 | for jm in iter_jm: | |
|
1519 | 1550 | delta = len(jm.name_with_symbols) - len(jm.complete) |
|
1520 | 1551 | yield Completion(start=offset - delta, end=offset, text=jm.name_with_symbols, type=jm.type, _origin='jedi') |
|
1552 | if time.monotonic() > deadline: | |
|
1553 | break | |
|
1554 | ||
|
1555 | for jm in iter_jm: | |
|
1556 | delta = len(jm.name_with_symbols) - len(jm.complete) | |
|
1557 | yield Completion(start=offset - delta, end=offset, text=jm.name_with_symbols+'?', type='<unknown>', _origin='jedi') | |
|
1521 | 1558 | |
|
1522 | 1559 | |
|
1523 | 1560 | start_offset = before.rfind(matched_text) |
General Comments 0
You need to be logged in to leave comments.
Login now