nvim-lua / lsp-status.nvim

Utility functions for getting diagnostic status and progress messages from LSP servers, for use in the Neovim statusline
MIT License
625 stars 41 forks source link

CursorHold error/bad argument to util.lua #24

Closed garymh closed 3 years ago

garymh commented 3 years ago

Hi - I'm running into a weird error with re-sourcing my vimrc file. My config works great normally, but if I try to do a source $MYVIMRC again I'll get the following error with the cursor resting on a word:

Error detected while processing CursorHold Autocommands for "<buffer=1>":                                                                                                  
E5108: Error executing lua ...fig/nvim/plugged/lsp-status.nvim/lua/lsp-status/util.lua:5: bad argument #1 to 'ipairs' (table expected, got number)

This is with a recent build of neovim from a day or two ago, on macOS 11.0.1. Here is my lua relevant config (lsp.lua):

local lsp_status = require('lsp-status')
lsp_status.register_progress()

local lspconfig  = require('lspconfig')

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

lspconfig.vimls.setup({
    on_attach    = lsp_status.on_attach,
    capabilities = lsp_status.capabilities
  })

lsp_status.config({
    indicator_errors   = '',
    indicator_warnings = '',
    indicator_info     = '🛈',
    indicator_hint     = '❗',
    indicator_ok       = '',
    spinner_frames     = { '⣾', '⣽', '⣻', '⢿', '⡿', '⣟', '⣯', '⣷' },
    status_symbol      = '𝓵',
  })

