forked from VimPlug/jedi
Fix string additions when used in certain ways
This commit is contained in:
@@ -7,27 +7,32 @@ from jedi.evaluate.helpers import get_str_or_none
|
|||||||
|
|
||||||
|
|
||||||
def file_name_completions(evaluator, module_context, start_leaf, string, like_name):
|
def file_name_completions(evaluator, module_context, start_leaf, string, like_name):
|
||||||
|
# First we want to find out what can actually be changed as a name.
|
||||||
base_name = os.path.basename(string)
|
base_name = os.path.basename(string)
|
||||||
like_name = base_name + like_name
|
like_name_length = len(base_name + like_name)
|
||||||
string = os.path.dirname(string)
|
|
||||||
|
|
||||||
string = _get_string_additions(module_context, start_leaf) + string
|
string = _get_string_additions(module_context, start_leaf) + string
|
||||||
|
# Here we use basename again, because if strings are added like
|
||||||
|
# `'foo' + 'bar`, it should complete to `foobar/`.
|
||||||
|
must_start_with = os.path.basename(string) + like_name
|
||||||
|
string = os.path.dirname(string)
|
||||||
|
|
||||||
base_path = os.path.join(evaluator.project._path, string)
|
base_path = os.path.join(evaluator.project._path, string)
|
||||||
try:
|
try:
|
||||||
listed = os.listdir(base_path)
|
listed = os.listdir(base_path)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
return
|
return
|
||||||
for name in listed:
|
for name in listed:
|
||||||
if name.startswith(like_name):
|
if name.startswith(must_start_with):
|
||||||
path_for_name = os.path.join(base_path, name)
|
path_for_name = os.path.join(base_path, name)
|
||||||
if os.path.isdir(path_for_name):
|
if os.path.isdir(path_for_name):
|
||||||
name += os.path.sep
|
name += os.path.sep
|
||||||
|
|
||||||
yield classes.Completion(
|
yield classes.Completion(
|
||||||
evaluator,
|
evaluator,
|
||||||
FileName(evaluator, name),
|
FileName(evaluator, name[len(must_start_with) - like_name_length:]),
|
||||||
stack=None,
|
stack=None,
|
||||||
like_name_length=len(like_name),
|
like_name_length=like_name_length
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -55,8 +60,6 @@ def _get_string_additions(module_context, start_leaf):
|
|||||||
if child_node != '+':
|
if child_node != '+':
|
||||||
break
|
break
|
||||||
was_addition = True
|
was_addition = True
|
||||||
child_node
|
|
||||||
module_context
|
|
||||||
return string
|
return string
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -190,6 +190,12 @@ def test_keyword_completion(Script, code, has_keywords):
|
|||||||
('example.py', '"test" + "%stest_cac' % s, None, ['he.py']),
|
('example.py', '"test" + "%stest_cac' % s, None, ['he.py']),
|
||||||
('example.py', '"test" + "%s" + "test_cac' % s, None, ['he.py']),
|
('example.py', '"test" + "%s" + "test_cac' % s, None, ['he.py']),
|
||||||
('example.py', 'x = 1 + "test', None, [s]),
|
('example.py', 'x = 1 + "test', None, [s]),
|
||||||
|
('example.py', 'x = f("te" + "st)', 16, [s]),
|
||||||
|
('example.py', 'x = f("te" + "st', 16, [s]),
|
||||||
|
('example.py', 'x = f("te" + "st"', 16, [s]),
|
||||||
|
('example.py', 'x = f("te" + "st")', 16, [s]),
|
||||||
|
('example.py', 'x = f("t" + "est")', 16, [s]),
|
||||||
|
('example.py', '"test" + "', None, [s]),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
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