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.17k stars 48 forks source link

IlluminatePause command doesn't work properly #211

Open ronandalton opened 1 month ago

ronandalton commented 1 month ago

When hovering over a reference and executing the :IlluminatePause command, existing highlights are not immediately cleared.

To Reproduce

  1. Open Neovim.
  2. Press i to enter insert mode and enter the text abc def abc.
  3. Press escape to return to normal mode.
  4. Press 0 to position the cursor at the start of the line.
  5. Observe both references to abc are now highlighted.
  6. Execute the command :IlluminatePause
  7. Observe that the references to abc flicker but then stay in a highlighted state until the cursor is moved.

Minimal config: (save as init.lua)

-- Start nvim with the command: `nvim -nu init.lua`
-- To cleanup once finished: `rm -rf ./.repro`

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs { "config", "data", "state", "cache" } do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.uv.fs_stat(lazypath) then
  vim.fn.system {
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  }
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  {
    'RRethy/vim-illuminate',
    opts = {
      providers = {
        'regex',
      },
    },
    config = function(_, opts)
      require('illuminate').configure(opts)
    end,
  }
}

require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

Output from :IlluminateDebug

buf_should_illuminate 1 false
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 = { "regex" },
  providers_regex_syntax_allowlist = {},
  providers_regex_syntax_denylist = {},
  under_cursor = true
}
started true
provider table: 0x7486e8650c58 regex
`termguicolors` true

Expected behavior All currently highlighted references should be cleared when :IlluminatePause is issued, without having to move the cursor.

Additional context Issue seen on Neovim 0.10.1 and 0.9.5.

ronandalton commented 1 month ago

I think this is happening because buf_highlight_references is being called even when buf_should_illuminate(bufnr) is false (in engine.lua). There is a check for this at the start of the refresh_references function but the value that buf_should_illuminate evaluates to must be different when the callback for the internal timer is executed.