forked from VimPlug/jedi
also enable autocompletion on namespace packages, fixes #122
This commit is contained in:
@@ -129,7 +129,8 @@ class ImportPath(pr.Base):
|
|||||||
if on_import_stmt and isinstance(scope, pr.Module) \
|
if on_import_stmt and isinstance(scope, pr.Module) \
|
||||||
and scope.path.endswith('__init__.py'):
|
and scope.path.endswith('__init__.py'):
|
||||||
pkg_path = os.path.dirname(scope.path)
|
pkg_path = os.path.dirname(scope.path)
|
||||||
names += self.get_module_names([pkg_path])
|
paths = self._namespace_packages(pkg_path, self.import_path)
|
||||||
|
names += self.get_module_names([pkg_path] + paths)
|
||||||
for s, scope_names in evaluate.get_names_of_scope(scope,
|
for s, scope_names in evaluate.get_names_of_scope(scope,
|
||||||
include_builtin=False):
|
include_builtin=False):
|
||||||
for n in scope_names:
|
for n in scope_names:
|
||||||
|
|||||||
@@ -1,17 +1,20 @@
|
|||||||
import jedi
|
import jedi
|
||||||
import sys
|
import sys
|
||||||
|
from os.path import dirname, join
|
||||||
|
|
||||||
def test_namespace_package():
|
def test_namespace_package():
|
||||||
sys.path.insert(0, 'namespace_package/ns1')
|
sys.path.insert(0, join(dirname(__file__), 'namespace_package/ns1'))
|
||||||
sys.path.insert(1, 'namespace_package/ns2')
|
sys.path.insert(1, join(dirname(__file__), 'namespace_package/ns2'))
|
||||||
try:
|
try:
|
||||||
assert jedi.Script('from pkg import ns1_file').goto_definitions()
|
assert jedi.Script('from pkg import ns1_file').goto_definitions()
|
||||||
assert jedi.Script('from pkg import ns2_file').goto_definitions()
|
assert jedi.Script('from pkg import ns2_file').goto_definitions()
|
||||||
assert not jedi.Script('from pkg import ns3_file').goto_definitions()
|
assert not jedi.Script('from pkg import ns3_file').goto_definitions()
|
||||||
|
|
||||||
completions = jedi.Script('from pkg import ').completions()
|
completions = jedi.Script('from pkg import ').completions()
|
||||||
names = [c.name for c in completions]
|
names = [str(c.name) for c in completions] # str because of unicode
|
||||||
assert names == ['foo', 'ns1_file', 'ns1_folder', 'ns2_folder', 'ns2_file']
|
compare = ['foo', 'ns1_file', 'ns1_folder', 'ns2_folder', 'ns2_file']
|
||||||
|
# must at least contain these items, other items are not important
|
||||||
|
assert not (set(compare) - set(names))
|
||||||
finally:
|
finally:
|
||||||
sys.path.pop(0)
|
sys.path.pop(0)
|
||||||
sys.path.pop(0)
|
sys.path.pop(0)
|
||||||
|
|||||||
Reference in New Issue
Block a user