forked from VimPlug/jedi
Fix quote completions for os.path.join path completions
This commit is contained in:
@@ -4,6 +4,7 @@ from jedi._compatibility import FileNotFoundError, force_unicode
|
||||
from jedi.evaluate.names import AbstractArbitraryName
|
||||
from jedi.api import classes
|
||||
from jedi.evaluate.helpers import get_str_or_none
|
||||
from jedi.parser_utils import get_string_quote
|
||||
|
||||
|
||||
def file_name_completions(evaluator, module_context, start_leaf, string, like_name):
|
||||
@@ -29,7 +30,13 @@ def file_name_completions(evaluator, module_context, start_leaf, string, like_na
|
||||
for name in listed:
|
||||
if name.startswith(must_start_with):
|
||||
path_for_name = os.path.join(base_path, name)
|
||||
if os.path.isdir(path_for_name) and not is_in_os_path_join:
|
||||
if is_in_os_path_join:
|
||||
if start_leaf.type == 'string':
|
||||
name += get_string_quote(start_leaf)
|
||||
else:
|
||||
assert start_leaf.type == 'error_leaf'
|
||||
name += start_leaf.value
|
||||
elif os.path.isdir(path_for_name):
|
||||
name += os.path.sep
|
||||
|
||||
yield classes.Completion(
|
||||
@@ -103,7 +110,6 @@ def _maybe_add_os_path_join(module_context, start_leaf, string):
|
||||
arglist = start_leaf.parent
|
||||
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:
|
||||
|
||||
@@ -291,3 +291,7 @@ def cut_value_at_position(leaf, position):
|
||||
column -= leaf.column
|
||||
lines[-1] = lines[-1][:column]
|
||||
return ''.join(lines)
|
||||
|
||||
|
||||
def get_string_quote(leaf):
|
||||
return re.match('\w*("""|\'{3}|"|\')', leaf.value).group(1)
|
||||
|
||||
@@ -210,20 +210,20 @@ os_path = 'from os.path import *\n'
|
||||
(f2, os_path + 'dirname(__file__) + "%stest_ca' % s, None, ['che.py']),
|
||||
(f2, os_path + 'dirname(abspath(__file__)) + sep + "test_ca', None, ['che.py']),
|
||||
(f2, os_path + 'join(dirname(__file__), "completion") + sep + "basi', None, ['c.py']),
|
||||
(f2, os_path + 'join(dirname(__file__), "completion", "basi', None, ['c.py']),
|
||||
(f2, os_path + 'join(dirname(__file__), "completion", "basi)', 43, ['c.py']),
|
||||
(f2, os_path + 'join(dirname(__file__), "completion", "basi")', 43, ['c.py']),
|
||||
(f2, os_path + 'join(dirname(__file__), "completion", "basi)', 35, ['']),
|
||||
(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', None, ['c.py"']),
|
||||
(f2, os_path + 'join(dirname(__file__), "completion", "basi)', 43, ['c.py"']),
|
||||
(f2, os_path + 'join(dirname(__file__), "completion", "basi")', 43, ['c.py"']),
|
||||
(f2, os_path + 'join(dirname(__file__), "completion", "basi)', 35, ['"']),
|
||||
(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 will not get evaluated and the result is
|
||||
# that directories and in a slash. This is unfortunate, but doesn't
|
||||
# really matter.
|
||||
(f2, os_path + 'join("tes', 9, ['t']),
|
||||
(f2, os_path + 'join("tes)', 9, ['t']),
|
||||
(f2, os_path + 'join("tes"', 9, ['t']),
|
||||
(f2, os_path + 'join("tes")', 9, ['t']),
|
||||
(f2, os_path + 'join("tes', 9, ['t"']),
|
||||
(f2, os_path + 'join(\'tes)', 9, ["t'"]),
|
||||
(f2, os_path + 'join(r"tes"', 10, ['t"']),
|
||||
(f2, os_path + 'join("""tes""")', 11, ['t"""']),
|
||||
]
|
||||
)
|
||||
def test_file_path_completions(Script, file, code, column, expected):
|
||||
|
||||
Reference in New Issue
Block a user