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

lua/lsp-status/messaging.lua:24: attempt to index a nil value #6

Closed lithammer closed 4 years ago

lithammer commented 4 years ago

I get this error when opening Rust file using rust-analyzer.

Error executing vim.schedule lua callback: .../opt/lsp-status.nvim/lua/lsp-status/messaging.lua:24: attempt to index a nil value

Did some print debugging, and I suspect that maybe goes wrong because of the global messages table in lua/lsp-status/messaging.lua and there's two messages in parallel (rustAnalyzer/cargoWatcher and rustAnalyzer/startup). But that's just a hunch.

client_id = 1
msg.token = rustAnalyzer/cargoWatcher
messages =  { {
    messages = {},
    name = "rust_analyzer",
    progress = {
      ["rustAnalyzer/startup"] = {
        message = "0/10 packages",
        percentage = 0,
        spinner = 1,
        title = "rust-analyzer"
      }
    },
    status = {}
  } }
Error executing vim.schedule lua callback: ...ackager/opt/lsp-status.nvim/lua/lsp-status/messaging.lua:24: attempt to index a nil value
client_id = 1
msg.token = rustAnalyzer/startup
messages =  { {
    messages = {},
    name = "rust_analyzer",
    progress = {
      ["rustAnalyzer/startup"] = {
        message = "9/10 packages",
        percentage = 90,
        spinner = 10,
        title = "rust-analyzer"
      }
    },
    status = {}
  } }
client_id = 1
msg.token = rustAnalyzer/cargoWatcher
messages =  { {
    messages = {},
    name = "rust_analyzer",
    progress = {
      ["rustAnalyzer/cargoWatcher"] = {
        spinner = 1,
        title = "Running `cargo check`"
      }
    },
    status = {}
  } }

As you can see in the first message msg.token is rustAnalyzer/cargoWatcher, but the progress table only contains rustAnalyzer/startup causing a lookup error on this line:

https://github.com/wbthomason/lsp-status.nvim/blob/d6ad84228c7a30dc6295afde110edb31bc331bdb/lua/lsp-status/messaging.lua#L24

wbthomason commented 4 years ago

Thanks for the report! I'll try to replicate the error.

wbthomason commented 4 years ago

Ah. So, this looks to be because rust-analyzer sends that rustAnalyzer/cargoWatcher message as an "end" kind without a corresponding "begin" first.

It looks like this might be a known rust-analyzer bug: https://github.com/rust-analyzer/rust-analyzer/issues/4384

However, I should still add code to check that we have info for a token before trying to update it.

lithammer commented 4 years ago

Thanks for the quick response and fix! 👍