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.18k stars 50 forks source link

Long lines causes illuminate to slow to a crawl. #175

Closed cazador481 closed 1 year ago

cazador481 commented 1 year ago

Describe the bug On really long lines illiminate hangs. I have a file is 5 lines long, 2 of the lines are more than 250k char long. When I goto the first word of one of those lines nvim seems to hang, after several minutes nvim comes back. If I disable illuminate things operate as they should. In addition, nvim also takes a real long time to open that file.

To Reproduce

Using lazyvim's defaults. Which are:

{
    "RRethy/vim-illuminate",
    event = { "BufReadPost", "BufNewFile" },
    opts = {
      delay = 200,
      large_file_cutoff = 2000,
      large_file_overrides = {
        providers = { "lsp" },
      },
    },
    config = function(_, opts)
      require("illuminate").configure(opts)

      local function map(key, dir, buffer)
        vim.keymap.set("n", key, function()
          require("illuminate")["goto_" .. dir .. "_reference"](false)
        end, { desc = dir:sub(1, 1):upper() .. dir:sub(2) .. " Reference", buffer = buffer })
      end

      map("]]", "next")
      map("[[", "prev")

      -- also set it after loading ftplugins, since a lot overwrite [[ and ]]
      vim.api.nvim_create_autocmd("FileType", {
        callback = function()
          local buffer = vim.api.nvim_get_current_buf()
          map("]]", "next", buffer)
          map("[[", "prev", buffer)
        end,
      })
    end,
    keys = {
      { "]]", desc = "Next Reference" },
      { "[[", desc = "Prev Reference" },
    },
  },

Note Omitting a minimal init.vim/init.lua/.vimrc will likely result in the issue being closed without explanation.

Output from :IlluminateDebug

buf_should_illuminate 1 true
config {
  delay = 200,
  filetype_overrides = {},
  filetypes_allowlist = {},
  filetypes_denylist = { "dirbuf", "dirvish", "fugitive" },
  large_file_cutoff = 2000,
  large_file_overrides = {
    providers = { "lsp" }
  },
  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: 0x7f7ab0fdc7e8 regex
`termguicolors` true
cazador481 commented 1 year ago

Thank you, using the code snippet in #161 and your changes fixed my issue.