Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Duplicate results in _python - (Re: [MINOR BUG] Duplicate results in tab-menu)

On Thu, Jun 23, 2022 at 7:42 AM Eric Cook <llua@xxxxxxx> wrote:
> On 6/23/22 05:54, Morten Nissov wrote:
> > In some cases, when I tab to open the menu everything is duplicated, see below for example
> Just the group-name and list-dirs-first styles being empty string and true are needed to cause the problem.

There are some interacting things going on here.

First, _python uses
#compdef -P python[0-9.]#

This means to first try completions for commands matching the pattern,
and then try completions for any other context that matches, which in
this case happens to be -default-.

This is handled by _dispatch, which (after discovering that "python3"
matches the pattern), sets _compskip=default to indicate that it
should not try the -default- context after all, and then calls

Unfortunately _python calls _normal which sets _compskip='' again.
_normal is expecting _compskip to have come from _main_complete, but
instead it clobbers the local in _dispatch, so when control eventually
returns there, _dispatch goes ahead with completing for -default-.

This would be invisible except that list-dirs-first causes the results
of these two different contexts to be placed in separate completion
groups, and then group-name prevents them from being mutually

The trouble here is that the completion invoked by _dispatch is
explicitly allowed to change _compskip to control the behavior of
_dispatch.  It just happens that any completion that relies on calling
_normal may do so incorrectly.

Now, as it happens there's an undocumented option of _normal to
prevent it from doing this, but using that option breaks the python3
completion because the -default- context is needed for the "script
argument".  So the fix appears to be to make _compskip local to
_python, which seems a bit icky because it doesn't help with any other
completions that may have it wrong.  Better suggestions?

diff --git a/Completion/Unix/Command/_python b/Completion/Unix/Command/_python
index e5bac18bb..2711b8fd3 100644
--- a/Completion/Unix/Command/_python
+++ b/Completion/Unix/Command/_python
@@ -3,7 +3,7 @@
 # Python 2.7
 # Python 3.9

-local curcontext="$curcontext" state state_descr line
+local curcontext="$curcontext" state state_descr line _compskip="$_compskip"
 typeset -A opt_args
 local -a args

Messages sorted by: Reverse Date, Date, Thread, Author