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 treesitter highlighting support in cat mode #98

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

adeg
Copy link

@adeg adeg commented Apr 1, 2024

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 #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:

  • Observed regular and new functionality displaying C and Bash source files in cat mode in traditional highlighting then with treesitter highlighting.
  • Confirmed that syntax highlighting colours while in treesitter mode match in side by side comparison between nvimpager in cat mode and nvim edit mode.

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 also resolves the issue with no syntax highlighting available at
all when treesitter highlighting is active, traditional and treesitter
modes are mutually exclusive; that is no traditional highlighting data
will be available if treesitter is active for a given buffer.

Testing done:
* Observed regular and new functionality displaying C and Bash source
files in cat mode in traditional highlighting then with treesitter
highlighting.
* Confirmed that  syntax highlighting colours while in treesitter mode
match in side by side comparison between nvimpager in cat mode and nvim
edit mode.
@lucc
Copy link
Owner

lucc commented Apr 5, 2024

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

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

@lucc
Copy link
Owner

lucc commented May 20, 2024

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants