dawsers / telescope-file-history.nvim

Neovim local file history managed by git and Telescope
MIT License
12 stars 5 forks source link

Add telescope diff support #2

Open ColinKennedy opened 10 months ago

ColinKennedy commented 10 months ago

Hi, I just started using your plugin today and am enjoying it. I wrote an old plugin to do a global git backup https://github.com/ColinKennedy/vim-git-backup but it's a bit slow, doesn't work on Windows, and has no interactivity. I found your plugin and got excited to try it!

This is minor but the highlighting could be a bit better depending on the colorscheme. I added tree-sitter support which I thought gives a good out of box experience for those colorschemes.

Summary

Adds optional tree-sitter parsing (and highlights) if available. Regex can be used as a fallback.

Before

telescope-file-history nvim_before_highlights

After

telescope-file-history nvim_after_highlights

dawsers commented 10 months ago

What is the advantage of tree-sitter highlights while diffing? My understanding is it doesn't keep the underlying file format highlighting either, just adds color to the added and deleted lines, same as with regex highlighting. In the example you show, the problem is your theme is probably not configured with the right colors (DiffAdd, DiffChange, DiffDelete, DiffText). This is what I see in the preview buffer:

file-history

ColinKennedy commented 10 months ago

My theme has those highlight groups defined - https://github.com/ColinKennedy/hybrid2.nvim/blob/c8eda875f5a84ae2537d181a65d7565f413df8ea/lua/hybrid2/theme.lua#L128-L131. Funnily enough, the tree-sitter out-of-box highlighting gets the hlighlights that you see here using just 2 highlight groups (which simply link back to DiffAdd and DiffDelete https://github.com/ColinKennedy/hybrid2.nvim/blob/c8eda875f5a84ae2537d181a65d7565f413df8ea/lua/hybrid2/theme.lua#L195-L196). Why they don't apply on the tree-sitter parser but not to the regex highlighting, I'm not sure.

FWIW tree-sitter can keep the underlying file format highlighting if the parser is extended with injections. Unrelated to this PR of course but would probably be a worthy feature request to https://github.com/the-mikedavis/tree-sitter-diff. Tree-sitter also has lots of interesting ways it can be extended with optional, out-of-plugin .scm files if you've never tried them before. It's pretty great!

dawsers commented 10 months ago

Yes, I use tree-sitter extensively in my other plugins. Have a look at navigator.nvim or edit-code-block.nvim, for example. They use injections and multi-language tree-sitter graph parsing. It is just in this case I didn't want to add an extra dependency for something that should work out of the box with most themes. I really don't know what the problem is with your theme.