From 9a3f41e63b694bc95ee11b6ed88b71c2f03e2ed2 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Tue, 13 Aug 2019 07:57:00 -0700 Subject: [PATCH 1/2] Complete path after ~. Note this is mostly to discuss as if I understood one of your message on Twitter, this was not possible without fuzzy completion. I tried with just this patch and that works great. Note that unlike IPython that right now does : ~/ -> /Full/Path/to/user/home But with this patch this just complete things correctly without expanding the tab. And I think not expanding the tab is actually better. Anyway, open that to better understand the why you were waiting for fuzzy completion. --- jedi/api/file_name.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jedi/api/file_name.py b/jedi/api/file_name.py index 542b5957..6fbecace 100644 --- a/jedi/api/file_name.py +++ b/jedi/api/file_name.py @@ -37,6 +37,8 @@ def file_name_completions(evaluator, module_context, start_leaf, string, like_name_length = len(os.path.basename(string) + like_name) addition = _get_string_additions(module_context, start_leaf) + if string.startswith('~'): + string = os.path.expanduser(string) if addition is None: return string = addition + string From 5329f9509639140ce0ad2c562ea10cd70327754a Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Fri, 23 Aug 2019 18:26:11 +0200 Subject: [PATCH 2/2] Attempt at a test of completion of filepath after ~. I'm not quite sure how this will behave on windows, and we can't really create a tempdir (as we don't want to mess with path on home. One possibility would be to mock/monkeypatch scandir, listdir and os.path.expanduser or set $HOME in env; but I'm quite unsure we want to go that route. --- test/test_api/test_completion.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/test_api/test_completion.py b/test/test_api/test_completion.py index 178daee9..fefef549 100644 --- a/test/test_api/test_completion.py +++ b/test/test_api/test_completion.py @@ -1,4 +1,5 @@ -from os.path import join, sep as s +from os.path import join, sep as s, expanduser +import os import sys from textwrap import dedent @@ -83,6 +84,14 @@ def test_loading_unicode_files_with_bad_global_charset(Script, monkeypatch, tmpd line=2, column=4, path=filename2) s.completions() +def test_complete_expanduser(Script): + possibilities = os.listdir(expanduser('~')) + non_dots = [p for p in possibilities if not p.startswith('.') and len(p) > 1] + item = non_dots[0] + line = "'~%s%s'" % (os.sep, item) + s = Script(line, line=1, column=len(line)-1) + assert item in [c.name for c in s.completions()] + def test_fake_subnodes(Script): """