-
-
Notifications
You must be signed in to change notification settings - Fork 618
LSP diagnostics inside nvim-tree may flicker #2954
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
I've seen a bit of flickering on and off for the diagnostic status with With the above setup you'll notice that there are multiple language servers running - it starts a new one whech every file is opened. Open nvim-tree and two other files: : ; ps aux | grep typos
alex 13574 0.0 0.0 2323388 21600 ? Ssl 09:41 0:00 typos-lsp
alex 13609 0.0 0.0 2323380 20756 ? Ssl 09:41 0:00 typos-lsp
alex 13650 0.0 0.0 2323420 21588 ? Ssl 09:41 0:00 typos-lsp
alex 13703 0.0 0.0 6396 3840 pts/3 S+ 09:42 0:00 grep --color=auto typos
: ; |
For other language servers, adding an identifying name is enough to result in the one instance being shared e.g. lua-language-server: wiki: Development: Native neovim Configuration That doesn't seem to be the case for typos-lsp. Using the "official" language server manager nvim-lspconfig did work nicely: local lspconfig = require("lspconfig")
lspconfig.typos_lsp.setup() You'll need Please let me know if that works and I'll convert this to a discussion. |
|
#2956 nvt-min.lua fixed |
You are right. With the I have to check my actual neovim config. (where I already use lspconfig with mason btw. 😅) There I observed the flickering as well. When I find the cause I will post it. Sorry for the noise and thanks for the rapid response and the effort on nvim-tree! |
No apologies needed; there are some issues here that we need to get to the bottom of. |
After a lot of stripping my configuration down I found the cause and the (already existing 🫣) solution. The underlying issue was "fixed" in neovim/nvim-lspconfig@b2c7317. Before this change a With the following config I am able to reproduce the issue. Notice I have re-enabled local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()
require("lazy.minit").setup({
spec = {
{
"neovim/nvim-lspconfig"
},
{
"kyazdani42/nvim-tree.lua",
opts = {
diagnostics = {
enable = true,
},
},
},
},
})
require("lspconfig").typos_lsp.setup({
cmd = { "PATH-TO-typos-lsp" },
filetypes = { "*" }, -- or 'NvimTree' if you like
})
vim.keymap.set("n", "<F2>", function()
require("nvim-tree.api").tree.toggle()
end) With the configuration above
Now
So with the second order the behavior is reproducible since Flickering itself is caused by lsp diagnostics I guess. When With this monkey-patched version of local view = require("nvim-tree.view")
local is_buf_valid_orig = view.is_buf_valid
---@diagnostic disable-next-line: duplicate-set-field
view.is_buf_valid = function(bufnr)
return is_buf_valid_orig(bufnr) and vim.bo[bufnr].buflisted
end I would like to be able to use I am interested in your opinions on how to continue. At least it would make sense to ensure |
Wow, great find! We should do this regardless. Would this deterministic order resolve all the above issues? An array something like this. Guessed at a sensible order. ---@type { name: string, value: any }[]
local BUFFER_OPTIONS = {
{ name = "buftype", value = "nofile" },
{ name = "filetype", value = "NvimTree" },
{ name = "buflisted", value = false },
{ name = "bufhidden", value = "wipe" },
{ name = "modifiable", value = false },
{ name = "swapfile", value = false },
}
---
bufnr = M.get_bufnr()
for _, option in ipairs(BUFFER_OPTIONS) do
vim.api.nvim_set_option_value(option.name, option.value, { buf = bufnr })
end |
That is reasonable; we can safely ignore unlisted buffers.
|
I'd be most grateful for a PR with both these changes; you're the best one to validate the solution ;) |
This ensures related autocmd's (e.g. on FileType) will be called in a similar environment.
…'buflisted' is_buf_valid has been inlined since it is only used for diagnostics and its name is misleading.
… buffer options in deterministic order (#2980) * fix(#2954): set buffer options in deterministic order This ensures related autocmd's (e.g. on FileType) will be called in a similar environment. * fix(#2954): redraw only for diagnostics if source buffer is 'buflisted' is_buf_valid has been inlined since it is only used for diagnostics and its name is misleading.
#2990 temporarily reverted this change. |
Experimenting with
Event It appears that we can use the events themselves to determine the state for each node, rather than enumerating. We can detect a delta, and do nothing if there is no delta. Simplest ApproachWhen an event is received, set Performant AlternativeNode lookup by path is expensive. |
Description
When
diagnostics.enable = true
and a filetype-generic LSP (e.g.typos-lsp
) is running, one may see flickering of diagnostics in the nvim-tree buffer/window.On a more complex neovim setup than "Clean room replication" I also observed moderate to high CPU load.
A possible workaround for me was to add a check for
vim.bo[bufnr].buflisted
inview.lua:491:is_buf_valid
. I am new to this stuff and not sure if this would be a valid solution.Neovim version
Operating system and version
Linux 6.11.3
Windows variant
nvim-tree version
master
Clean room replication
Steps to reproduce
som.txt
Expected behavior
Diagnostic on
som.txt
shown in nvim-tree should just show ''typos:som
should besome
"Actual behavior
The diagnostic is shown but flickers every few ~100ms
The text was updated successfully, but these errors were encountered: