-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
git commit message highlighting #1338
git commit message highlighting #1338
Conversation
example of configuring a theme to differentiate the |
Would I be stepping on theme-maintainers' toes by updating existing themes to add the new scopes? (and wow the themes dir has been growing! :D) |
This seems to be missing highlighting for untracked file names that are not staged.
|
Ah yeah I thought about untracked files but it would be a bit more difficult to parse them with how the grammar is currently written. I was thinking it'd be fine to leave them unhighlighted (and hence highlighted as comment) since they're unstaged and aren't really important to the commit anyways It might be nice to at least have the option to highlight those paths though, especially for the similar case of conflicts in a merge/rebase like so:
|
I also think that there should be some highlighting for the headers, like |
Ok @Omnikar I wrangled the grammar a bit and now there's highlighting for summary headers (Conflicts/Untracked files/Changes to be committed) and paths under those headers. That rebase-commit from above now looks pretty: (and for the online playground, I mucked with the setup a bit so you'll have to clear local storage or open in a private window to kick the playground into a good state, if you want to try these new changes there) |
Looks great! |
Sure, if you don't mind! Can just copy-paste the defaults if you don't know which colors to use |
I just want to say that this is a very exciting PR for me because git commit messages are the last thing that I still use Vim for, so I'll finally be able to completely switch over to Helix once this is merged. 😄 |
@archseer w.r.t. the scissors, I updated the grammar to parse out the scissors comment as a node within I think you're using
So I'd like to support both and leave it up to the query to figure out what is diff and what isn't. (btw I didn't know about verbose commit, I'm definitely stealing that in my dotfiles now :D the-mikedavis/dotfiles@8280144) also I think a diff grammar is up next for me :) |
Ok so I took a crack at a diff parser based on those injections.scm queries (repo, integration branch) and it's looking good, albeit it's a little buggy: line-25 is picking up as an addition but only when injected 🤔 I'll poke around the grammar and see if that's the grammar or maybe a bug in tree-sitter. |
Huh, I completely forgot about that: https://github.com/archseer/snowflake/blob/4079405214666163c50cfbf71d798e63895814ae/users/profiles/git/default.nix#L60
That would be great :D Wish we could also syntax highlight the diffs but that will be hard with tree-sitter since we only get partial code fragments, not the whole file. |
Ooo highlighting within diffs would be super sweet. Maybe you can reconstruct the full file by consulting the git index in some cases? Could be a cool feature of a git-porcelain plugin some day |
I use https://github.com/dandavison/delta that does this for git diffs, there's a nixos module for it too |
a234d55
to
bb8f2da
Compare
I was thinking it should also be possible to inject tree-sitter-git-rebase under those "last command done" / "next command to do" headers. I'll see if tree-sitter-gitcommit needs any changes to support that edit: added a |
fbdd5b4
to
33d1921
Compare
33d1921
to
5f75e6c
Compare
Shouldn't it be named |
Hmm that's weird that highlighting doesn't work with I was leaning into some prior art here with that rename:
Let me do a fresh clone of helix to make sure I don't have any weird submodule things hanging around |
Hm, maybe the issue is on my end, I'll try again. |
OK, I tried rebuilding everything and it still didn't work. |
Ok I tried a fresh clone and build
And I the scopes and highlights seem to be working for me. Maybe there's something strange going on with the submodules you have? I renamed the repository and I had to do some funky stuff to my git index to make git happy. Maybe if you delete the branch, re-check it out and |
Huh, I tried it with a new clone and it did work… |
OK, I was able to get it to work on my main clone by deleting and refreshing the submodule and |
Tested, LGTM! 👍 |
see helix-editor/helix#1338 (comment) Leading whitespace is important when injecting diff highlights into messages trailing the scissors. Without this change, some adverserial context lines can end up being mistakenly parsed as non-$.context rules. For example, in the screenshot of the linked issue comment, a context line is being parsed by a tricky link that looks like a malformed $.similarity rule. Because NEWLINE is not a child of $._line but $.source in tree-sitter-git-diff, part of the line is re-parsed into another valid $._line rule, namely $.addition in this case. For an example COMMIT_EDITMSG which has a second diff line 6 characters to the right of the newline, this commit changes the start column of the parsed $.message node to include the whitespace: (source [0, 0] - [7, 0] (subject [0, 0] - [0, 53]) (comment [2, 0] - [4, 38] (scissors [2, 0] - [4, 38])) (message [5, 0] - [5, 36]) - (message [6, 5] - [6, 80])) + (message [6, 0] - [6, 80])) This change probably restricts this grammar to tree-sitter 0.20.1+ because the WHITE_SPACE 'extra' is now used as an extra and within a rule (see tree-sitter/tree-sitter#1444 (comment)) but trailing diffs are not meant to be edited anyways, so it's probably not a big deal.
Git stuff was my last bastion of kakoune and I like the way kakoune highlighted new files, deletions, etc. So I made this!
I've got the playground up here if you wanna play with it ahead of time: https://the-mikedavis.github.io/tree-sitter-git-commit/
I was curious how we could choose language based on exact filename instead of extension, but according to this block, that's already possible!