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

Cannot input anything after install highlighting plugin #842

Open wasPrime opened 2 years ago

wasPrime commented 2 years ago

I encountered a problem that shows _zsh_highlight_main_highlighter_highlight_list:87: error in flags after installing highlighting plugin, setting plugins=(<other plugins> zsh-syntax-highlighting) in ~/.zshrc and running source ~/.zshrc, and I cannot input anything. This problem is as same as another closed issue https://github.com/zsh-users/zsh-syntax-highlighting/issues/805.

The below image is from issue https://github.com/zsh-users/zsh-syntax-highlighting/issues/805. There is a little difference that my error line number is 87 and that issue's error line number is 86. I think both is exactlty the same problem. :)

issue_image

I found that my zsh version was zsh 4.3.10 (x86_64-redhat-linux-gnu), and I installed a later zsh(reference from: https://www.codeleading.com/article/89254852381/) and used the new zsh(In VSCode, I click Select Default Shell in terminal and select zsh(/usr/local/bin/zsh). The version of the later zsh I installed is zsh 5.0.2 (x86_64-unknown-linux-gnu). Then I can use zsh-syntax-highlighting and other plugins like zsh-autosuggestions normally.

phy1729 commented 2 years ago

This appears to be due to

args=(${(zZ+c+)buf})

It seems the Z PE flag was introduced in zsh-users/zsh@66152e8adad7b00935c0b5fbe0cf0a7df3c639c7 which I think was first included in 4.3.11.

danielshahaf commented 2 years ago

zsh-users/zsh@66152e8 which I think was first included in 4.3.11.

That's correct. If you follow the link on github you can click the ellipsis at the bottom of the log message box to see the list of tags that include that commit.

danielshahaf commented 2 years ago

4.3.10 isn't supported:

https://github.com/zsh-users/zsh-syntax-highlighting/blob/c7caf57ca805abd54f11f756fda6395dd4187f8a/README.md#L6

We used to require 4.3.17, but the threshold was lowered in #440. It seems that the threshold was lowered as far as tests still passed — i.e., that we require "4.3.11+" specifically because 4.3.10 is known not to work.

4.3.11 was released on 2010-12-20, just under eleven years ago.

I'm not sure what's the best we can do under 4.3.10. If we remove the Z+c+ part and assuming for the moment that INTERACTIVE_COMMENTS is unset, does everything else work?

Then again, perhaps we should add an explicit $ZSH_VERSION check and bail out under old zsh's.

wasPrime commented 2 years ago

4.3.10 isn't supported:

https://github.com/zsh-users/zsh-syntax-highlighting/blob/c7caf57ca805abd54f11f756fda6395dd4187f8a/README.md#L6

We used to require 4.3.17, but the threshold was lowered in #440. It seems that the threshold was lowered as far as tests still passed — i.e., that we require "4.3.11+" specifically because 4.3.10 is known not to work.

4.3.11 was released on 2010-12-20, just under eleven years ago.

I'm not sure what's the best we can do under 4.3.10. If we remove the Z+c+ part and assuming for the moment that INTERACTIVE_COMMENTS is unset, does everything else work?

Then again, perhaps we should add an explicit $ZSH_VERSION check and bail out under old zsh's.

For a user who doesn't know how the plugin works, it's actually easier to understand the error information if adding an explicit $ZSH_VERSION limit. :)

phy1729 commented 2 years ago

I wouldn't be opposed to something like the below. Any opinions on wording?

diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh
index d20dc5b..dfa5409 100644
--- a/zsh-syntax-highlighting.zsh
+++ b/zsh-syntax-highlighting.zsh
@@ -108,6 +108,10 @@ else
   typeset -g zsh_highlight__pat_static_bug=true
 fi

+if ! is-at-least 4.3.11 && ! (( $+ZSH_HIGHLIGHT_KNOWN_OLD )); then
+  print >&2 'zsh-syntax-highlighting: warning: zsh versions prior to 4.3.11 are not supported. Set ZSH_HIGHLIGHT_KNOWN_OLD to suppress this warning.'
+fi
+
 # Array declaring active highlighters names.
 typeset -ga ZSH_HIGHLIGHT_HIGHLIGHTERS
danielshahaf commented 2 years ago

@wasPrime The error message is a zsh syntax error message. It shouldn't be ending up anywhere near end users (it's at too low a layer of abstraction).

danielshahaf commented 2 years ago

@phy1729 Maybe add a few words to preëmpt "What does 'are not supported' means?" questions? E.g., 'are not supported and [one-sentence description of the failure mode]'?

Did you intend to have something other than print in the block, e.g., a return 1? Seems reasonable given the failure mode…?

gongruiyang commented 1 year ago

I have the same problem, what should i do to solve this?

wasPrime commented 1 year ago

I have the same problem, what should i do to solve this?

Try to upgrade the version of zsh such as zsh 5.0.2. : )

gongruiyang commented 1 year ago

I can't input or run any cmd, How to upgrade?

wasPrime commented 1 year ago

I can't input or run any cmd, How to upgrade?

Sorry for late reply. Maybe you can try to use another shell base (e.g. bash) to remove the configuration about the highlighting plugin. Then you could upgrade zsh.