Show More
@@ -77,10 +77,6 b' from IPython.utils.process import arg_split' | |||
|
77 | 77 | from IPython.utils.py3compat import builtin_mod, string_types, PY3, cast_unicode_py2 |
|
78 | 78 | from traitlets import Bool, Enum, observe |
|
79 | 79 | |
|
80 | import jedi | |
|
81 | import jedi.api.helpers | |
|
82 | import jedi.parser.user_context | |
|
83 | ||
|
84 | 80 | #----------------------------------------------------------------------------- |
|
85 | 81 | # Globals |
|
86 | 82 | #----------------------------------------------------------------------------- |
@@ -649,6 +645,7 b' class IPCompleter(Completer):' | |||
|
649 | 645 | |
|
650 | 646 | # All active matcher routines for completion |
|
651 | 647 | self.matchers = [ |
|
648 | self.python_matches, | |
|
652 | 649 | self.file_matches, |
|
653 | 650 | self.magic_matches, |
|
654 | 651 | self.python_func_kw_matches, |
@@ -768,60 +765,6 b' class IPCompleter(Completer):' | |||
|
768 | 765 | comp += [ pre+m for m in line_magics if m.startswith(bare_text)] |
|
769 | 766 | return [cast_unicode_py2(c) for c in comp] |
|
770 | 767 | |
|
771 | def python_jedi_matches(self, text, line_buffer, cursor_pos): | |
|
772 | """Match attributes or global Python names using Jedi.""" | |
|
773 | if line_buffer.startswith('aimport ') or line_buffer.startswith('%aimport '): | |
|
774 | return () | |
|
775 | namespaces = [] | |
|
776 | if self.namespace is None: | |
|
777 | import __main__ | |
|
778 | namespaces.append(__main__.__dict__) | |
|
779 | else: | |
|
780 | namespaces.append(self.namespace) | |
|
781 | if self.global_namespace is not None: | |
|
782 | namespaces.append(self.global_namespace) | |
|
783 | ||
|
784 | # cursor_pos is an it, jedi wants line and column | |
|
785 | ||
|
786 | interpreter = jedi.Interpreter(line_buffer, namespaces, column=cursor_pos) | |
|
787 | path = jedi.parser.user_context.UserContext(line_buffer, \ | |
|
788 | (1, len(line_buffer))).get_path_until_cursor() | |
|
789 | path, dot, like = jedi.api.helpers.completion_parts(path) | |
|
790 | if text.startswith('.'): | |
|
791 | # text will be `.` on completions like `a[0].<tab>` | |
|
792 | before = dot | |
|
793 | else: | |
|
794 | before = line_buffer[:len(line_buffer) - len(like)] | |
|
795 | ||
|
796 | ||
|
797 | def trim_start(completion): | |
|
798 | """completions need to start with `text`, trim the beginning until it does""" | |
|
799 | ltext = text.lower() | |
|
800 | lcomp = completion.lower() | |
|
801 | if ltext in lcomp and not (lcomp.startswith(ltext)): | |
|
802 | start_index = lcomp.index(ltext) | |
|
803 | if cursor_pos: | |
|
804 | if start_index >= cursor_pos: | |
|
805 | start_index = min(start_index, cursor_pos) | |
|
806 | return completion[start_index:] | |
|
807 | return completion | |
|
808 | ||
|
809 | completions = interpreter.completions() | |
|
810 | ||
|
811 | completion_text = [c.name_with_symbols for c in completions] | |
|
812 | ||
|
813 | if self.omit__names: | |
|
814 | if self.omit__names == 1: | |
|
815 | # true if txt is _not_ a __ name, false otherwise: | |
|
816 | no__name = lambda txt: not txt.startswith('__') | |
|
817 | else: | |
|
818 | # true if txt is _not_ a _ name, false otherwise: | |
|
819 | no__name = lambda txt: not txt.startswith('_') | |
|
820 | completion_text = filter(no__name, completion_text) | |
|
821 | ||
|
822 | ||
|
823 | return [trim_start(before + c_text) for c_text in completion_text] | |
|
824 | ||
|
825 | 768 | |
|
826 | 769 | def python_matches(self, text): |
|
827 | 770 | """Match attributes or global python names""" |
@@ -1255,8 +1198,6 b' class IPCompleter(Completer):' | |||
|
1255 | 1198 | # different types of objects. The rlcomplete() method could then |
|
1256 | 1199 | # simply collapse the dict into a list for readline, but we'd have |
|
1257 | 1200 | # richer completion semantics in other evironments. |
|
1258 | self.matches.extend(self.python_jedi_matches(text, line_buffer, cursor_pos)) | |
|
1259 | ||
|
1260 | 1201 | self.matches = sorted(set(self.matches), key=completions_sorting_key) |
|
1261 | 1202 | |
|
1262 | 1203 | return text, self.matches |
@@ -279,20 +279,11 b' def test_greedy_completions():' | |||
|
279 | 279 | _,c = ip.complete('.', line=line, cursor_pos=cursor_pos) |
|
280 | 280 | nt.assert_in(expect, c, message%c) |
|
281 | 281 | |
|
282 | yield _, 'a[0].', 5, '.real', "Should have completed on a[0].: %s" | |
|
283 | yield _, 'a[0].r', 6, '.real', "Should have completed on a[0].r: %s" | |
|
282 | yield _, 'a[0].', 5, 'a[0].real', "Should have completed on a[0].: %s" | |
|
283 | yield _, 'a[0].r', 6, 'a[0].real', "Should have completed on a[0].r: %s" | |
|
284 | 284 | |
|
285 | 285 | if sys.version_info > (3,4): |
|
286 | yield _, 'a[0].from_', 10, '.from_bytes', "Should have completed on a[0].from_: %s" | |
|
287 | ||
|
288 | ||
|
289 | def _2(): | |
|
290 | # jedi bug, this will be empty, makeitfail for now, | |
|
291 | # once jedi is fixed, switch to assert_in | |
|
292 | # https://github.com/davidhalter/jedi/issues/718 | |
|
293 | _,c = ip.complete('.',line='a[0].from', cursor_pos=9) | |
|
294 | nt.assert_not_in('.from_bytes', c, "Should not have completed on a[0].from (jedi bug), if fails, update test to assert_in: %s"%c) | |
|
295 | yield _2 | |
|
286 | yield _, 'a[0].from_', 10, 'a[0].from_bytes', "Should have completed on a[0].from_: %s" | |
|
296 | 287 | |
|
297 | 288 | |
|
298 | 289 |
General Comments 0
You need to be logged in to leave comments.
Login now