Skip to content

Treesitter support #63

Open
Open

Description

@fhill2

Can nvimpager show treesitter syntax highlighting?

From my tests below, nvimpager.lua isn't parsing treesitter syntax highlighting.

Here is what I am using to test:

mkdir -p ~/.local/share/nvimpager/site/pack/packer/opt
ln -s ~/.local/share/nvim/site/pack/packer/opt/nvim-treesitter ~/.local/share/nvimpager/site/pack/packer/opt/nvim-treesitter

~/.config/nvimpager/init.vim

packadd nvim-treesitter

lua << EOF
require'nvim-treesitter.configs'.setup {
ensure_installed = {
  "lua"
  },
highlight = {
enable = true
},
}
EOF

using nvimpager on a lua file to see if treesitter works:

nvimpager ~/lua.lua # shows nvim syntax highlighting
nvimpager -c ~/lua.lua # shows nvim syntax highlighting
nvimpager -p ~/lua.lua # shows treesitter highlighted text

Activity

  1. lucc commented on Jun 13, 2022

    @lucc
    Owner

    Sorry, somehow I missed this issue. I just checked and I can reproduce it.

  2. MatthiasGrandl commented on Dec 2, 2022

    @MatthiasGrandl

    Can also confirm. Also tabstop settings are ignored in cat mode, but work fine in pager mode.

  3. lucc commented on Sep 29, 2023

    @lucc
    Owner

    Today I found out that synID() which was used in cat mode does not see all highlights added to a position. I will have to refactor cat mode to use vim.inspect_pos()

    Ref https://vi.stackexchange.com/a/41586/18062

  4. night0721 commented on Mar 20, 2024

    @night0721

    Would this be fixed any time soon?

  5. lucc commented on Mar 20, 2024

    @lucc
    Owner

    You are welcome to work on it. I currently do not have the time to fix it / I can not give an ETA.

    As noted above it would be necessary to refactor the code to use vim.inspect_pos() instead of synID(). I previously had a short look at the output of that function and it seems it yields all different extmarks and treesitter tokens like this:

    {
      buffer = 14,
      col = 3,
      extmarks = { {
          col = 2,
          end_col = 10,
          end_row = 112,
          id = 25,
          ns = "illuminate.highlight",
          ns_id = 20,
          opts = {
            end_col = 10,
            end_right_gravity = false,
            end_row = 112,
            hl_eol = false,
            hl_group = "IlluminatedWordText",
            hl_group_link = "IlluminatedWordText",
            ns_id = 20,
            priority = 199,
            right_gravity = true
          },
          row = 112
        } },
      row = 112,
      semantic_tokens = {},
      syntax = {},
      treesitter = { {
          capture = "string",
          hl_group = "@string.yaml",
          hl_group_link = "Constant",
          lang = "yaml",
          metadata = {}
        }, {
          capture = "property",
          hl_group = "@property.yaml",
          hl_group_link = "Identifier",
          lang = "yaml",
          metadata = {}
        } }
    }

    The main question I had (and did not have the time to figure out) was in which order these different highlight groups should be stacked/merged to produce the final display attributes.

  6. night0721 commented on Mar 20, 2024

    @night0721
  7. adeg commented on Mar 31, 2024

    @adeg

    Hey folks — just to let to whoever is interested to know — I have managed to add treesitter syntax highlighting support. The only piece that's missing is a way to determine if the treesitter resolver function that I wrote should be used instead of built-in synID, so that compatibility with regular syntax highlighting is preserved.
    As soon as this is done followed by some testing — I will submit a pull request.

  8. added
    cat moderelated to the cat mode of nvimpager or the conversion of highlight groups to ansi escape sequences
    on Feb 15, 2025
  9. Freed-Wu commented on Mar 5, 2026

    @Freed-Wu

    If you want to cat a file with treesitter's syntax hightlight, there exist some alternatives:

    • texcat: written in lua, output to terminal/LaTeX/HTML
    • syncat: written in rust, output to terminal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcat moderelated to the cat mode of nvimpager or the conversion of highlight groups to ansi escape sequenceshelp wanted

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions