Option to disable treesitter highlight in previewer
joshuali925 opened this issue · 11 comments
Feature description
Thanks for your work, have been using it until recently I ran into some performance issues with treesitter tsx and nvim 0.9. Steps to reproduce:
- 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)
require("lazy").setup({
{ "kevinhwang91/nvim-bqf" },
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
opts = { ensure_installed = { "typescript", "tsx" }, highlight = { enable = true } },
config = function(_, opts) require("nvim-treesitter.configs").setup(opts) end,
},
{
"williamboman/mason.nvim",
build = ":MasonUpdate",
dependencies = { "williamboman/mason-lspconfig.nvim", "neovim/nvim-lspconfig" },
config = function()
require("mason").setup()
require("mason-lspconfig").setup({ ensure_installed = { "tsserver" } })
require("lspconfig").tsserver.setup({})
end,
},
})
vim.cmd.colorscheme("habamax")
vim.keymap.set("n", "gd", vim.lsp.buf.definition)
nvim test.js +'norm! iURLSearchParams'
- press
gd
- nvim freezes with bqf using treesitter to highlight definition file
mason/packages/typescript-language-server/node_modules/typescript/lib/lib.dom.d.ts
nvim version
NVIM v0.9.0
Build type: Release
LuaJIT 2.1.0-beta3
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/build/neovim-stable/nvim-build/share/nvim"
Run :checkhealth for more info
Describe the solution you'd like
I'll probably create an issue in nvim or treesitter repo for performance issue, but in nvim-bqf it would be good to have an option to disable treesitter
nvim-bqf/lua/bqf/preview/handler.lua
Line 110 in e0e2b4c
Additional context
No response
Give my fork a try, https://github.com/kevinhwang91/nvim-treesitter
TBH, this opt is not very meaningful. If your editing buffer is lagging, your preview buffer should be the same. Should solve the culprit (nvim-treesitter).
I tried your fork but still got stuck, I think nvim 0.9 is having some problems with treesitter, will create a issue there
Editing buffer would have treesitter highlight disabled with this config and doesn't lag, somehow this doesn't fix performance issue in the previewer
highlight = {
enable = true,
disable = function(_, buf)
local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
return ok and stats and stats.size > vim.g.treesitter_size_threshold
end,
},
It's weird. bqf respects nvim-treesitter config setup.
nvim-bqf/lua/bqf/preview/treesitter.lua
Line 73 in 1276701
lua =require('nvim-treesitter.configs').is_enabled('highlight', ft, bufnr)
should return false for your editing buffer.
I found that bqf doesn't lag with treesitter highlight = { enable = false }
initially, but after opening lib.dom.d.ts
(large file), putting cursor back into quickfix will cause a long lag. If I comment out ts.attach
in bqf then this does not happen. I think it's not treesitter highlight but something else in treesitter is causing this
I can't reproduce the issue. lib.dom.d.ts
is just 13k lines file which is not large enough, and shouldn't cause any perf issues.
diff --git a/lua/bqf/preview/handler.lua b/lua/bqf/preview/handler.lua
index ed0a684..f019640 100644
--- a/lua/bqf/preview/handler.lua
+++ b/lua/bqf/preview/handler.lua
@@ -111,6 +111,7 @@ local function doSyntax(qwinid)
if not ps.syntax then
vim.bo[fbufnr].syntax = ft
ps.syntax = true
+ ts.disableActive(fbufnr)
end
end
end
should work for you?
it didn't work. I disabled treesitter highlight but bqf's call to treesitter here is causing the lag (about 40 seconds stuck for lib.dom.d.ts
)
nvim-bqf/lua/bqf/preview/treesitter.lua
Line 47 in 1276701
Here are the steps to reproduce with your treesitter fork and with highlights disabled:
- open test.js and type
URLSearchParams
- press
gd
- press
<CR>
to open the definition file - press
<C-w>j
to go back to bqf - nvim doesn't respond for 40 seconds
I've tried nvim nightly and 0.9 on mac/linux x64/arm64 they all have this problem, but 0.8 works ok even with treesitter highlight enabled. Not sure if i should ask core or treesitter, but it would be good if we can disable treesitter completely in bqf...
@joshuali925 I tested it on my side (nvim 0.9 on M1 mac) and experienced the freeze as well (around 13 seconds). The stuck happened at step-3. After I pressed <CR>
, it was stuck there. After nvim restored from the lag, pressing <C-w>j
to go back to qf was not stuck.
Also, it was stuck when I opened this file directly by nvim lib/lib.dom.d.ts
. So I think the problem is caused by Treesitter and core, not bqf.
Btw, I don't use mason and mason-config, and instead I installed tsserver maually. Then I cd into the dir where tsserver installed and followed the steps you listed above. As you said, I think this problem is specific to nvim 0.9 and It would be good to report it to core and treesitter. :)
UPDATE:
I tried Kevin's own treesitter fork (https://github.com/kevinhwang91/nvim-treesitter) and no lags any more. He removed the unnecessary injections that bring about many problems and have very bad performance. As for this issue, the injections in typescript is the culprit (they are inherited from ecma). After emptying typescript/injections.scm, nvim will become smooth.
I can confirm that nvim open lib.dom.d.ts
directly will be frozen if using https://github.com/nvim-treesitter/nvim-treesitter , but it's smooth if using my fork, you should make sure that my fork is working under your ENV.
I'm sure that this is nvim-treesitter issue.
BTW, thank @rockyzhang24 to provide the useful information.
Thanks @rockyzhang24 @kevinhwang91 for looking into this, this seems specific to my environment then. To summarize, I experienced two issues with either nvim-treesitter/nvim-treesitter
or kevinhwang91/nvim-treesitter
:
- Treesitter highlight causing bqf preview to freeze, which is described initially in the issue and experienced by @rockyzhang24
- With treesitter highlight disabled, bqf freezes when trying to preview
lib.dom.d.ts
again afterlib.dom.d.ts
buffer is loaded
I actually tried the same init.lua
in a clean docker container, and it worked without any lag even with nvim-treesitter/nvim-treesitter
. No idea what is in my system causing these issues, will update if i find out. Thanks again!