sindrets / diffview.nvim

Single tabpage interface for easily cycling through diffs for all modified files for any git rev.
Other
3.85k stars 105 forks source link

LSP interaction error - 'semanticTokensProvider' #304

Closed jamestrew closed 1 year ago

jamestrew commented 1 year ago

Howdy :wave:

I've been getting this error message when using Diffview: LSP[lua_ls]: Error SERVER_REQUEST_HANDLER_ERROR: "...local/share/nvim/runtime/lua/vim/lsp/semantic_tokens.lua:253: attempt to index field 'semanticTokensProvider' (a nil value)" I've only started using Diffview over frequently and I know lsp semantic highlighting is fairly new feature on neovim nightly and so maybe this is more of a neovim core issue but I want to bring this to your attention.

This only occurs when you disable semantic highlighting in your lsp config - more details below. Reproduce-ability of this bug is a little finicky and feels like it's maybe a timing issue between when lsp loads vs when the Diffview buffers are opened. That said I've found a way to reliably reproduce this using a slightly "non-typical" workflow.

Here are the details:


Neovim version:

NVIM v0.9.0-dev-970+gf006313e9
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3

I've experienced this on older versions of 0.9 nightly as well.

System info

Linux archlinux 6.1.11-arch1-1

Minimal config

Settings up Diffview and lspconfig - using lua_ls as an example as it supports semantic tokens. Note the setting of semanticTokensProvider = nil in the on_attach function. I believe this is the recommended way to disable semantic tokens. Commenting this line out resolves this issue.

```lua -- DO NOT change the paths and don't remove the colorscheme local root = vim.fn.fnamemodify("./.repro", ":p") -- set stdpaths to use .repro for _, name in ipairs({ "config", "data", "state", "cache" }) do vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name end -- bootstrap lazy local lazypath = root .. "/plugins/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", lazypath, }) end vim.opt.runtimepath:prepend(lazypath) -- install plugins local plugins = { { "sindrets/diffview.nvim", dependencies = "nvim-lua/plenary.nvim", opts = { use_icons = false }, }, { "neovim/nvim-lspconfig", config = function() require("lspconfig").lua_ls.setup({ settings = { Lua = { runtime = { -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) version = "LuaJIT", }, diagnostics = { -- Get the language server to recognize the `vim` global globals = { "vim" }, }, workspace = { -- Make the server aware of Neovim runtime files library = vim.api.nvim_get_runtime_file("", true), checkThirdParty = false, }, -- Do not send telemetry data containing a randomized but unique identifier telemetry = { enable = false, }, }, }, on_attach = function(client, bufnr) client.server_capabilities.semanticTokensProvider = nil end, }) end, }, -- add any other plugins here } require("lazy").setup(plugins, { root = root .. "/plugins", }) vim.cmd.colorscheme("habamax") ```

Steps to reproduce

  1. mkdir -p /tmp/testing
  2. cd /tmp/testing
  3. git init
  4. touch min.lua and paste in the minimal config from above
  5. launch nvim with nvim -nu min.lua and confirm minimal config is working (including the lua lsp)
  6. relaunch with nvim -nu min.lua "+DiffviewOpen"
  7. observer 'semanticTokensProvider' error from above

Expected behavior

observer no lsp errors


Let me know if you would like any additional details. I'm curious if other have experienced this as well.

sindrets commented 1 year ago

Looking at the error message and your description of the error, I highly doubt your issue has anything to do with this plugin. Seems like either the runtime module in core is neglecting to do a nil check, or the server capabilities is not following the spec. I would open an issue upstream.

jamestrew commented 1 year ago

Got it thanks. I'll report this upstream.