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

Treesitter support #63

Open
fhill2 opened this issue Mar 16, 2022 · 7 comments
Open

Treesitter support #63

fhill2 opened this issue Mar 16, 2022 · 7 comments

Comments

@fhill2
Copy link

fhill2 commented Mar 16, 2022

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
@lucc lucc added the bug label Jun 13, 2022
@lucc
Copy link
Owner

lucc commented Jun 13, 2022

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

@MatthiasGrandl
Copy link

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

@lucc
Copy link
Owner

lucc commented Sep 29, 2023

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

@night0721
Copy link

Would this be fixed any time soon?

@lucc
Copy link
Owner

lucc commented Mar 20, 2024

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.

@night0721
Copy link

night0721 commented Mar 20, 2024 via email

@adeg
Copy link

adeg commented Mar 31, 2024

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.

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

No branches or pull requests

5 participants