zsh-users / zsh-syntax-highlighting

Fish shell like syntax highlighting for Zsh.
github.com/zsh-users/zsh-syntax-highlighting
BSD 3-Clause "New" or "Revised" License
20k stars 1.33k forks source link

"_zsh_highlight_call_widget: maximum nested function level reached; increase FUNCNEST?" error when plugin is used along with zsh-autocomplete #812

Closed robole closed 3 years ago

robole commented 3 years ago

Hi

Thanks for your work. I like the plugin.

One issue I have is that it doesn't play nice with the plugin zsh-autocomplete. I get the error below when I execute most (all?) commands it seems.

Kazam_screenshot_00000

I commented out all other plugin/scripts in my zshrc and found that it was by removing zsh-autocomplete made the error go away. See excerpt below:

#...

# Plugins
source ~/zsh-plugins/zsh-autocomplete/zsh-autocomplete.plugin.zsh

# leave as last plugin
source ~/zsh-plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

I have the latest of both plugins. You can find my entire zshrc in this gist

I am running zsh 5.8 on ubuntu 20.04.

danielshahaf commented 3 years ago

@robole Still investigating. In the meantime, you might sourcing the two plugins in the opposite order, and/or the following patch (the caveat about interoperability, in the comment above the hunk context, doesn't apply to marlonrichert/zsh-autocomplete as it stands today).

diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh
index d20dc5b..bad5c70 100644
--- a/zsh-syntax-highlighting.zsh
+++ b/zsh-syntax-highlighting.zsh
@@ -414,7 +414,7 @@ _zsh_highlight_call_widget()
 #
 #    See _zsh_highlight for the magic version number.  (The use of 5.8.0.2
 #    rather than 5.8.0.3 as in the _zsh_highlight is deliberate.)
-if is-at-least 5.8.0.2 $ZSH_VERSION.0.0 && _zsh_highlight__function_callable_p add-zle-hook-widget
+if is-at-least 5.3 $ZSH_VERSION.0.0 && _zsh_highlight__function_callable_p add-zle-hook-widget
 then
   autoload -U add-zle-hook-widget
   _zsh_highlight__zle-line-finish() {
danielshahaf commented 3 years ago

zsh-autocomplete overwrites the z-sy-h internal implementation detail function that the error message is about (meaning the error might not be z-sy-h's fault at all, despite the function's name):

https://github.com/marlonrichert/zsh-autocomplete/blob/405c29211047968516c9dbd9f41146976725462e/module/.autocomplete.async#L29-L34

@marlonrichert Do not define functions in the _zsh_highlight_* namespace except as specifically permitted in the z-sy-h documentation.

robole commented 3 years ago

@danielshahaf Thanks Daniel. Reversing the order did the trick. 👍

What is the preferred scenario going forward?

marlonrichert commented 3 years ago

@danielshahaf I'm not defining a new function in the _zsh_highlight_* namespace. Rather, I'm patching your existing function, because it breaks kill/yank widget chaining, as described in various issues here. (I'd point you to the right one, but I think you know better than I which one that is. 🙂) Yes, you have a fix for it somewhere, but that won't work until Zsh 5.9 is released (and everyone using both our plugins upgrades to Zsh 5.9).

zsh-autocomplete itself has a functional workaround for this problem, but as soon as zsh-syntax-highlighting is introduced, everything breaks again. Hence, the patch.


@robole I cannot reproduce your issue, no matter in which order I source the plugins. This makes me think there might be something interfering in your global rcs. Have you tried restarting with exec zsh -d? This disables global rc files.

Do any of these issues look like your problem? If not, feel free to open a new one.

danielshahaf commented 3 years ago

@robole What I can say for certain is that once you upgrade to (not yet released) 5.9, the function in the error message won't be called by z-sy-h at all. I'm not certain why the error message occurs in the first place (probably an infinite recursion, but why does that happen?), so I'm not sure whether under 5.9 things would just work™ or would fail differently.

@marlonrichert Do not define functions in the _zsh_highlight_* namespace except as specifically permitted in the z-sy-h documentation.

robole commented 3 years ago

hi @marlonrichert & @danielshahaf

yesterday, the issue was persistent. today, there is no issue! the order of the 2 plugins does not reproduce the issue! 😅

i followed the troubleshooting section of the zsh-autocomplete README yesterday before I filed this issue. So, the completion cache was cleared and I ran zsh without global config also. It didn't impact it then.

i cant really point out something that might have caused it, but maybe it was related to caching by the fact that today when i rebooted my machine, it was fine. otherwise, i did not change anything from yesterday.

thanks for your help. i hope it was a freak once-off and it does not reoccur.

marlonrichert commented 3 years ago

Do not define functions in the _zshhighlight* namespace except as specifically permitted in the z-sy-h documentation.

@danielshahaf I already replied to your statement. Feel free to copy-paste it here, but I'm not going to do that.

danielshahaf commented 3 years ago

@marlonrichert Remove the (re-)definition of _zsh_highlight_call_widget from https://github.com/marlonrichert/zsh-autocomplete.

danielshahaf commented 3 years ago

@robole Thanks for the update. Closing, but reopen if it recurs.

marlonrichert commented 3 years ago

@danielshahaf Patches welcome. ❤️

danielshahaf commented 3 years ago

@marlonrichert It's not the responsibility of the z-sy-h authors to fix third party code that uses z-sy-h incorrectly.

marlonrichert commented 3 years ago

@danielshahaf Patches welcome. ❤️

danielshahaf commented 3 years ago

Full credit for humour.

However, in general, when product foo uses product bar, errors in foo's usage of bar are to be fixed by foo's maintainers. That's how it is. You wrote the bug and you maintain the project it is in, so it is you who should fix the bug.

jottr commented 11 months ago

I see the same a similar issue, even after disabling zsh-autosuggest (and completely restarting my shell) .

$ zsh --version
zsh 5.9 (arm-apple-darwin21.3.0)
$ true
_zsh_highlight_widget_zle-line-finish: job table full or recursion limit exceeded
cat ~/.zplug.zsh
# --- snip 
zplug 'zsh-users/zsh-syntax-highlighting', defer:2
# snip ---

What can I do?

phy1729 commented 11 months ago

This issue is already closed. Please open a new issue with a minimal reproducer starting from zsh -f and sourcing zsh-syntax-highlighting.