0

I'm trying to get rust-analyzer working in Neovim, but with no luck so far.

I've downloaded the rust-analyzer binary (rust-analyzer-x86_64-pc-windows-msvc.gz) from the rust-analyzer releases page and put it in my PATH (specifically in %USERPROFILE%\.rustup\toolchains\rust-analyzer-x86_64-pc-windows-msvc).

I have the language server enabled in my init.lua but when I open a source file in a rust project and enter :LspInfo I get the following:

 Config: rust_analyzer
    filetypes:         rust
    root directory:    C:\Users\[my user name]\source\repos\rust\loops
    cmd:               rust-analyzer
    cmd is executable: Unable to find executable. Please check your path and ensure the server is installed
    autostart:         true
    custom handlers:   

My init.lua for lsp config looks like this:

local servers = { 'gopls', 'lemminx', 'rust_analyzer' }
for _, lsp in ipairs(servers) do
    nvim_lsp[lsp].setup {
        on_attach = on_attach,
        capabilities = capabilities,
    }
end

gopls is working all fine, so I think that config is correct. But rust-analyzer just doesn't seem to work.

I've also tried installing rust-analyzer in VSCode in case neovim can use that one, but that didn't appear to work either.

I'm using v0.5.0 of neovim.

I read on some webpage that I've now lost that the rust-analyzer MSVC needs to be registered but I can't find any info on how to register an MSVC.

For comparison, this is what :LspInfo shows when I have a Go source file open and the gopls LSP is attached:

 Client: gopls (id: 1, pid: 59572, bufnr: [1])
    filetypes:       go, gomod
    autostart:       true
    root directory:  C:\Users\[my user name]\source\repos\go\k6-extensions\xk6-wsrte
    cmd:             gopls
4
  • 1
    Can you run the command rust-analyzer, or is the command rust-analyzer-x86_64-pc-windows-msvc? It's not clear from your description of the paths involved
    – D. Ben Knoble
    Commented Nov 8, 2021 at 15:33
  • 1
    @D.BenKnoble that's a very good question and I don't know the answer. What's baffling me is that the init.lua says rust_analyzer but the error message says rust-analyzer. I don't know where the cmd value is coming from. Running rust-analyzer or rust_analyzer from command line just gets the "is not recognized as a name of a cmdlet etc" response. Same for trying rust-analyzer-x86_64-pc-windows-msvc. Commented Nov 8, 2021 at 16:19
  • Ah, I finally stumbled across what I was doing wrong! I'll self-answer. Commented Nov 8, 2021 at 17:09
  • @D.BenKnoble I also discovered that in the nvim-lspconfig folders there's a rust_analyzer.lua file that defines the cmd - which is 'rust-analyzer'. This has been most educational! Commented Nov 8, 2021 at 17:34

1 Answer 1

2

I had missed the section of the documentation that says:

Other editors generally require the rust-analyzer binary to be in $PATH. You can download pre-built binaries from the releases page. You will need to uncompress and rename the binary for your platform, e.g. from rust-analyzer-aarch64-apple-darwin.gz on Mac OS to rust-analyzer, make it executable, then move it into a directory in your $PATH.

Once I have renamed the rust-analyzer-x86_64-pc-windows-msvc file to rust-analyzer.exe when I opened a rust source file in nvim I got this from :LspInfo:

 Client: rust_analyzer (id: 1, pid: 57880, bufnr: [1])
    filetypes:       rust
    autostart:       true
    root directory:  C:\Users\[my user name]\source\repos\rust\loops
    cmd:             rust-analyzer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.