forked from VimPlug/jedi
Fix on_import tests.
This commit is contained in:
@@ -157,6 +157,7 @@ class Script(object):
|
|||||||
last word part. To ignore certain strange patterns with dots, just
|
last word part. To ignore certain strange patterns with dots, just
|
||||||
use regex.
|
use regex.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if re.match('\d+\.\.$|\.{4}$', path):
|
if re.match('\d+\.\.$|\.{4}$', path):
|
||||||
return True # check Ellipsis and float literal `1.`
|
return True # check Ellipsis and float literal `1.`
|
||||||
|
|
||||||
@@ -164,8 +165,9 @@ class Script(object):
|
|||||||
|
|
||||||
debug.speed('completions start')
|
debug.speed('completions start')
|
||||||
path = self._user_context.get_path_until_cursor()
|
path = self._user_context.get_path_until_cursor()
|
||||||
if not completion_possible(path):
|
# TODO still needed with the new parser?
|
||||||
return []
|
#if not completion_possible(path):
|
||||||
|
# return []
|
||||||
path, dot, like = helpers.completion_parts(path)
|
path, dot, like = helpers.completion_parts(path)
|
||||||
|
|
||||||
user_stmt = self._parser.user_stmt_with_whitespace()
|
user_stmt = self._parser.user_stmt_with_whitespace()
|
||||||
|
|||||||
@@ -36,24 +36,30 @@ def get_on_import_stmt(evaluator, user_context, user_stmt, is_like_search=False)
|
|||||||
|
|
||||||
def check_error_statements(evaluator, module, pos):
|
def check_error_statements(evaluator, module, pos):
|
||||||
for error_statement in module.error_statement_stacks:
|
for error_statement in module.error_statement_stacks:
|
||||||
if error_statement.first_type in ('import_from' or 'import_name') \
|
if error_statement.first_type in ('import_from', 'import_name') \
|
||||||
and error_statement.first_pos < pos <= error_statement.next_start_pos:
|
and error_statement.first_pos < pos <= error_statement.next_start_pos:
|
||||||
return importer_from_error_statement(evaluator, module, error_statement, pos)
|
return importer_from_error_statement(evaluator, module, error_statement, pos)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def importer_from_error_statement(evaluator, module, error_statement, pos):
|
def importer_from_error_statement(evaluator, module, error_statement, pos):
|
||||||
|
def check_dotted(children):
|
||||||
|
for name in children[::2]:
|
||||||
|
if name.end_pos < pos:
|
||||||
|
yield name
|
||||||
|
|
||||||
names = []
|
names = []
|
||||||
level = 0
|
level = 0
|
||||||
for typ, nodes in error_statement.stack:
|
for typ, nodes in error_statement.stack:
|
||||||
if typ == 'dotted_name':
|
if typ == 'dotted_name':
|
||||||
names += nodes[::2]
|
names += check_dotted(nodes)
|
||||||
elif typ == 'import_from':
|
elif typ == 'import_from':
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
if isinstance(node, pt.Node) and node.type == 'dotted_name':
|
if isinstance(node, pt.Node) and node.type == 'dotted_name':
|
||||||
names += node.children[::2]
|
names += check_dotted(node.children[::2])
|
||||||
print(typ, nodes)
|
elif node in ('.', '...'):
|
||||||
|
level += len(node.value)
|
||||||
print('x', names)
|
elif isinstance(node, pt.Name) and node.end_pos < pos:
|
||||||
|
names.append(node)
|
||||||
|
|
||||||
return imports.get_importer(evaluator, names, module, level)
|
return imports.get_importer(evaluator, names, module, level)
|
||||||
|
|||||||
@@ -54,7 +54,8 @@ class ImportWrapper(pr.Base):
|
|||||||
module = self._import.get_parent_until()
|
module = self._import.get_parent_until()
|
||||||
importer = get_importer(self._evaluator, tuple(import_path),
|
importer = get_importer(self._evaluator, tuple(import_path),
|
||||||
module, self._import.level)
|
module, self._import.level)
|
||||||
return importer.completion_names(self._evaluator)
|
only_modules = isinstance(self._import, pr.ImportName)
|
||||||
|
return importer.completion_names(self._evaluator, only_modules)
|
||||||
|
|
||||||
@memoize_default()
|
@memoize_default()
|
||||||
def follow(self, is_goto=False):
|
def follow(self, is_goto=False):
|
||||||
@@ -91,7 +92,7 @@ class ImportWrapper(pr.Base):
|
|||||||
|
|
||||||
# follow the rest of the import (not FS -> classes, functions)
|
# follow the rest of the import (not FS -> classes, functions)
|
||||||
if len(rest) > 1 or rest and self.is_like_search:
|
if len(rest) > 1 or rest and self.is_like_search:
|
||||||
if ('os', 'path') == importer.str_import_path()[:2] \
|
if ('os', 'path') == importer.str_import_path[:2] \
|
||||||
and self._import.level == 0:
|
and self._import.level == 0:
|
||||||
# This is a huge exception, we follow a nested import
|
# This is a huge exception, we follow a nested import
|
||||||
# ``os.path``, because it's a very important one in Python
|
# ``os.path``, because it's a very important one in Python
|
||||||
@@ -443,7 +444,10 @@ class _Importer(object):
|
|||||||
return in_path + sys_path_with_modifications(self._evaluator, self.module)
|
return in_path + sys_path_with_modifications(self._evaluator, self.module)
|
||||||
|
|
||||||
def follow(self, evaluator):
|
def follow(self, evaluator):
|
||||||
|
try:
|
||||||
scope, rest = self.follow_file_system()
|
scope, rest = self.follow_file_system()
|
||||||
|
except ModuleNotFound:
|
||||||
|
return []
|
||||||
if rest:
|
if rest:
|
||||||
# follow the rest of the import (not FS -> classes, functions)
|
# follow the rest of the import (not FS -> classes, functions)
|
||||||
return []
|
return []
|
||||||
@@ -653,7 +657,6 @@ class _Importer(object):
|
|||||||
if only_modules:
|
if only_modules:
|
||||||
# In the case of an import like `from x.` we don't need to
|
# In the case of an import like `from x.` we don't need to
|
||||||
# add all the variables.
|
# add all the variables.
|
||||||
print(self.import_path)
|
|
||||||
if ('os',) == self.str_import_path and not self.level:
|
if ('os',) == self.str_import_path and not self.level:
|
||||||
# os.path is a hardcoded exception, because it's a
|
# os.path is a hardcoded exception, because it's a
|
||||||
# ``sys.modules`` modification.
|
# ``sys.modules`` modification.
|
||||||
|
|||||||
@@ -71,6 +71,13 @@ from import_tree.p import pkg
|
|||||||
from .import_tree import
|
from .import_tree import
|
||||||
#? 10 ['run']
|
#? 10 ['run']
|
||||||
from ..run import
|
from ..run import
|
||||||
|
#? ['run']
|
||||||
|
from ..run
|
||||||
|
#? 10 ['run']
|
||||||
|
from ..run.
|
||||||
|
#? []
|
||||||
|
from ..run.
|
||||||
|
|
||||||
#? ['run']
|
#? ['run']
|
||||||
from .. import run
|
from .. import run
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user