From 8dac83a9a05fef5972f64631e16383e9e7c06b1b Mon Sep 17 00:00:00 2001 From: Daniel Shimon Date: Thu, 29 Jul 2021 10:02:25 +0300 Subject: [PATCH] Fix jedi path completion (#4400) * xontrib: jedi: Don't complete paths with '~' * tests: xontrib: jedi: Update tests * news: Add fix-jedi-path-completion --- news/fix-jedi-path-completion.rst | 23 +++++++++++++++++++++++ tests/xontribs/test_jedi.py | 1 + xontrib/jedi.py | 4 ++-- 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 news/fix-jedi-path-completion.rst diff --git a/news/fix-jedi-path-completion.rst b/news/fix-jedi-path-completion.rst new file mode 100644 index 000000000..8757b89dd --- /dev/null +++ b/news/fix-jedi-path-completion.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* ``Jedi`` completer doesn't complete paths with ``~``. + +**Security:** + +* diff --git a/tests/xontribs/test_jedi.py b/tests/xontribs/test_jedi.py index 0681e7fb8..166ef2005 100644 --- a/tests/xontribs/test_jedi.py +++ b/tests/xontribs/test_jedi.py @@ -253,6 +253,7 @@ def test_special_tokens(jedi_xontrib): @skip_if_on_windows def test_no_command_path_completion(jedi_xontrib, completion_context_parse): assert jedi_xontrib.complete_jedi(completion_context_parse("./", 2)) is None + assert jedi_xontrib.complete_jedi(completion_context_parse("~/", 2)) is None assert jedi_xontrib.complete_jedi(completion_context_parse("./e", 3)) is None assert jedi_xontrib.complete_jedi(completion_context_parse("/usr/bin/", 9)) is None assert ( diff --git a/xontrib/jedi.py b/xontrib/jedi.py index 1d860b821..49d991382 100644 --- a/xontrib/jedi.py +++ b/xontrib/jedi.py @@ -65,8 +65,8 @@ def complete_jedi(context: CompletionContext): # if we're completing a possible command and the prefix contains a valid path, don't complete. if context.command: - path_parts = os.path.split(context.command.prefix) - if len(path_parts) > 1 and os.path.isdir(os.path.join(*path_parts[:-1])): + path_dir = os.path.dirname(context.command.prefix) + if path_dir and os.path.isdir(os.path.expanduser(path_dir)): return None filter_func = get_filter_function()