##// END OF EJS Templates
Allow to completely deactivate jedi type inference....
Matthias Bussonnier -
Show More
@@ -86,7 +86,7 b' from IPython.utils import generics'
86 from IPython.utils.dir2 import dir2, get_real_method
86 from IPython.utils.dir2 import dir2, get_real_method
87 from IPython.utils.process import arg_split
87 from IPython.utils.process import arg_split
88 from IPython.utils.py3compat import cast_unicode_py2
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 try:
91 try:
92 import jedi
92 import jedi
@@ -475,6 +475,12 b' class Completer(Configurable):'
475 help="Experimental: Use Jedi to generate autocompletions. "
475 help="Experimental: Use Jedi to generate autocompletions. "
476 "Default to True if jedi is installed").tag(config=True)
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 debug = Bool(default_value=False,
484 debug = Bool(default_value=False,
479 help='Enable debug for the Completer. Mostly print extra '
485 help='Enable debug for the Completer. Mostly print extra '
480 'information for experimental jedi integration.')\
486 'information for experimental jedi integration.')\
@@ -1503,13 +1509,13 b' class IPCompleter(Completer):'
1503 # - `.real` from 1 to 2
1509 # - `.real` from 1 to 2
1504 # the current code does not (yet) check for such equivalence
1510 # the current code does not (yet) check for such equivalence
1505 seen = set()
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 if c and (c in seen):
1513 if c and (c in seen):
1508 continue
1514 continue
1509 yield c
1515 yield c
1510 seen.add(c)
1516 seen.add(c)
1511
1517
1512 def _completions(self, full_text: str, offset: int, *, _timeout=0.4)->Iterator[Completion]:
1518 def _completions(self, full_text: str, offset: int, *, _timeout)->Iterator[Completion]:
1513 """
1519 """
1514 Core completion module.Same signature as :any:`completions`, with the
1520 Core completion module.Same signature as :any:`completions`, with the
1515 extra `timeout` parameter (in seconds).
1521 extra `timeout` parameter (in seconds).
@@ -1546,15 +1552,25 b' class IPCompleter(Completer):'
1546 full_text=full_text, cursor_line=cursor_line, cursor_pos=cursor_column)
1552 full_text=full_text, cursor_line=cursor_line, cursor_pos=cursor_column)
1547
1553
1548 iter_jm = iter(jedi_matches)
1554 iter_jm = iter(jedi_matches)
1549 for jm in iter_jm:
1555 if _timeout:
1550 delta = len(jm.name_with_symbols) - len(jm.complete)
1556 for jm in iter_jm:
1551 yield Completion(start=offset - delta, end=offset, text=jm.name_with_symbols, type=jm.type, _origin='jedi')
1557 delta = len(jm.name_with_symbols) - len(jm.complete)
1552 if time.monotonic() > deadline:
1558 yield Completion(start=offset - delta,
1553 break
1559 end=offset,
1560 text=jm.name_with_symbols,
1561 type=jm.type,
1562 _origin='jedi')
1563
1564 if time.monotonic() > deadline:
1565 break
1554
1566
1555 for jm in iter_jm:
1567 for jm in iter_jm:
1556 delta = len(jm.name_with_symbols) - len(jm.complete)
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 start_offset = before.rfind(matched_text)
1576 start_offset = before.rfind(matched_text)
General Comments 0
You need to be logged in to leave comments. Login now