Nvim-lspconfig: [rust_analyzer] initalizationOptions causing ra_lsp_server an error

Created on 15 Jan 2020  路  24Comments  路  Source: neovim/nvim-lspconfig

Because of how vim json_encode transform vim data into JSON data, the lua value {} which is the default value for init_options is being encoded into an empty JSON array.
But ra_lsp_server expect to receive a JSON map for decoding the init options and emit an error: failed to deserialize config: invalid length 0, expected struct ServerConfig with 12 elements when receiving an empty initializationOptions by vim.lsp.
Hopefully rust-analyzer handle this error by just logging it and sticking with default values, but still the error message appears, which can be actually confusing.

bug good first issue help wanted

Most helpful comment

Issue has been resolved. Thank you!

All 24 comments

lua value {} which is the default value for init_options is being encoded into an empty JSON array.

This can be fixed by setting it to vim.empty_dict(). Just need someone to send a PR doing that.

Or should we always default to that (for all configs, not just rust-analyzer)?

I think default to that would be good, as the LSP spec says initOptions has to be a dictionary anyway, so even if implementations actually mainly don't mind about this, defaulting to what the spec says seems to be the correct way of handling this imho

Changing in lua/nvim_lsp/skeleton.lua
init_options = {}; to
init_options = vim.empty_dict();
did not solve the issue.
I directly changed the git folder in plugged and used
lua require'nvim_lsp'.rust_analyzer.setup{} in init.vim.

call nvim_lsp#setup("rust_analyzer", {}) returns unknown function, so it should be removed from the docs.
What am I missing here?

@matu3ba Did you get it to work? If yes, I would very much appreciate a full example of how to do it.

Sorry, somehow it works. I was very confused by the message, but the message shortly thereafter disappears.

With the described 1-line PR added, it works.

call nvim_lsp#setup("rust_analyzer", {}) returns unknown function, so it should be removed from the docs.

@matu3ba where are you seeing that? It was removed from all docs that I know of, weeks ago.

@justinmk you are correct.

Can someone please double check? I still have this issue.

@tuxsoy always need to know exact version of Nvim and this plugin. Ensure that you have https://github.com/neovim/nvim-lsp/commit/b4f4b72a50983464864810e642e0b70e0b987e6f and then post exact error message.

@justinmk I'm using the appimage release of neovim (NVIM v0.5.0-363-g31614d3eb) with nvim-lsp commit 42385db. The error message is:

LSP[rust_analyzer] failed to deserialize config: invalid length 0, expected struct ServerConfig with 12 elements

Reverting to commit b4f4b72 does not solve the issue either.

Commenting the following lines fixes the issue for me, so the problem is probably on these lines:
https://github.com/neovim/nvim-lsp/blob/42385dbf6a5eac40da213322fdd3037588eede56/lua/nvim_lsp/configs.lua#L102-L103

OK, I'll check it later.

@KokaKiwi @matu3ba @tuxsoy
Would you try this branch?

@KokaKiwi @matu3ba @tuxsoy
Would you try this branch?

This removes the error message and shows "LSP[rust_analyzer][Info] workspace loaded, 12 rust packages".
Did try on the old and current nightly neovim appimage.

I think neovim/neovim#11864 will solve this.

I manually patched the last nightly (v0.5.0-372-g68de6b17b) with the 5 lines (here) and it didn't fix the error. Also tried it in combination with pull 121 with no success.

@halzy
It works fine in my environment.
Would you show me this command result?

:lua print(vim.inspect(vim.deepcopy(vim.empty_dict())))

This is the result:
E5105: Error while calling lua chunk: [string "<VimL compiled string>"]:1: attempt to call field 'empty_dict' (a nil value)

I had modified the file that were unzip'd with neovim's nightly (osx) and had used Plug to install (git fetch) the nvim-lsp directory, to which I added the other repo as a remote and checked the branch out that the pull request was for.

Ah, shoot. I was in the wrong neovim for that command you mentioned.

The actual result: {}

I've also verified the branch setup and other changes. Let me know if there is something else I can test.
LSP[rust_analyzer] Failed to deserialize config: invalid length 0, expected struct ServerConfig with 12 elements; []

@halzy

Ah, shoot. I was in the wrong neovim for that command you mentioned.

The actual result: {}

That result is not expected.
Expected behavior is vim.empty_dict().
You may have something wrong build.

Versions:
NeoVIM: NVIM v0.5.0-374-gd9657b3ae
nvim-lsp: :Plug 'h-michael/nvim-lsp', { 'branch': 'ra-server' }

With the nvim-osx files expanded in my home dir patched with:
https://github.com/neovim/neovim/pull/11864/files#diff-7f472431a1463bbeec031cd66114173e

All other NeoVim install have been removed from my system.
:lua print(vim.inspect(vim.deepcopy(vim.empty_dict())))
still reports: {}

@h-michael Am I missing a step? is there a cache of the original ~/nvim-osx64/share/nvim/runtime/lua/vim/shared.lua file somewhere?

I just ran a git bisect on the issue. 3062676b5c846174996bfd7ee746b3e5b7176d5b is the commit that introduced the error.

This got closed by automatic github action. If issues persist we can reopen it.

@halzy Try nightly Neovim. My fixes are included.

Issue has been resolved. Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

K1DV5 picture K1DV5  路  10Comments

ahmedelgabri picture ahmedelgabri  路  4Comments

nhooyr picture nhooyr  路  3Comments

glacambre picture glacambre  路  5Comments

nomasprime picture nomasprime  路  5Comments