lucc / nvimpager

Use nvim as a pager to view manpages, diffs, etc with nvim's syntax highlighting
Other
365 stars 19 forks source link

Add treesitter highlighting support in cat mode #98

Open adeg opened 3 months ago

adeg commented 3 months ago

Resolve treesitter highlighting metadata to syntax_id needed by nvim_get_hl() in group2ansi() which converts highlighting colours to ANSI escape sequences. Fallback to parsing traditional highlighting if treesitter metadata is not available.

This expected to provide functionality requested in https://github.com/lucc/nvimpager/issues/63.

This also resolves the issue with no syntax highlighting available at all when treesitter highlighting is active as traditional and treesitter modes are mutually exclusive; that is no traditional highlighting data will be available if treesitter is active for a given buffer.

Note that a workaround had to be introduced for the treesitter highlighting mode which removes background colour definition for the "Normal" highlight group. The reason is that treesitter themes seem to define the window background in in the Normal highlight group profile, which was causing spotty background issues with nvimpager rendering a different background for the parts of the text we didn't have a highlighting group for.

Testing done:

lucc commented 3 months ago

Thanks for the PR! I don't have time to review it until next week but until then you could try to find out why and how the output changed to fix the test.

PS and can we make a test case for treesitter highlighting specifically?

night0721 commented 2 months ago

Tested on local, works like charm. Will it get merged any time soon?

lucc commented 2 months ago

@night0721 I am currently thinking about how to fix the tests because neovim 0.10 changed the default colorscheme and the tests depend on it. So I am not working on it.

I am still hoping for @adeg to come back to this: This PR breaks the tests and does not add new tests for the new functionality that is added. These two points have to be addressed firsts.