Skip to content
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

Add telescope diff support #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ColinKennedy
Copy link

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

@ColinKennedy ColinKennedy force-pushed the add_telescope_diff_support branch from d3c4b8f to a30adf5 Compare December 15, 2023 06:16
@dawsers
Copy link
Owner

dawsers commented Dec 15, 2023

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
Copy link
Author

ColinKennedy commented Dec 15, 2023

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
Copy link
Owner

dawsers commented Dec 16, 2023

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.

@ColinKennedy ColinKennedy force-pushed the add_telescope_diff_support branch from a30adf5 to ea804fc Compare February 29, 2024 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants