mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
Improve import completions (#4265)
* completers: import: Move `import` completer before `bash` completer If this completer returns a result, it's definitely an import statement * completers: import: Complete `import` keyword in `from ... import` statements * news: Add improve-import-completions
This commit is contained in:
parent
59819cf28f
commit
35f1ba1819
4 changed files with 28 additions and 2 deletions
23
news/improve-import-completions.rst
Normal file
23
news/improve-import-completions.rst
Normal file
|
@ -0,0 +1,23 @@
|
|||
**Added:**
|
||||
|
||||
* Complete ``import`` keyword in ``from ... import`` statements.
|
||||
|
||||
**Changed:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Deprecated:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Removed:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Fixed:**
|
||||
|
||||
* ``import`` completions always work.
|
||||
|
||||
**Security:**
|
||||
|
||||
* <news item>
|
|
@ -73,7 +73,7 @@ def test_complete_python_ctx():
|
|||
class A:
|
||||
def wow():
|
||||
pass
|
||||
|
||||
|
||||
a = A()
|
||||
|
||||
res = complete_python(CompletionContext(python=PythonContext("a.w", 2, ctx=locals())))
|
||||
|
@ -86,6 +86,7 @@ def test_complete_python_ctx():
|
|||
(CommandContext(args=(CommandArg("import"),), arg_index=1, prefix="pathli"), {"pathlib"}),
|
||||
(CommandContext(args=(CommandArg("from"),), arg_index=1, prefix="pathli"), {"pathlib "}),
|
||||
(CommandContext(args=(CommandArg("import"),), arg_index=1, prefix="os.pa"), {"os.path"}),
|
||||
(CommandContext(args=(CommandArg("from"), CommandArg("x"),), arg_index=2), {"import"}),
|
||||
(CommandContext(args=(
|
||||
CommandArg("import"), CommandArg("os,"),
|
||||
), arg_index=2, prefix="pathli"), {"pathlib"}),
|
||||
|
|
|
@ -33,9 +33,9 @@ def default_completers():
|
|||
("rmdir", complete_rmdir),
|
||||
("xonfig", complete_xonfig),
|
||||
("xontrib", complete_xontrib),
|
||||
("import", complete_import),
|
||||
("bash", complete_from_bash),
|
||||
("man", complete_from_man),
|
||||
("import", complete_import),
|
||||
("python", complete_python),
|
||||
("path", complete_path),
|
||||
(
|
||||
|
|
|
@ -308,6 +308,8 @@ def complete_import(context: CompletionContext):
|
|||
if arg_index >= 1 and args[0].value == "import":
|
||||
# completing module to import
|
||||
return complete_module(prefix)
|
||||
if arg_index == 2 and args[0].value == "from":
|
||||
return {RichCompletion("import", append_space=True)}
|
||||
if arg_index > 2 and args[0].value == "from" and args[2].value == "import":
|
||||
# complete thing inside a module
|
||||
try:
|
||||
|
|
Loading…
Add table
Reference in a new issue