(loaded in init.nvim with: luafile $DOTFILES/home/vim/lua/lsp.lua

Maybe the vim language server is returning something weird? 😕

(also: thank you for the great plugin!)

wbthomason commented 3 years ago

Hmm, interesting. That does seem to point to VimLS returning something strange - that line is iterating over the result passed to the callback for getting the current function.

However, I cannot reproduce the error on my end (with NVIM v0.5.0-865-gfb52790d1, built just now)... I assume your lsp-status version is latest, but could you please try rebuilding Neovim from master just to rule out a temporary breakage in the LSP functionality?

Also, what is your VimLS version? Mine seems to be 2.0.0.

garymh commented 3 years ago

Ah-ha! I went back to see what the issue was in my config since you couldn't reproduce it- I had the standard setup for the statusbar:

  function! LspStatus() abort
    if luaeval('#vim.lsp.buf_get_clients() > 0')
      return luaeval("require('lsp-status').status()")
    endif

    return ''
  endfunction

loading before the lua stuff. I guess being out of order and being sourced again caused it?

Either way, seems to be fixed for me 😄 Sorry for the confusion!

wbthomason commented 3 years ago

Ah, that would do it! Thanks for the info, and I'm glad things are working for you now!

joshuachp commented 3 years ago

I have the same issue with rust-analyze, could you please elaborate on how you solved it? I try putting the LspStatus function at the end of my configuration, but it didn't help.

Edit: Could this be an error with the server instead of the status line?

wbthomason commented 3 years ago

@joshuachp: Could you please check to see if https://github.com/nvim-lua/lsp-status.nvim/pull/25 fixes this issue for you? If rust-analyzer or other servers are potentially returning invalid values for the list of symbols, we should be checking for this before trying to process the current function.

joshuachp commented 3 years ago

Thank you very much, this fixed the CursorHold problem.

The rust-analyzer main thread still panics, but I'm not sure if it is related to lps-status. I have attached the log for the crash if you want to take a look. It happens after a file is saved and formatted with lsp.

``` [ ERROR ] 2020-11-25T19:29:44+0100 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:443 ] "rpc" "rust-analyzer" "stderr" "[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.9/examples/client.rs\n[ERROR rust_analyzer::reload] " [ ERROR ] 2020-11-25T19:29:44+0100 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:443 ] "rpc" "rust-analyzer" "stderr" "failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.9/examples/client_json.rs\n[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.9/examples/echo.rs\n[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.9/examples/gateway.rs\n[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.9/examples/hello.rs\n[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.9/examples/http_proxy.rs\n[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.9/examples/multi_server.rs\n[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.9/examples/params.rs\n[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.9/examples/send_file.rs\n[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.9/examples/service_struct_impl.rs\n[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.9/examples/single_threaded.rs\n[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.9/examples/state.rs\n[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.9/examples/tower_client.rs" [ ERROR ] 2020-11-25T19:29:44+0100 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:443 ] "rpc" "rust-analyzer" "stderr" "\n[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.9/examples/tower_server.rs\n[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.9/examples/upgrades.rs\n[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.9/examples/web_api.rs\n[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.9/tests/client.rs\n[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.9/tests/integration.rs\n[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.9/tests/server.rs\n[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.9/benches/body.rs\n[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.9/benches/connect.rs\n[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.9/benches/end_to_end.rs\n[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.9/benches/pipeline.rs\n[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.13.9/benches/server.rs\n" [ ERROR ] 2020-11-25T19:29:44+0100 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:443 ] "rpc" "rust-analyzer" "stderr" "[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.6.22/test/mod.rs\n" [ ERROR ] 2020-11-25T19:29:44+0100 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:443 ] "rpc" "rust-analyzer" "stderr" "[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/nom-6.0.0/examples/json.rs\n[ERROR rust_analyzer::reload] failed to load " [ ERROR ] 2020-11-25T19:29:44+0100 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:443 ] "rpc" "rust-analyzer" "stderr" "/home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/nom-6.0.0/examples/s_expression.rs\n[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/nom-6.0.0/examples/string.rs\n" [ ERROR ] 2020-11-25T19:29:44+0100 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:443 ] "rpc" "rust-analyzer" "stderr" "[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/nom-6.0.0/benches/arithmetic.rs\n" [ ERROR ] 2020-11-25T19:29:44+0100 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:443 ] "rpc" "rust-analyzer" "stderr" "[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/nom-6.0.0/benches/number.rs\n" [ ERROR ] 2020-11-25T19:29:44+0100 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:443 ] "rpc" "rust-analyzer" "stderr" "[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/nom-6.0.0/benches/http.rs\n[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/nom-6.0.0/benches/ini.rs\n[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/nom-6.0.0/benches/ini_complete.rs\n" [ ERROR ] 2020-11-25T19:29:44+0100 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:443 ] "rpc" "rust-analyzer" "stderr" "[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/nom-6.0.0/benches/ini_str.rs\n[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/nom-6.0.0/benches/json.rs\n" [ ERROR ] 2020-11-25T19:29:44+0100 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:443 ] "rpc" "rust-analyzer" "stderr" "[ERROR rust_analyzer::reload] failed to load /home/joshuachp/.cargo/registry/src/github.com-1ecc6299db9ec823/url-2.2.0/benches/parse_url.rs\n" [ ERROR ] 2020-11-25T19:30:01+0100 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:443 ] "rpc" "rust-analyzer" "stderr" "thread 'main' panicked at 'Invalid notification\nMethod: textDocument/didSave\n error: missing field `version`', /build/.cargo/registry/src/github.com-1ecc6299db9ec823/lsp-server-0.5.0/src/msg.rs:192:17\nstack backtrace:\nnote: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.\n" [ ERROR ] 2020-11-25T19:30:02+0100 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:443 ] "rpc" "rust-analyzer" "stderr" "thread '' panicked at 'called `Result::unwrap()` on an `Err` value: \"SendError(..)\"', /build/.cargo/registry/src/github.com-1ecc6299db9ec823/lsp-server-0.5.0/src/stdio.rs:29:37\nstack backtrace:\nnote: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.\n" [ WARN ] 2020-11-25T19:30:03+0100 ] /usr/share/nvim/runtime/lua/vim/lsp.lua:85 ] "method textDocument/documentSymbol is not supported by any of the servers registered for the current buffer" [ WARN ] 2020-11-25T19:30:04+0100 ] /usr/share/nvim/runtime/lua/vim/lsp.lua:85 ] "method textDocument/formatting is not supported by any of the servers registered for the current buffer" ```
wbthomason commented 3 years ago

Great, I'll merge that PR. From your trace, it seems as though the rust-analyzer panic does not have to do with lsp-status, though I'm not completely sure why the server is crashing (for instance, I cannot reproduce that panic on my system).

joshuachp commented 3 years ago

Probably some problems with being on nvim HEAD and Arch version of rust-analyzer, I'll wait to see if it will fix it self. Thank you for your work.

wbthomason commented 3 years ago

For what it's worth, I'm on the same versions of both, without this error. If you can figure out a minimal Rust source code example to reproduce the issue, I can try to reproduce on my end again.

joshuachp commented 3 years ago

For me is crashing even on a cargo init project, but after rebuilding rust-analyzer-git it's now fixed. So it was probably a server problem sorry for the trouble.