I am using NeoVim with NvChad default configs on a M1 mac. Trying to edit a .rs
file. Neovim lsp shows snippets but no error or autocompletion.
What I did
I have installed rust-analyzer
with Mason and configured
# ~/.config/nvim/lua/custom/configs/lspconfig.lua
local servers=(... "rust_analyzer")
That caused Error:
[lspconfig] unhandled error: ...ig/lua/lspconfig/server_configurations/rust_analyzer.lua:41: Expected value but found T_END at character 1`
The problem was empty string was being passed to line 41: vim.json.decode
that came from here
# ~/.local/share/nvim/lazy/nvim-lspconfig/lua/lspconfig/server_configurations/rust_analyzer.lua
18 local jobid = vim.fn.jobstart(cmd, {
19 │ on_stdout = function(_, data, _)
-->20 │ │ stdout[#stdout + 1] = table.concat(data, '\n')
21 │ end,
...
-->41 stdout = vim.json.decode(table.concat(stdout, ''))
42 return stdout and stdout['workspace_root'] or nil
Creating a Cargo.toml
solved the problem.
But Client 1 quit with exit code 1 and signal 0
was the new error. It means for some reason the rust-analyzer
crashed! The log
# ~/.local/state/nvim/lsp.log
[ERROR][2023-05-07 21:37:38] .../vim/lsp/rpc.lua:734 "rpc" "rust-analyzer" "stderr" "error: 'rust-analyzer' is not installed for the toolchain 'stable-aarch64-apple-darwin'"
I have installed it though with Mason
, but does not work. Not even with :!rust-analyzer
command. Error msg same as the log.
:!which rust-analyzer
command outputs ~/.cargo/bin/rust-analyzer
should be ~/.local/share/nvim/mason/bin/rust-analyzer
. So the package installed with Mason
is not recognised as it is later it the PATH. (see this issue)
Conclusion
Mason installs the correct packages of rust-analyzer for 'stable-aarch64-apple-darwin' toolchain.
If rustup version of rust-analyzer exists in ~/.cargo/bin/rust-analyzer it will be used. (this is the buggy package. issue)
rust-analyzer
does not work ifCargo.toml
is not at project root. (according to developers this is expected. see this reply)