mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 14:34:31 +08:00
Fix first param argument of os.path.join file completions
This commit is contained in:
@@ -93,34 +93,51 @@ def _maybe_add_os_path_join(module_context, start_leaf, string):
|
|||||||
return string, False
|
return string, False
|
||||||
return _add_strings(context, nodes, add_slash=True), True
|
return _add_strings(context, nodes, add_slash=True), True
|
||||||
|
|
||||||
|
def check_trailer(trailer, arglist_nodes):
|
||||||
|
atom = trailer.get_previous_sibling()
|
||||||
|
if atom.type != 'trailer':
|
||||||
|
return check_for_power(atom, arglist_nodes)
|
||||||
|
return string, False
|
||||||
|
|
||||||
|
# Maybe an arglist or some weird error case. Therefore checked below.
|
||||||
arglist = start_leaf.parent
|
arglist = start_leaf.parent
|
||||||
if start_leaf.type == 'error_leaf':
|
|
||||||
index = arglist.children.index(start_leaf)
|
index = arglist.children.index(start_leaf)
|
||||||
|
arglist_nodes = arglist.children[:index]
|
||||||
|
print(arglist, arglist_nodes)
|
||||||
|
if start_leaf.type == 'error_leaf':
|
||||||
|
# Unfinished string literal, like `join('`
|
||||||
if index > 0:
|
if index > 0:
|
||||||
error_node = arglist.children[index - 1]
|
error_node = arglist_nodes[-1]
|
||||||
if error_node.type == 'error_node' and len(error_node.children) >= 3:
|
if error_node.type == 'error_node' and len(error_node.children) >= 2:
|
||||||
atom = error_node.children[-3]
|
index = -2
|
||||||
arglist = error_node.children[-1]
|
if error_node.children[-1].type == 'arglist':
|
||||||
if atom.type in ('atom_expr', 'power', 'name') and arglist.type == 'arglist':
|
arglist_nodes = error_node.children[-1].children
|
||||||
return check_for_power(atom, arglist.children[::2])
|
index -= 1
|
||||||
|
else:
|
||||||
|
arglist_nodes = []
|
||||||
|
|
||||||
|
if error_node.children[index + 1] == '(':
|
||||||
|
atom = error_node.children[index]
|
||||||
|
if atom.type in ('atom_expr', 'power', 'name'):
|
||||||
|
return check_for_power(atom, arglist_nodes[::2])
|
||||||
elif arglist.type == 'arglist':
|
elif arglist.type == 'arglist':
|
||||||
trailer = arglist.parent
|
trailer = arglist.parent
|
||||||
if trailer.type == 'error_node':
|
if trailer.type == 'error_node':
|
||||||
index = trailer.children.index(arglist)
|
trailer_index = trailer.children.index(arglist)
|
||||||
assert index >= 2
|
assert trailer_index >= 2
|
||||||
assert trailer.children[index - 1] == '('
|
assert trailer.children[trailer_index - 1] == '('
|
||||||
name = trailer.children[index - 2]
|
name = trailer.children[trailer_index - 2]
|
||||||
if name.type in ('atom_expr', 'power', 'name'):
|
if name.type in ('atom_expr', 'power', 'name'):
|
||||||
nodes = arglist.children[:arglist.children.index(start_leaf):2]
|
return check_for_power(name, arglist_nodes[::2])
|
||||||
return check_for_power(name, nodes)
|
|
||||||
|
|
||||||
elif False:
|
|
||||||
for node in reversed(trailer.children[:trailer.children.index(arglist)]):
|
|
||||||
print(node)
|
|
||||||
elif trailer.type == 'trailer':
|
elif trailer.type == 'trailer':
|
||||||
atom = trailer.get_previous_sibling()
|
return check_trailer(trailer, arglist_nodes[::2])
|
||||||
if atom.type != 'trailer':
|
elif arglist.type == 'trailer':
|
||||||
nodes = arglist.children[:arglist.children.index(start_leaf):2]
|
return check_trailer(arglist, [])
|
||||||
return check_for_power(atom, nodes)
|
elif arglist.type == 'error_node':
|
||||||
|
# Stuff like `join(""`
|
||||||
|
if len(arglist_nodes) >= 2 and arglist_nodes[-1] == '(':
|
||||||
|
name = arglist_nodes[-2]
|
||||||
|
if name.type in ('atom_expr', 'power', 'name'):
|
||||||
|
return check_for_power(name, [])
|
||||||
|
|
||||||
return string, False
|
return string, False
|
||||||
|
|||||||
@@ -217,11 +217,13 @@ os_path = 'from os.path import *\n'
|
|||||||
(f2, os_path + 'join(dirname(__file__), "completion", "basi)', 33, ['on']),
|
(f2, os_path + 'join(dirname(__file__), "completion", "basi)', 33, ['on']),
|
||||||
(f2, os_path + 'join(dirname(__file__), "completion", "basi")', 33, ['on']),
|
(f2, os_path + 'join(dirname(__file__), "completion", "basi")', 33, ['on']),
|
||||||
|
|
||||||
# join with one argument
|
# join with one argument. join will not get evaluated and the result is
|
||||||
#(f2, os_path + 'join("tes', 10, ['t']),
|
# that directories and in a slash. This is unfortunate, but doesn't
|
||||||
#(f2, os_path + 'join("tes)', 10, ['t']),
|
# really matter.
|
||||||
#(f2, os_path + 'join("tes"', 10, ['t']),
|
(f2, os_path + 'join("tes', 9, ['t']),
|
||||||
#(f2, os_path + 'join("tes")', 10, ['t']),
|
(f2, os_path + 'join("tes)', 9, ['t']),
|
||||||
|
(f2, os_path + 'join("tes"', 9, ['t']),
|
||||||
|
(f2, os_path + 'join("tes")', 9, ['t']),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
def test_file_path_completions(Script, file, code, column, expected):
|
def test_file_path_completions(Script, file, code, column, expected):
|
||||||
|
|||||||
Reference in New Issue
Block a user