Search code examples
neovimtreesitter

Link one Treesitter highlight group to another


Trying to undergo the Neovim 0.10 upgrade (as it horrifically broke my colorscheme, so I've put it off), but I'm running into an issue when it comes to linking one group to another.

In my old config, I see @module.javascript links to @module javascript when I use :Inspect, but in the new, @module.javascript links to Identifier javascript.

For all other mismatched highlights I've been able to use vim.api.nvim_set_hl(0, "@foo.bar", { link = "Identifier" }) per the docs, but vim.api.nvim_set_hl(0, '@module.javascript', { link = '@module' }) doesn't seem to work correctly.

How can I restore this behavior? Is there a different function or form that I need to use? I dug through the docs but couldn't find a single example in there or in the wild, assuming I'm not being daft and missing something obvious.


Solution

  • It seems I was mistaken, vim.api.nvim_set_hl(0, '@module.javascript', { link = '@module' }) does in fact work.

    I'm not quite sure why that failed in my specific scenario, could've been a problem with the definition of @module or something later taking precedence, but I have gotten that form to work in other situations. Nesting link targets also works, i.e., '@module.javascript', { link = '@foo.bar.baz' }.

    So the syntax should be consistent here whether you're targeting a highlight or another group.