From c6e08221ce1ede295b930abb9a493cb6cb9540bb Mon Sep 17 00:00:00 2001 From: David Halter Date: Wed, 7 Aug 2013 10:24:28 +0430 Subject: [PATCH] fixed more import problems (also with the `import` usage), definitely fixes davidhalter/jedi-vim#152 --- jedi/api.py | 3 ++- jedi/imports.py | 10 ++++++---- jedi/modules.py | 6 ++++-- test/completion/imports.py | 4 +++- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/jedi/api.py b/jedi/api.py index 73b60421..e8df0e37 100644 --- a/jedi/api.py +++ b/jedi/api.py @@ -112,7 +112,8 @@ class Script(object): names = s.get_magic_method_names() else: if isinstance(s, imports.ImportPath): - if like == 'import': + under = like + self._module.get_path_after_cursor() + if under == 'import': if not completion_line.endswith('import import'): continue a = s.import_stmt.alias diff --git a/jedi/imports.py b/jedi/imports.py index bed6fd0c..117bc856 100644 --- a/jedi/imports.py +++ b/jedi/imports.py @@ -153,14 +153,16 @@ class ImportPath(pr.Base): return pr.Name(self.GlobalNamespace, [(name, inf_pos)], inf_pos, inf_pos, self.import_stmt) - if not search_path: - search_path = self.sys_path_with_modifications() names = [] inf_pos = float('inf'), float('inf') + # add builtin module names + if search_path is None: + names += [generate_name(name) for name in sys.builtin_module_names] + + if search_path is None: + search_path = self.sys_path_with_modifications() for module_loader, name, is_pkg in pkgutil.iter_modules(search_path): names.append(generate_name(name)) - # add builtin module names - names += [generate_name(name) for name in sys.builtin_module_names] return names def sys_path_with_modifications(self): diff --git a/jedi/modules.py b/jedi/modules.py index a8193bed..396d57b5 100644 --- a/jedi/modules.py +++ b/jedi/modules.py @@ -208,9 +208,11 @@ class ModuleWithCursor(Module): Return the path under the cursor. If there is a rest of the path left, it will be added to the stuff before it. """ + return self.get_path_until_cursor() + self.get_path_after_cursor() + + def get_path_after_cursor(self): line = self.get_line(self.position[0]) - after = re.search("[\w\d]*", line[self.position[1]:]).group(0) - return self.get_path_until_cursor() + after + return re.search("[\w\d]*", line[self.position[1]:]).group(0) def get_operator_under_cursor(self): line = self.get_line(self.position[0]) diff --git a/test/completion/imports.py b/test/completion/imports.py index 95be6668..c1653e05 100644 --- a/test/completion/imports.py +++ b/test/completion/imports.py @@ -211,7 +211,9 @@ import datetime. #? [] import datetime.date -#? 18 ['mod1', 'random', 'pkg', 'rename1', 'rename2', 'import', 'recurse_class1', 'recurse_class2'] +#? 18 ['import'] +from import_tree. import pkg +#? 17 ['mod1', 'random', 'pkg', 'rename1', 'rename2', 'recurse_class1', 'recurse_class2'] from import_tree. import pkg #? 18 ['pkg']