Skip to content

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.

@kaliberr44
Copy link

I tried to run this using cat mode, but still no colouring. This is my nvimpager config:

-- This file is automatically loaded by plugins.core
vim.g.mapleader = " "
vim.g.maplocalleader = "\\"

vim.opt.clipboard = vim.env.SSH_TTY and "" or "unnamedplus" -- Sync with system clipboard
vim.opt.number = true -- Make line numbers default
-- Case-insensitive searching UNLESS \C or one or more capital letters in the search term
vim.opt.ignorecase = true
vim.opt.smartcase = true
vim.opt.termguicolors = true

vim.opt.shiftround = true -- Round indent
vim.opt.shiftwidth = 2 -- Size of an indent
vim.opt.tabstop = 2 -- Number of spaces tabs count for
vim.opt.scrolloff = 4 -- Lines of context
vim.opt.sidescrolloff = 8 -- Columns of context
vim.opt.linebreak = true -- Wrap lines at convenient points
vim.opt.laststatus = 3 -- global statusline
vim.opt.showmode = false -- Dont show mode since we have a statusline
vim.opt.showcmd = false -- Dont show command or size of selected area

vim.opt.runtimepath:append("~/.local/share/nvim/lazy/github-nvim-theme,~/.local/share/nvim/lazy/nvim-treesitter")
vim.cmd("colorscheme github_dark_dimmed")

require("nvim-treesitter.configs").setup({
	modules = { "highlight", "indent", "incremental_selection" },
	auto_install = true,
	sync_install = false,
	ignore_install = {},
	highlight = { enable = true },
	indent = { enable = true },
	incremental_selection = { enable = true },
	ensure_installed = {
		"bash",
		"c",
		"diff",
		"html",
		"javascript",
		"jsdoc",
		"json",
		"jsonc",
		"lua",
		"luadoc",
		"luap",
		"markdown",
		"markdown_inline",
		"printf",
		"python",
		"query",
		"regex",
		"toml",
		"tsx",
		"typescript",
		"vim",
		"vimdoc",
		"xml",
		"yaml",
	},
})

Am I doing something wrong? Colouring works in pager mode though.

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.

4 participants