mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
Path completion in python code (#4457)
* completions: path: Fix completing a single-arg python code segment * tests: completions: path: Test completing python code * news: Add path-completion-in-python-code
This commit is contained in:
parent
89f54ee10a
commit
6df8a24fc9
3 changed files with 39 additions and 1 deletions
23
news/path-completion-in-python-code.rst
Normal file
23
news/path-completion-in-python-code.rst
Normal file
|
@ -0,0 +1,23 @@
|
|||
**Added:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Changed:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Deprecated:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Removed:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Fixed:**
|
||||
|
||||
* Completing a single-arg python code segment (e.g. ``@(/etc/hos<TAB>)``).
|
||||
|
||||
**Security:**
|
||||
|
||||
* <news item>
|
|
@ -71,3 +71,18 @@ def test_path_from_partial_string(prefix):
|
|||
else:
|
||||
expected = (f"{quote}{string}{quote}", string, f"{prefix}{quote}", quote)
|
||||
assert out == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize("num_args", (0, 1, 2, 3))
|
||||
def test_path_in_python_code(num_args, completion_context_parse):
|
||||
with tempfile.NamedTemporaryFile(prefix="long_name") as tmp:
|
||||
args = []
|
||||
if num_args:
|
||||
args = ["blah"] * 3 + [tmp.name[:-2]]
|
||||
args = args[-num_args:]
|
||||
|
||||
inner_line = " ".join(map(repr, args))
|
||||
exp = xcp.complete_path(completion_context_parse(inner_line, len(inner_line)))
|
||||
line = "@(" + inner_line
|
||||
out = xcp.complete_path(completion_context_parse(line, len(line)))
|
||||
assert out == exp
|
||||
|
|
|
@ -362,7 +362,7 @@ def complete_path(context):
|
|||
elif context.python:
|
||||
line = context.python.prefix
|
||||
# simple prefix _complete_path_raw will handle gracefully:
|
||||
prefix = line.rsplit(" ", 1)[1]
|
||||
prefix = line.rsplit(" ", 1)[-1]
|
||||
return _complete_path_raw(prefix, line, len(line) - len(prefix), len(line), {})
|
||||
return set(), 0
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue