nvim-tree / nvim-tree.lua

A file explorer tree for neovim written in lua
Other
6.8k stars 604 forks source link

nvim-tree not respecting diagnostics update_in_insert value set by neovim #2745

Open shreyas-a-s opened 3 months ago

shreyas-a-s commented 3 months ago

Description

By default neovim sets diagnostics update_in_insert = false and other plugins (for example lualine) respects it. But somehow, nvim-tree doesn't.

Neovim version

NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1710088188

Operating system and version

Debian 12 Stable (Linux 6.1.0-18-amd64)

Windows variant

No response

nvim-tree version

707b24a

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,
    },
  }
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 = "lua",
  callback = function()
    vim.lsp.start { cmd = { "lua-language-server" } }
  end,
})

Steps to reproduce

  1. Make sure lua-language-server is in $PATH.
  2. Copy the above clean room replication into nvt-min.lua.
  3. Launch neovim using nvim -nu nvt-min.lua.
  4. Open nvim-tree using :NvimTreeToggle.
  5. Open nvt-min.lua or any other lua file while keeping nvim-tree open.
  6. Go to insert mode.
  7. Create a diagnostic event (error, warning, etc.) by deleting some characters while in insert mode.
  8. See that nvim-tree is updated (showing diagnostic icons) while in insert mode even though the default for neovim is update_in_insert = false.

Expected behavior

Nvim-tree respects the value of update_in_insert set by neovim.

Actual behavior

https://github.com/nvim-tree/nvim-tree.lua/assets/137637016/142b382d-c6b1-4669-9452-4575dcd780d4

As you can see, when I am creating an error in insert mode, lualine don't update the status but nvim-tree does.

I have checked the docs, issues and discussions and couldn't find anything related to it.

alex-courtis commented 3 months ago

I don't think I'm fully understanding. What is update_in_insert? It doesn't seem to be an nvim or lsp setting.

It appears to be a lualine specific setting: https://github.com/nvim-lualine/lualine.nvim?tab=readme-ov-file#diagnostics-component-options

Is it known by another name?

gegoune commented 3 months ago

@alex-courtis

it's part of configuration options for vim.diagnostic.config(), see :h vim.diagnostic.Opts.

alex-courtis commented 3 months ago

@alex-courtis

it's part of configuration options for vim.diagnostic.config(), see :h vim.diagnostic.Opts.

Ah... new in 0.10.

This featurecan be added, although it will have to be behind a 0.10 feature flag.

I'm a little wary of 0.10; there have been a few breaking breaking changes recently.

shreyas-a-s commented 3 months ago

First of all, thanks for the insights. It made me recheck the things and I was wrong. When it comes to lualine yes it indeed is a separate option. But when it comes to neovim an option does exist but I think lualine uses its own value for implementing it.

This is the option in neovim:

vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
  vim.lsp.diagnostic.on_publish_diagnostics, {
    update_in_insert = false, 
  }
)

And the thing is, I use neovim 0.9.5 and it works as intended when it comes to neovim buffers. See this video:

https://github.com/nvim-tree/nvim-tree.lua/assets/137637016/9d1627d6-e28f-4212-8503-a0212bf3401a

At first I set the update_in_insert to false and see that neovim respects it and doesn't show the diagnostic virtual_text while in insert mode. Then when I set it to true neovim respects that and shows diagnostic virtual_text even when in insert mode.

Similarly, when it comes to lualine as you have found out, it also have such an option.

What I am hoping is the addition of an option like the one below that kind of brings the feature to nvim-tree:

require("nvim-tree").setup({
  diagnostics = {
    update_in_insert = false, -- ability to set something like this
  },
})
alex-courtis commented 2 months ago

That's quite nice. We do seem to have two different mechanisms to achieve this: vim.diagnostic.config() (0.10) and the above LSP setting.

Can we implement one mechanism to handle both?

shreyas-a-s commented 2 months ago

I am not really well versed with the programming implications of adding this feature hence it would be better if you could choose one mechanism that you feel is the best choice to handle both.

alex-courtis commented 2 months ago

Let's build for nvim 0.10 and see if it works for 0.9

We can decide whether to build a 0.9 specific implementation based on the above.

shreyas-a-s commented 2 months ago

I agree. Since neovim 0.10 is the upcoming release, initial focus should be on it.