Show More
@@ -86,7 +86,7 b' from IPython.utils import generics' | |||
|
86 | 86 | from IPython.utils.dir2 import dir2, get_real_method |
|
87 | 87 | from IPython.utils.process import arg_split |
|
88 | 88 | from IPython.utils.py3compat import cast_unicode_py2 |
|
89 | from traitlets import Bool, Enum, observe | |
|
89 | from traitlets import Bool, Enum, observe, Int | |
|
90 | 90 | |
|
91 | 91 | try: |
|
92 | 92 | import jedi |
@@ -475,6 +475,12 b' class Completer(Configurable):' | |||
|
475 | 475 | help="Experimental: Use Jedi to generate autocompletions. " |
|
476 | 476 | "Default to True if jedi is installed").tag(config=True) |
|
477 | 477 | |
|
478 | jedi_compute_type_timeout = Int(default_value=400, | |
|
479 | help="""Experimental: restrict time (in milliseconds) during which Jedi can compute types. | |
|
480 | Set to 0 to stop computing types. Non-zero value lower than 100ms may hurt | |
|
481 | performance by preventing jedi to build its cache. | |
|
482 | """).tag(config=True) | |
|
483 | ||
|
478 | 484 | debug = Bool(default_value=False, |
|
479 | 485 | help='Enable debug for the Completer. Mostly print extra ' |
|
480 | 486 | 'information for experimental jedi integration.')\ |
@@ -1503,13 +1509,13 b' class IPCompleter(Completer):' | |||
|
1503 | 1509 | # - `.real` from 1 to 2 |
|
1504 | 1510 | # the current code does not (yet) check for such equivalence |
|
1505 | 1511 | seen = set() |
|
1506 | for c in self._completions(text, offset): | |
|
1512 | for c in self._completions(text, offset, _timeout=self.jedi_compute_type_timeout/1000): | |
|
1507 | 1513 | if c and (c in seen): |
|
1508 | 1514 | continue |
|
1509 | 1515 | yield c |
|
1510 | 1516 | seen.add(c) |
|
1511 | 1517 | |
|
1512 |
def _completions(self, full_text: str, offset: int, *, _timeout |
|
|
1518 | def _completions(self, full_text: str, offset: int, *, _timeout)->Iterator[Completion]: | |
|
1513 | 1519 | """ |
|
1514 | 1520 | Core completion module.Same signature as :any:`completions`, with the |
|
1515 | 1521 | extra `timeout` parameter (in seconds). |
@@ -1546,15 +1552,25 b' class IPCompleter(Completer):' | |||
|
1546 | 1552 | full_text=full_text, cursor_line=cursor_line, cursor_pos=cursor_column) |
|
1547 | 1553 | |
|
1548 | 1554 | iter_jm = iter(jedi_matches) |
|
1555 | if _timeout: | |
|
1549 | 1556 | for jm in iter_jm: |
|
1550 | 1557 | delta = len(jm.name_with_symbols) - len(jm.complete) |
|
1551 | yield Completion(start=offset - delta, end=offset, text=jm.name_with_symbols, type=jm.type, _origin='jedi') | |
|
1558 | yield Completion(start=offset - delta, | |
|
1559 | end=offset, | |
|
1560 | text=jm.name_with_symbols, | |
|
1561 | type=jm.type, | |
|
1562 | _origin='jedi') | |
|
1563 | ||
|
1552 | 1564 | if time.monotonic() > deadline: |
|
1553 | 1565 | break |
|
1554 | 1566 | |
|
1555 | 1567 | for jm in iter_jm: |
|
1556 | 1568 | 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') | |
|
1569 | yield Completion(start=offset - delta, | |
|
1570 | end=offset, | |
|
1571 | text=jm.name_with_symbols, | |
|
1572 | type='<unknown>', # don't compute type for speed | |
|
1573 | _origin='jedi') | |
|
1558 | 1574 | |
|
1559 | 1575 | |
|
1560 | 1576 | start_offset = before.rfind(matched_text) |
General Comments 0
You need to be logged in to leave comments.
Login now