RRethy / vim-illuminate

illuminate.vim - (Neo)Vim plugin for automatically highlighting other uses of the word under the cursor using either LSP, Tree-sitter, or regex matching.
2.12k stars 44 forks source link

Illumination only works if treesitter removed from providers #191

Closed jimrybarski closed 5 months ago

jimrybarski commented 5 months ago

Describe the bug Illumination does not work if treesitter is included in the providers list. Removing treesitter, and only including regex (or regex and lsp) works fine. I'm not using an LSP (for the moment, as I'm slowly building up a new config from scratch).

Additionally, illumination only works if vim.opt.termguicolors is set to true. If this isn't a bug I believe it should be documented somewhere, since the readme states that installing the plugin should be sufficient.

Treesitter is definitely working (I can toggle it with :TSDisable highlight and :TSEnable highlight and see changes in the highlighting. Moving the plugin to to before or after treesitter in the lazy setup makes no difference.

To Reproduce Steps to reproduce the behavior (include minimal init.vim or .vimrc):

Minimal init.lua:

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({
        "git", "clone", "--filter=blob:none",
        "https://github.com/folke/lazy.nvim.git", "--branch=stable",
        lazypath
    })
end
vim.opt.rtp:prepend(lazypath)
vim.opt.termguicolors = true

require("lazy").setup({
    {"RRethy/vim-illuminate"},
    { "nvim-treesitter/nvim-treesitter",
      build = ":TSUpdate",
      config = function()
      local configs = require("nvim-treesitter.configs")
      configs.setup({
          highlight = {
              enable = true
          },
          ensure_installed = {
              "awk",
              "bash",
              "bibtex",
              "css",
              "diff",
              "dockerfile",
              "fish",
              "gitcommit",
              "git_config",
              "gitignore",
              "git_rebase",
              "gpg",
              "html",
              "javascript",
              "json",
              "json5",
              "latex",
              "lua",
              "luadoc",
              "make",
              "markdown",
              "markdown_inline",
              "passwd",
              "printf",
              "python",
              "r",
              "regex",
              "rust",
              "scss",
              "sql",
              "ssh_config",
              "toml",
              "tsv",
              "vim",
              "vimdoc",
              "yaml"
              }
            })
        end
    }, 
})

require('illuminate').configure({
    providers = {
        'lsp',
        'treesitter',
        'regex',
    },
})

To reproduce:

  1. Open this minimal init.lua. The cursor will be on the first word ("local") which will not highlight.
  2. Remove 'treesitter' from the providers list of the illuminate configuration.
  3. Save the file, close it, and open init.lua again. "local" will highlight, along with the "local" on line 17.
  4. Repeat by toggling vim.opt.termguicolors to false.

Output from :IlluminateDebug

buf_should_illuminate 1 true
config {
  case_insensitive_regex = false,
  delay = 100,
  filetype_overrides = {},
  filetypes_allowlist = {},
  filetypes_denylist = { "dirbuf", "dirvish", "fugitive" },
  min_count_to_highlight = 1,
  modes_allowlist = {},
  modes_denylist = {},
  providers = { "lsp", "treesitter", "regex" },
  providers_regex_syntax_allowlist = {},
  providers_regex_syntax_denylist = {},
  under_cursor = true
}
started true
provider table: 0x7307f1804240 treesitter
`termguicolors` true

Expected behavior vim-illuminate should highlight "local" and other tokens using the treesitter provider.

Additional context I'm using nvim 0.9.5 on Arch Linux (LTS).

leftas commented 5 months ago

Should be fixed with newest TS commit. Reference https://github.com/nvim-treesitter/nvim-treesitter/pull/5982

RRethy commented 5 months ago

Additionally, illumination only works if vim.opt.termguicolors is set to true. If this isn't a bug I believe it should be documented somewhere, since the readme states that installing the plugin should be sufficient.

It's not required to have termguicolors turned on, this would be an issue with your colorscheme. The default highlight is just an underline.

I'm going to close since it seems @leftas fixed this in nvim-treesitter, if the issue persists then drop a comment and I can re-open.

jimrybarski commented 5 months ago

Thanks to you both! This solved my problems. Whatever was happening with termguicolors has also gone away with the updated treesitter.