nvim-tree / nvim-tree.lua

A file explorer tree for neovim written in lua
Other
7.15k stars 608 forks source link

LSP diagnostics inside nvim-tree may flicker #2954

Open des-b opened 5 days ago

des-b commented 5 days ago

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 in view.lua:491:is_buf_valid. I am new to this stuff and not sure if this would be a valid solution.

Neovim version

NVIM v0.10.2
Build type: RelWithDebInfo
LuaJIT 2.1.1727870382

Operating system and version

Linux 6.11.3

Windows variant

-

nvim-tree version

master

Clean room replication

vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1

vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.cmd([[set packpath=/tmp/nvt-min/site]])
local package_root = "/tmp/nvt-min/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
    require("packer").startup({
        {
            "wbthomason/packer.nvim",
            "nvim-tree/nvim-tree.lua",
            "nvim-tree/nvim-web-devicons",
            -- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
        },
        config = {
            package_root = package_root,
            compile_path = install_path .. "/plugin/packer_compiled.lua",
            display = { non_interactive = true },
        },
    })
end
if vim.fn.isdirectory(install_path) == 0 then
    print("Installing nvim-tree and dependencies.")
    vim.fn.system({ "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path })
end
load_plugins()
require("packer").sync()
vim.cmd([[autocmd User PackerComplete ++once echo "Ready!" | lua setup()]])
vim.opt.termguicolors = true
vim.opt.cursorline = true

-- MODIFY NVIM-TREE SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
_G.setup = function()
    require("nvim-tree").setup({
        diagnostics = {
            enable = true,
        },
    })
    require("nvim-tree.api").tree.open()
end

-- UNCOMMENT this block for diagnostics issues, substituting pattern and cmd as appropriate.
-- Requires diagnostics.enable = true in setup.

vim.api.nvim_create_autocmd("FileType", {
    pattern = "*",
    callback = function()
                -- please adjust path to `typos-lsp`
        vim.lsp.start({ cmd = { "/home/des-b/.local/share/nvim/mason/bin/typos-lsp" } })
    end,
})

Steps to reproduce

  1. Put a file with an invalid name: som.txt
  2. Run neovim

Expected behavior

Diagnostic on som.txt shown in nvim-tree should just show ''typos: som should be some"

Actual behavior

The diagnostic is shown but flickers every few ~100ms

alex-courtis commented 4 days ago

I've seen a bit of flickering on and off for the diagnostic status with som, ede and others in files.

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
: ;
alex-courtis commented 4 days ago

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 typos-lsp in your $PATH

Please let me know if that works and I'll convert this to a discussion.

alex-courtis commented 4 days ago
alex-courtis commented 4 days ago

2956 nvt-min.lua fixed

Updated https://github.com/nvim-tree/nvim-tree.lua/wiki/Development

des-b commented 2 days ago

You are right. With the lspconfig config as you suggested there is no flickering.

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!