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

`vim-illuminate` not highlighting word under cursor despite being loaded #154

Closed SichangHe closed 1 year ago

SichangHe commented 1 year ago

Describe the bug I have just installed vim-illuminate with Packer and loaded it, but I don't have words under cursor highlighted.

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

  1. Use this init.lua:
    require('packer').startup(function(use)
    use {
        'RRethy/vim-illuminate',
    }
    end)
  2. Reenter Neovim.
  3. Run :PackerCompile (no :PackerSync because already run before).
  4. Reenter Neovim, opening init.lua.
  5. Move the cursor to use, notice that neither use is highlighted.

Output from :IlluminateDebug

buf_should_illuminate 1 true
config {
  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: 0x0110836378 treesitter
`termguicolors` false

Expected behavior Both use should be highlighted via Regex matching.

Screenshots Screen Shot 2

Additional context Initially, I tried with Lsp plugins, and it did not highlight variables under cursor either.

$ nvim --version
NVIM v0.8.2
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by brew@HMBRW-A-001-M1-005.local

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.8.2/share/nvim"

Run :checkhealth for more info
$ uname -a
Darwin blah.local 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:20:05 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T8101 arm64 arm Darwin
jamezwhocares commented 1 year ago

Same here. Tried disabling LSP and treesitter - no highlighting. a-n and a-p work.

Output from :IlluminateDebug

buf_should_illuminate 7 true
config {
  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: 0x0110553e18 lsp
`termguicolors` true

:checkhealth doesn't report any error .

$ nvim --version
NVIM v0.9.0-dev-521+g1c4794944-dirty
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by me@foo.local

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/Cellar/neovim/HEAD-1c47949/share/nvim"

Run :checkhealth for more info
$ uname -a
Darwin foo.local 21.6.0 Darwin Kernel Version 21.6.0: Sun Nov  6 23:31:16 PST 2022; root:xnu-8020.240.14~1/RELEASE_X86_64 x86_64
RRethy commented 1 year ago

@SichangHe you probably need to turn on :set termguicolors since your IlluminateDebug shows that option as being turned off.

RRethy commented 1 year ago

@jamezwhocares please open another issue with the issue template filled out (and include the output from :hi IlluminatedWordText, :hi IlluminatedWordRead, :hi IlluminatedWordWrite), your issue looks different. If I had to guess you might not have highlight groups defined which would indicate you are calling :hi clear somewhere (or something you use calls it), creating a minimal init.lua should make it obvious where this is being done.

SichangHe commented 1 year ago

@SichangHe you probably need to turn on :set termguicolors since your IlluminateDebug shows that option as being turned off.

That option works.

However, in my case the problem is from onedark.nvim, and I need to manually set the three highlight groups:

require('packer').startup(function(use)
    use {
        'RRethy/vim-illuminate',
    }
    use {
        'navarasu/onedark.nvim',
        config = function()
            local onedark = require('onedark')
            onedark.setup {
                style = 'light',
                highlights = {
                    IlluminatedWordText = { bg = '#e6e6e6' },
                    IlluminatedWordRead = { bg = '#e6e6e6' },
                    IlluminatedWordWrite = { bg ='#e6e6e6' },
                },
            }
            onedark.load()
        end,
    }
end)

(Note: the color here are copied from hi LspReferenceText.)


Thank you, @RRethy, for your useful hint.

RRethy commented 1 year ago

@SichangHe The problem is actually with packer. It is loading plugins in the incorrect order, user-configuration should be guaranteed to run prior to plugin code :h initialization, but packer breaks that ordering.

SichangHe commented 1 year ago

I thought that way, too. But, it still did not work after I specified a requires for vim-illuminate to tell packer to load it after onedark.

Anyway, underline with onelight looks bad and I would need to change the highlight group anyway.

jamezwhocares commented 1 year ago

@RRethy thanks for pointing to problem: it was similar to @SichangHe: I have rose-pine theme, and it was interfering/clearing highlight groups (I'm using packer, too, and vim-illuminate is loading last).

Something like this helps out:

require('rose-pine').setup({
    disable_background = true,
    highlight_groups = {
        IlluminatedWordText = { style = 'underline' },
        IlluminatedWordRead = { style = 'underline' },
        IlluminatedWordWrite = { style = 'underline' },
    },
})