mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 14:34:31 +08:00
@@ -151,19 +151,13 @@ class Completion:
|
|||||||
# Also true for defining names as a class or function.
|
# Also true for defining names as a class or function.
|
||||||
return list(self._get_class_context_completions(is_function=True))
|
return list(self._get_class_context_completions(is_function=True))
|
||||||
elif "import_stmt" in symbol_names:
|
elif "import_stmt" in symbol_names:
|
||||||
level = 0
|
level, names = self._parse_dotted_names(nodes, "import_from" in symbol_names)
|
||||||
only_modules = True
|
|
||||||
level, names = self._parse_dotted_names(nodes)
|
|
||||||
if "import_from" in symbol_names:
|
|
||||||
if 'import' in nodes:
|
|
||||||
only_modules = False
|
|
||||||
else:
|
|
||||||
assert "import_name" in symbol_names
|
|
||||||
|
|
||||||
|
only_modules = not ("import_from" in symbol_names and 'import' in nodes)
|
||||||
completion_names += self._get_importer_names(
|
completion_names += self._get_importer_names(
|
||||||
names,
|
names,
|
||||||
level,
|
level,
|
||||||
only_modules
|
only_modules=only_modules,
|
||||||
)
|
)
|
||||||
elif symbol_names[-1] in ('trailer', 'dotted_name') and nodes[-1] == '.':
|
elif symbol_names[-1] in ('trailer', 'dotted_name') and nodes[-1] == '.':
|
||||||
dot = self._module_node.get_leaf_for_position(self._position)
|
dot = self._module_node.get_leaf_for_position(self._position)
|
||||||
@@ -211,7 +205,7 @@ class Completion:
|
|||||||
completion_names += filter.values()
|
completion_names += filter.values()
|
||||||
return completion_names
|
return completion_names
|
||||||
|
|
||||||
def _parse_dotted_names(self, nodes):
|
def _parse_dotted_names(self, nodes, is_import_from):
|
||||||
level = 0
|
level = 0
|
||||||
names = []
|
names = []
|
||||||
for node in nodes[1:]:
|
for node in nodes[1:]:
|
||||||
@@ -222,7 +216,12 @@ class Completion:
|
|||||||
names += node.children[::2]
|
names += node.children[::2]
|
||||||
elif node.type == 'name':
|
elif node.type == 'name':
|
||||||
names.append(node)
|
names.append(node)
|
||||||
|
elif node == ',':
|
||||||
|
if not is_import_from:
|
||||||
|
names = []
|
||||||
else:
|
else:
|
||||||
|
# Here if the keyword `import` comes along it stops checking
|
||||||
|
# for names.
|
||||||
break
|
break
|
||||||
return level, names
|
return level, names
|
||||||
|
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ def test_goto_following_on_imports():
|
|||||||
assert (g[0].line, g[0].column) != (0, 0)
|
assert (g[0].line, g[0].column) != (0, 0)
|
||||||
|
|
||||||
|
|
||||||
def test_after_from():
|
def test_os_after_from():
|
||||||
def check(source, result, column=None):
|
def check(source, result, column=None):
|
||||||
completions = Script(source, column=column).completions()
|
completions = Script(source, column=column).completions()
|
||||||
assert [c.name for c in completions] == result
|
assert [c.name for c in completions] == result
|
||||||
@@ -211,6 +211,24 @@ def test_after_from():
|
|||||||
check('from os \\\n', ['import'])
|
check('from os \\\n', ['import'])
|
||||||
|
|
||||||
|
|
||||||
|
def test_os_issues():
|
||||||
|
def import_names(*args, **kwargs):
|
||||||
|
return [d.name for d in jedi.Script(*args, **kwargs).completions()]
|
||||||
|
|
||||||
|
# Github issue #759
|
||||||
|
s = 'import os, s'
|
||||||
|
assert 'sys' in import_names(s)
|
||||||
|
assert 'path' not in import_names(s, column=len(s) - 1)
|
||||||
|
assert 'os' in import_names(s, column=len(s) - 3)
|
||||||
|
|
||||||
|
# Some more checks
|
||||||
|
s = 'from os import path, e'
|
||||||
|
assert 'environ' in import_names(s)
|
||||||
|
assert 'json' not in import_names(s, column=len(s) - 1)
|
||||||
|
assert 'environ' in import_names(s, column=len(s) - 1)
|
||||||
|
assert 'path' in import_names(s, column=len(s) - 3)
|
||||||
|
|
||||||
|
|
||||||
def test_path_issues():
|
def test_path_issues():
|
||||||
"""
|
"""
|
||||||
See pull request #684 for details.
|
See pull request #684 for details.
|
||||||
|
|||||||
Reference in New Issue
Block a user