HiPhish / nvim-ts-rainbow2

Rainbow delimiters for Neovim through Tree-sitter
https://gitlab.com/HiPhish/nvim-ts-rainbow2
Apache License 2.0
339 stars 35 forks source link

Neovim 0.9.1 hangs consuming 100% CPU #45

Open r-vdp opened 1 year ago

r-vdp commented 1 year ago

Describe the bug

Since upgrading to neovim 0.9.1, I get random hangs where neovim hangs and consumes 100% CPU on one core for seconds before recovering. I tried enabling and disabling plugins to find the culprit and it seems to be nvim-ts-rainbow2.

Steps to reproduce

I don't know yet how to trigger the issue, but it happened several times today (I upgraded neovim yesterday night).

Expected behavior

No hangs.

Config

require("nvim-treesitter.configs").setup {
  highlight = {
    enable = true,
    disable = function(lang, buf)
      local max_filesize = 100 * 1024 -- 100 KB
      local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
      if ok and stats and stats.size > max_filesize then
        return true
      end
    end,
  },

  rainbow = {
    enable = true,
    extended_mode = true,
    max_file_lines = 20000,
    query = {
      "rainbow-parens",
      html = "rainbow-tags",
      latex = "rainbow-blocks",
    }
  }
}
HiPhish commented 1 year ago

Which file type does this happen with? Can you provide a sample text? BTW, you can remove extended_mode and max_file_lines from your configuration, they do nothing in this fork.

KTheRD commented 1 year ago

I am using Astronvim with Lazy package manager, I added rainbow without any configuration like this:

return {
  "nvim-treesitter/nvim-treesitter",
  dependencies = {
    "HiPhish/nvim-ts-rainbow2",
  },
  opts = {
    rainbow = {
      enable = true,
    },
  },
}

Noticed some weird hangs when I edited some typescript, but they appeared rarely and I didn't do anything to solve them. Recently I tried out Zig language and it hangs every time I open zig file and try to edit it (even empty .zig file). Tried to remove plugins from my config, removing rainbow fixes the problem, so I think the issue is in this plugin.

Neovim version is v0.10.0-dev (neovim-nightly from AUR); Lazy fetched e1783c8 commit of rainbow.

UPD: this fork https://github.com/mrjones2014/nvim-ts-rainbow works for me

kiyoon commented 1 year ago

It doesn't hang for me but I see a noticeable slowdown. Also when I comment a block with comment.nvim or mini.comment, it takes 10 seconds. Uninstalling this plugin resolves the issue but also I think it's upstream neovim treesitter problem

HiPhish commented 1 year ago

@KTheRD Zig is a problem in general, see #43 for my findings. It is the query file itself that causes Neovim to hang for a bit every time you open your first Zig file. Even when using the no-op strategy (:h ts-rainbow.strategy.noop) the editor will freeze. After you have opened the first Zig file everything should be smooth again.

The fork you have linked works differently, it has very naive queries. These cause more problems than they solve, it is impossible to reliably determine the level of nesting for every file type and every strategy. But I guess if it works for you, then good for you.

HiPhish commented 1 year ago

@kiyoon Can you please provide a file where this happens? I tried comment.nvim and commenting out a block was instantaneous. Do you have any other Tree-sitter modules enabled as well?

kiyoon commented 1 year ago

@HiPhish If you're interested, I reported the summary of finding here

https://github.com/neovim/neovim/issues/23918

HiPhish commented 1 year ago

I would still like a sample file so I can try to replicate the problem. It could very well be on my side because after every change to the tree I have to re-compute the tree structure of delimiters.

One thing you can try is to set the strategy to the no-op strategy (:h ts-rainbow.strategy.noop). The no-op strategy does nothing, so if you still get slowdowns that's a good indicator that the problem might be on the Neovim side.

rainbow = {
    enable = true,
    strategy = {
        rainbow.strategy.noop,
    },
},
HiPhish commented 1 year ago

This plugin is now deprecated because of upcoming changes to nvim-treesitter. The new rainbow plugin is here: rainbow-delimiters.nvim (GitHub mirror). Please file an issue over there if the problem still persists.