3 ways you can solve this issue.
Uninstalling rust-analyzer
from rustup ( rustup installs an unusable version of this package. see this reply )
mv ~/.cargo/bin/rust-analyzer ~/.backup/rust-analyzer`
or
On macOS Installing rust-analyzer
with homebrew
brew install rust-analyzer
or
In your ~/.config/nvim/lua/core/init.lua file replace line:61 with vim.env.PATH = vim.fn.stdpath "data" .. "/mason/bin" .. (is_windows and "; " or ":") .. vim.env.PATH
. This will add ~/.local/share/nvim/mason/bin/ at the beginning of your PATH. (from issue #1289 )
-- ~/.config/nvim/lua/core/init.lua
59 -- add binaries installed by mason.nvim to path
...
---> 61 vim.env.PATH = vim.env.PATH .. (is_windows and "; " or ":") .. vim.fn.stdpath "data" .. "/mason/bin"
+++> 61 vim.env.PATH = vim.fn.stdpath "data" .. "/mason/bin" .. (is_windows and "; " or ":") .. vim.env.PATH
Then add rust_analyzer
to lspconfig.lua.
( If using NvChad edit ~/.config/nvim/lua/custom/configs/lspconfig.lua to add
local servers=(... "rust_analyzer")
)
In work directory make sure project has a Cargo.toml file
cargo init
nvim main.rs
see this issue to know the problem, also see this reply