Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve completion suggestions #350

Merged
merged 4 commits into from
Jul 2, 2018

Conversation

ericfreese
Copy link
Member

Just insert the first completion directly into the buffer and read the whole buffer from the zpty.

Should fix a couple issues reported in #342.

@vaeth
Copy link
Contributor

vaeth commented Jul 1, 2018

There is a problem with this patch which already happened sometimes with auto-fu.zsh:
Sometimes the input now hangs forever and can only be shut off with Ctrl-C.

In contrast to auto-fu.zsh, after a Ctrl-C in such a situation the shell can become unusable.
There occurs repeatedly the message

_zsh_autosuggest_strategy_completion:zpty:12: pty command name already used: zsh_autosuggest_completion_pty

@vaeth
Copy link
Contributor

vaeth commented Jul 1, 2018

I should add that this message appeared already sometimes without this patch, but I was not able to reproduce it like now. (And it did not make the shell unusable).

@ericfreese ericfreese force-pushed the features/improved-completion-suggestions branch from 8334877 to fc8c034 Compare July 1, 2018 14:51
@ericfreese
Copy link
Member Author

ericfreese commented Jul 1, 2018

There is a problem with this patch which already happened sometimes with auto-fu.zsh:
Sometimes the input now hangs forever and can only be shut off with Ctrl-C.

Interesting. I was seeing this locally before, but it was fixed for me with this patch. I was seeing it most reliably when typing a space after man and only when using synchronous mode (not setting ZSH_AUTOSUGGEST_USE_ASYNC).

Have you found a case that reproduces the problem consistently? Can you provide more details?

@ericfreese
Copy link
Member Author

ericfreese commented Jul 1, 2018

Also, I did just force push a small change that fixed a problem using autosuggest with zsh-syntax-highlighting after this patch. Maybe it would help with auto-fu as well. Can you try the most recent commit 6a3e310?

@vaeth
Copy link
Contributor

vaeth commented Jul 1, 2018

It seems that there are 2 things involved.

  1. One seems to be a bug in zsh that a certain completion takes ages.
  2. If this completion is stopped with Ctrl-C, then after the next key the above message appears and the shell becomes unusable (also with the latest change 6a3e310). This is perhaps a bug in zsh-autosuggest.

Concerning the completion which takes ages: This happens also with ordinary completion (i.e. without zsh-autosuggestions). The strange thing is that the delay happens after the completion function finishes, i.e. somewhere in zsh itself. If zsh-autosuggest is not loaded, then pressing Ctrl-C has no effect, but eventually zsh becomes usable again.

I needed quite some time to find a minimal example, since it is hard to produce: If the number of completions is reduced from 40000 to 10000, there is almost delay; so maybe there is some memory issue involved (if you have much more ram maybe you have to increase until you hit the "critical" limit).

Also, the delay does not appear if the _description command is omitted

#compdef 2
local expl
_description a expl a
compadd "$expl[@]" - {1..40000}

@vaeth
Copy link
Contributor

vaeth commented Jul 1, 2018

After removing the line

zstyle ':completion:*' sort false

from my .zshrc due to #342 it turns out that the delay disappeared.
This is quite surprising, since I would have expected the opposite: That sorting takes time and not omitting sorting. I think I will report this on the zsh-dev mailing list.

@ericfreese
Copy link
Member Author

Thank you so much for your effort reproducing and bisecting your zshrc to find the offending zstyle. I've pushed a new commit 156ae5e that ensures that the zpty is always destroyed (even on ctrl-c) so that it can be recreated without issue the next time around. Please try the latest and let me know if it solves the issue for you.

As an aside, if you have completions that take a long time, you can use ZSH_AUTOSUGGEST_USE_ASYNC=true in your .zshrc to fetch suggestions asynchronously so they won't block your typing.

@vaeth
Copy link
Contributor

vaeth commented Jul 2, 2018

Indeed, 156ae5e fixes the problem.

I had tried ZSH_AUTOSUGGEST_USE_ASYNC=true before, but it had not changed anything.
If I set it now (in the above commit), I get no suggestions at all.

@ericfreese
Copy link
Member Author

If I set it now (in the above commit), I get no suggestions at all.

That's not good. Can you reproduce this using zsh -f and sourcing the plugin manually?

% zsh -f
%% autoload compinit && compinit; source path/to/zsh-autosuggestions.zsh; ZSH_AUTOSUGGEST_USE_ASYNC=true; ZSH_AUTOSUGGEST_STRATEGY=(completion)

@vaeth
Copy link
Contributor

vaeth commented Jul 2, 2018

Aha. Again it was a setting in my zshrc. This time the harmless looking
NULLCMD=:
is the culprit.

@vaeth
Copy link
Contributor

vaeth commented Jul 2, 2018

I have opened a new PR #352 for the latter.

Async mode now works great! Maybe it should become the default.

Just insert the first completion directly into the buffer and read the
whole buffer from the zpty.
If running in sync mode and a completion takes a long time, the user can
^C out of it. Without this patch, the pty will not be destroyed in this
case and the next time we go to create it, it will fail, making the
shell unusable.
To prevent the suggestion from not starting with the buffer string.

Example:

`ls / /[cursor left][cursor left]b`

Before the patch, suggests `ls /b /ls /bin/ /`

After the patch, suggests `ls /b /bin/`.

#343 (comment)
@ericfreese ericfreese force-pushed the features/improved-completion-suggestions branch from 2743a2e to f1c3b98 Compare July 2, 2018 18:25
@ericfreese
Copy link
Member Author

Async mode now works great! Maybe it should become the default.

Yes, it will eventually become the default. The implementation was just completely rewritten on develop branch though, so I will probably wait for some more kinks to be worked out before making it the default.

@ericfreese ericfreese merged commit 106bf02 into develop Jul 2, 2018
@ericfreese ericfreese deleted the features/improved-completion-suggestions branch July 2, 2018 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants