1

I am new to Neovim. I have install neovim v0.9 and copied lua configuration from kickstart.nvim. I have followed all the instructions as per TJ's youtube video too. Everything is working perfectly fine. Lsp is working for ts and lua. But Lsp recognizes rust file (:LspInfo shows that it has recognized rust file) yet autocomplete stuff isn't happening for rust.

I have tried all the configurations mentioned in mason repo. I do not know why it is not working.

James Z
  • 12,209
  • 10
  • 24
  • 44
ajihsan
  • 11
  • 2

3 Answers3

2

3 ways you can solve this issue.

  1. 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

  1. On macOS Installing rust-analyzer with homebrew

     brew install rust-analyzer
    

or

  1. 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

0

If the LSP is being recognised, but not loaded, that usually indicates that the binary could not be executed for some reason. Possible reasons include:

  1. The binary is not on the PATH (exact instruction will depend on the operating system)
  2. The binary was not executable (wonky permissions, or an invalid binary)
  3. The binary aborted for some reason (check :LspLog for details)
amycodes
  • 902
  • 14
0

Add mason/bin at the start of path in shell config file

# ~/.bashrc
export PATH="$HOME/.local/share/nvim/mason/bin/:$PATH"