zdharma-continuum / fast-syntax-highlighting

Feature-rich syntax highlighting for ZSH
BSD 3-Clause "New" or "Revised" License
1.06k stars 76 forks source link

[bug]: Broken syntax highlighting for --message option in git commit. #47

Closed jinyongp closed 1 year ago

jinyongp commented 1 year ago

Describe the bug

The syntax highlighting feature seems to be broken when passing a string after the "--message" option in "git commit" command. The string is not highlighted in yellow, instead it is highlighted in red.

It seems that there are no tests for the --message option but -m. https://github.com/zdharma-continuum/fast-syntax-highlighting/blob/7c390ee3bfa8069b8519582399e0a67444e6ea61/test/parse.zsh#L94

Steps to reproduce

  1. Run git commit -m "commit message" command, observe that the string is highlighted in yellow
  2. Run git commit --message "commit message" command, observe that the string is highlighted in red

Expected behavior

The string passed with the --message option in git commit command should be highlighted in yellow, same as when using the -m option.

Screenshots and recordings

image

Operating System & Version

darwin22.0 | apple | x86_64 | arm64 | arm64 arm

Zsh version

zsh 5.8.1 (x86_64-apple-darwin22.0)

Terminal emulator

xterm-256color

If using WSL on Windows, which version of WSL

None

Additional context

No response

Ultimator14 commented 1 year ago

I'm not sure if this is a problem with fsh. According to the git man page the syntax should be --message= and that also works for me.

-m <msg>, --message=<msg>
           Use the given <msg> as the commit message. If multiple -m options are given, their values are concatenated as separate
           paragraphs.

           The -m option is mutually exclusive with -c, -C, and -F.
jinyongp commented 1 year ago

Oh.. Your opinion makes sense. However, it doesn't seem possible to create an alias using the --message= option. I use the git alias plugin in on-my-zsh, and all of them use the long option format, so I just override the ones I use frequently. Anyway, the --message option still works, so it would be nice if it could be added if possible.

Ultimator14 commented 1 year ago

I had the same problem and solved it the same way, replacing --message with -m for my aliases ;)

As far as I understand fsh takes the information whether a command is correct from the zsh completion system. The completion file for git should be this one https://github.com/zsh-users/zsh/blob/master/Completion/Unix/Command/_git (installed at /usr/share/zsh/5.9/functions/Completion/Unix/_git). You could try to add --message there.

jinyongp commented 1 year ago

thx, @Ultimator14. It's very helpful.

Ultimator14 commented 1 year ago

I was wrong. The zsh source is just for tab completion (they also always use the --message= style). But fsh has it's command definitions here https://github.com/zdharma-continuum/fast-syntax-highlighting/blob/master/%E2%86%92chroma/-git.ch.

This should do the job

diff --git "a/\342\206\222chroma/-git.ch" "b/\342\206\222chroma/-git.ch"
index 12a97b3..43693ce 100644
--- "a/\342\206\222chroma/-git.ch"
+++ "b/\342\206\222chroma/-git.ch"
@@ -155,7 +155,7 @@ fsh__git__chroma__def=(
     subcmd:commit "COMMIT_#_opt // FILE_#_arg // NO_MATCH_#_opt"

     "COMMIT_#_opt" "
-              (-m|--message=|-am)
+              (-m|--message=|--message|-am)
                        <<>> NO-OP // ::→chroma/-git-commit-msg-opt-action
                        <<>> NO-OP // ::→chroma/-git-commit-msg-opt-ARG-action
            || (--help|-a|--all|-p|--patch|--reset-author|--short|--branch|