rust-analyzer: Stuck at 'rust_analyzer: -32801: waiting for cargo metadata or cargo check'

I’m opening a project directory and rust-analyzer seems to be stuck at loading. I checked if perhaps was a project issue but the error persists in both big (5+ dependencies) and small projects (using 1 dependency). I’m using neovim v0.7.0-dev in Ubuntu. Any suggestion of how to solve this issue? Thanks in advance.

rust-analyzer version: (eg. output of “Rust Analyzer: Show RA Version” command) rust-analyzer d9b2291f5 2021-11-29 stable

rustc version: (eg. output of rustc -V) rustc 1.56.1 (59eed8a2a 2021-11-01)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 17
  • Comments: 44 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Having this issue as well, on Emacs with lsp-mode and rustic.

Not sure if this is the same error: image

I think Rust-Analyzer takes some time to load. After that, it seems to be working normally. Though the red status line is quite annoying from time to time.

My setup: neovim + nvim-lsp + rust-analyzer on MacOS.

raerr

Having the same problem.

Same error happened in:

  • Windows11 Home 21H2
  • GNU Emacs 28.1 (build 52, x86_64-w64-mingw32) of 2022-04-05
  • lsp-mode 20220918.1522
  • rust-analyzer 0.3.1212-standalone (187bee0bb 2022-09-19)
  • Rust 1.63.0

Got messages:

LSP :: Connected to [rust-analyzer:29100/starting].
LSP :: rust-analyzer:29100 initialized successfully in folders: (c:/path/to/project)
LSP :: Error from the Language Server: waiting for cargo metadata or cargo check (Unknown error) [3 times]
vim-lsp Log

Note: a lot of duplicate requests have been omitted here

Sun 10 Apr 2022 14:22:40 BST:["lsp#register_server","server registered","rust-analyzer"]
Sun 10 Apr 2022 14:22:40 BST:["s:on_text_document_did_open()",1,"rust","/home/frank/fun/euler/035_circular_primes","file:///home/frank/fun/euler/035_circular_primes/src/main.rs"]

Sun 10 Apr 2022 14:22:40 BST:["Starting server","rust-analyzer",["rust-analyzer"]]
Sun 10 Apr 2022 14:22:40 BST:[{"response":{"data":{"__data__":"vim-lsp","lsp_id":1,"server_name":"rust-analyzer"},"message":"started lsp server successfully"}}]
Sun 10 Apr 2022 14:22:40 BST:[{"response":{"error":{"data":{"lsp_id":1,"__error__":"vim-lsp","server_name":"rust-analyzer"},"code":0,"message":"ignore initialization lsp server due to empty root_uri"}}}]
Sun 10 Apr 2022 14:22:40 BST:["--->",1,"rust-analyzer",{"method":"initialize",...
Sun 10 Apr 2022 14:22:40 BST:["<---",1,"rust-analyzer",{"response":{...,"request":{"id":1,"jsonrpc":"2.0","method":"initialize",...
Sun 10 Apr 2022 14:22:40 BST:["--->",1,"rust-analyzer",{"method":"initialized","params":{}}]
Sun 10 Apr 2022 14:22:40 BST:["--->",1,"rust-analyzer",{"method":"textDocument/didOpen",...
Sun 10 Apr 2022 14:22:40 BST:["--->",1,"rust-analyzer",{"method":"textDocument/foldingRange","on_notification":"---funcref---","bufnr":1,"params":{"textDocument":{"uri":"file:///home/frank/fun/euler/035_circular_primes/src/main.rs"}},"sync":0}]
Sun 10 Apr 2022 14:22:40 BST:["<---",1,"rust-analyzer",{"response":{"id":2,"jsonrpc":"2.0","error":{"code":-32801,"message":"waiting for cargo metadata or cargo check"}},"request":{"id":2,"jsonrpc":"2.0","method":"textDocument/foldingRange","params":{"textDocument":{"uri":"file:///home/frank/fun/euler/035_circular_primes/src/main.rs"}}}}]
Sun 10 Apr 2022 14:22:41 BST:["--->",1,"rust-analyzer",{"method":"textDocument/documentHighlight","on_notification":"---funcref---","params":{"textDocument":{"uri":"file:///home/frank/fun/euler/035_circular_primes/src/main.rs"},"position":{"character":0,"line":0}}}]
Sun 10 Apr 2022 14:22:41 BST:["<---",1,"rust-analyzer",{"response":{"id":4,"jsonrpc":"2.0","error":{"code":-32801,"message":"waiting for cargo metadata or cargo check"}},"request":{"id":4,"jsonrpc":"2.0","method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///home/frank/fun/euler/035_circular_primes/src/main.rs"},"position":{"character":0,"line":0}}}}]
Sun 10 Apr 2022 14:22:41 BST:["--->",1,"rust-analyzer",{"method":"textDocument/codeAction","on_notification":"---funcref---","params":{"context":{"diagnostics":[],"only":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite"]},"range":{"end":{"character":57,"line":0},"start":{"character":0,"line":0}},"textDocument":{"uri":"file:///home/frank/fun/euler/035_circular_primes/src/main.rs"}}}]
Sun 10 Apr 2022 14:22:41 BST:["<---",1,"rust-analyzer",{"response":{"id":5,"jsonrpc":"2.0","error":{"code":-32801,"message":"waiting for cargo metadata or cargo check"}},"request":{"id":5,"jsonrpc":"2.0","method":"textDocument/codeAction","params":{"context":{"diagnostics":[],"only":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite"]},"range":{"end":{"character":57,"line":0},"start":{"character":0,"line":0}},"textDocument":{"uri":"file:///home/frank/fun/euler/035_circular_primes/src/main.rs"}}}}]
⋮
Sun 10 A
Sun 10 Apr 2022 14:22:45 BST:["--->",1,"rust-analyzer",{"method":"textDocument/codeAction","on_notification":"---funcref---","params":{"context":{"diagnostics":[],"only":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite"]},"range":{"end":{"character":1,"line":57},"start":{"character":0,"line":57}},"textDocument":{"uri":"file:///home/frank/fun/euler/035_circular_primes/src/main.rs"}}}]
Sun 10 Apr 2022 14:22:47 BST:["<---",1,"rust-analyzer",{"response":{"id":6,"jsonrpc":"2.0","result":null},"request":{"id":6,"jsonrpc":"2.0","method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///home/frank/fun/euler/035_circular_primes/src/main.rs"},"position":{"character":0,"line":57}}}}]
Sun 10 Apr 2022 14:22:49 BST:["s:on_text_document_did_close()",1]

It seems as though this error is caused by the client making requests shortly after startup, before cargo metadata and/or cargo check have completed. If these commands must complete in order for the server to handle any requests, should rust-analyzer perhaps withold its response to the client’s initialized request until these commands have completed? At the moment, the initialized response is sent here while the commands are both dispatched here.

Switching to pre-release version worked for me

I get the same error when i open project with nvim, this is my configuration. Looks like rust-analyzer problem.

Uuh, running that command shouldn’t fix the problem for you 😅 I was more interested in seeing whether running cargo check manually would also fail for you or not. This seems rather odd since all that r-a usually does is running cargo metadata and cargo check.

Does running cargo check --workspace --message-format=json --manifest-path {path to your projects cargo toml} --all-targets manually in your project work fine?

Though I guess it gets stuck at calling cargo metadata

@hydra let’s continue in #14146.

I get this in eclipse corrosion on a ‘hello-world’ rust example, attached.

Screenshot: image

Eclipse workspace: eclipse-workspace-4.24-rust-analyzer-10910.zip

Project: hello-world.zip

  C/C++ Autotools support	10.7.1.202208160035	org.eclipse.cdt.autotools.feature.group	Eclipse CDT
  C/C++ CMake Build Support - Preview	10.7.1.202208160035	org.eclipse.cdt.cmake.feature.group	Eclipse CDT
  C/C++ Debug Adapter GDB Debugger Integration	10.7.1.202208160035	org.eclipse.cdt.debug.dap.feature.group	Eclipse CDT
  C/C++ Debug Adapter GDB Hardware Debugger Integration	10.7.1.202208160035	org.eclipse.cdt.debug.dap.gdbjtag.feature.group	Eclipse CDT
  C/C++ Development Tools	10.7.1.202208222120	org.eclipse.cdt.feature.group	Eclipse CDT
  C/C++ Docker Container Launch Support	10.7.1.202208160035	org.eclipse.cdt.docker.launcher.feature.group	Eclipse CDT
  C/C++ GCC Cross Compiler Support	10.7.1.202208160035	org.eclipse.cdt.build.crossgcc.feature.group	Eclipse CDT
  C/C++ GDB Hardware Debugging	10.7.1.202208160035	org.eclipse.cdt.debug.gdbjtag.feature.group	Eclipse CDT
  C/C++ Launch over Serial	10.7.1.202208160035	org.eclipse.cdt.launch.serial.feature.feature.group	Eclipse CDT
  C/C++ Library API Documentation Hover Help	8.7.0.202206072042	org.eclipse.linuxtools.cdt.libhover.feature.feature.group	Eclipse Linux Tools
  C/C++ Memory View Enhancements	10.7.1.202208160035	org.eclipse.cdt.debug.ui.memory.feature.group	Eclipse CDT
  C/C++ Meson Build Support - Preview	10.7.1.202208160035	org.eclipse.cdt.meson.feature.group	Eclipse CDT
  C/C++ Remote Launch	10.7.1.202208160035	org.eclipse.cdt.launch.remote.feature.group	Eclipse CDT
  C/C++ Standalone Debugger	10.7.1.202208160035	org.eclipse.cdt.debug.standalone.feature.group	Eclipse CDT
  C/C++ Test runner client for UnitTest View	10.7.1.202208160035	org.eclipse.cdt.unittest.feature.feature.group	Eclipse CDT
  C/C++ Unit Testing Support	10.7.1.202208160035	org.eclipse.cdt.testsrunner.feature.feature.group	Eclipse CDT
  ChangeLog Management Tools for C/C++	8.7.0.202206072042	org.eclipse.linuxtools.changelog.c.feature.group	Eclipse Linux Tools
  Corrosion: Rust edition in Eclipse IDE	1.2.4.202206282034	org.eclipse.corrosion.feature.feature.group	Eclipse Corrosion
  Eclipse IDE for Embedded C/C++ Developers	4.24.0.20220609-1200	epp.package.embedcpp	Eclipse Packaging Project
  Eclipse Java Development Tools	3.18.1200.v20220607-0700	org.eclipse.jdt.feature.group	Eclipse.org
  Eclipse Java EE Developer Tools	3.26.0.v202204042240	org.eclipse.jst.enterprise_ui.feature.feature.group	Eclipse Web Tools Platform
  Eclipse Web Developer Tools	3.26.0.v202204091445	org.eclipse.wst.web_ui.feature.feature.group	Eclipse Web Tools Platform
  Eclipse XML Editors and Tools	3.26.0.v202204091445	org.eclipse.wst.xml_ui.feature.feature.group	Eclipse Web Tools Platform
  Embedded C/C++ ADuCM360 Project Template	6.3.0.202208180721	org.eclipse.embedcdt.templates.ad.feature.group	Eclipse Embedded CDT
  Embedded C/C++ Arm Cross Compiler	6.3.0.202208180721	org.eclipse.embedcdt.managedbuild.cross.arm.feature.group	Eclipse Embedded CDT
  Embedded C/C++ CMSIS Packs (Experimental)	6.3.0.202208180721	org.eclipse.embedcdt.packs.feature.group	Eclipse Embedded CDT
  Embedded C/C++ CodeRed Debug Perspective	6.3.0.202208180721	org.eclipse.embedcdt.codered.feature.group	Eclipse Embedded CDT
  Embedded C/C++ Core	6.3.0.202208180721	org.eclipse.embedcdt.feature.group	Eclipse Embedded CDT
  Embedded C/C++ Documentation (Placeholder)	6.3.0.202208180721	org.eclipse.embedcdt.doc.user.feature.group	Eclipse Embedded CDT
  Embedded C/C++ Freescale Project Templates	6.3.0.202208180721	org.eclipse.embedcdt.templates.freescale.feature.group	Eclipse Embedded CDT
  Embedded C/C++ GDB JTAG Debugging	6.3.0.202208180721	org.eclipse.embedcdt.debug.gdbjtag.feature.group	Eclipse Embedded CDT
  Embedded C/C++ Generic Arm Cortex-M Project Template	6.3.0.202208180721	org.eclipse.embedcdt.templates.cortexm.feature.group	Eclipse Embedded CDT
  Embedded C/C++ J-Link Debugging	6.3.0.202208180721	org.eclipse.embedcdt.debug.gdbjtag.jlink.feature.group	Eclipse Embedded CDT
  Embedded C/C++ OpenOCD Debugging	6.3.0.202208180721	org.eclipse.embedcdt.debug.gdbjtag.openocd.feature.group	Eclipse Embedded CDT
  Embedded C/C++ PyOCD Debugging	6.3.0.202208180721	org.eclipse.embedcdt.debug.gdbjtag.pyocd.feature.group	Eclipse Embedded CDT
  Embedded C/C++ QEMU Debugging	6.3.0.202208180721	org.eclipse.embedcdt.debug.gdbjtag.qemu.feature.group	Eclipse Embedded CDT
  Embedded C/C++ RISC-V Cross Compiler	6.3.0.202208180721	org.eclipse.embedcdt.managedbuild.cross.riscv.feature.group	Eclipse Embedded CDT
  Embedded C/C++ SiFive RISC-V Project Template	6.3.0.202208180721	org.eclipse.embedcdt.templates.sifive.feature.group	Eclipse Embedded CDT
  Embedded C/C++ STM32Fx Project Templates	6.3.0.202208180721	org.eclipse.embedcdt.templates.stm.feature.group	Eclipse Embedded CDT
  GCov Integration	8.7.0.202206072042	org.eclipse.linuxtools.gcov.feature.group	Eclipse Linux Tools
  GDB Tracepoint Analysis	8.0.0.202206082347	org.eclipse.tracecompass.gdbtrace.feature.group	Eclipse Trace Compass
  Git integration for Eclipse	6.2.0.202206071550-r	org.eclipse.egit.feature.group	Eclipse EGit
  GProf Integration	8.7.0.202206072042	org.eclipse.linuxtools.gprof.feature.feature.group	Eclipse Linux Tools
  Java implementation of Git	6.2.0.202206071550-r	org.eclipse.jgit.feature.group	Eclipse JGit
  JavaScript Development Tools	2.4.200.v202204112136	org.eclipse.wst.jsdt.feature.feature.group	Eclipse Web Tools Platform
  JUnit Test runner client for UnitTest View	1.0.200.v20220204-2234	org.eclipse.jdt.ui.unittest.junit.feature.feature.group	Eclipse.org
  JustJ Adoptium OpenJDK Hotspot JRE Complete	18.0.1.v20220515-1614	org.eclipse.justj.openjdk.hotspot.jre.full.feature.group	Eclipse JustJ
  LaunchBar	10.7.1.202208160035	org.eclipse.launchbar.feature.group	Eclipse CDT
  Library Hover help for devhelp documentation	8.7.0.202206072042	org.eclipse.linuxtools.cdt.libhover.devhelp.feature.feature.group	Eclipse Linux Tools
  LTTng Kernel Analysis	8.0.0.202206082347	org.eclipse.tracecompass.lttng2.kernel.feature.group	Eclipse Trace Compass
  LTTng Tracer Control	8.0.0.202206082347	org.eclipse.tracecompass.lttng2.control.feature.group	Eclipse Trace Compass
  LTTng Userspace Analysis	8.0.0.202206082347	org.eclipse.tracecompass.lttng2.ust.feature.group	Eclipse Trace Compass
  Marketplace Client	1.10.0.v20220502-0731	org.eclipse.epp.mpc.feature.group	Eclipse Marketplace Client
  Mylyn WikiText	3.0.42.202201072301	org.eclipse.mylyn.wikitext_feature.feature.group	Eclipse Mylyn
  Oomph Setup	1.25.0.v20220607-1104	org.eclipse.oomph.setup.feature.group	Eclipse Oomph Project
  Remote Launch Targets	10.7.1.202208160035	org.eclipse.launchbar.remote.feature.group	Eclipse CDT
  RPM Tools	8.7.0.202206072042	org.eclipse.linuxtools.rpm.feature.group	Eclipse Linux Tools
  ShellWax	1.2.0.20220712-1356	org.eclipse.shellwax.feature.feature.group	null
  TM Terminal	10.7.1.202208160035	org.eclipse.tm.terminal.feature.feature.group	Eclipse CDT
  TM Terminal Serial Connector Extensions	10.7.1.202208160035	org.eclipse.tm.terminal.connector.cdtserial.feature.feature.group	Eclipse CDT
  Valgrind Tools Integration	8.7.0.202206072042	org.eclipse.linuxtools.valgrind.feature.group	Eclipse Linux Tools
rustc --version
rustc 1.64.0-nightly (1c7b36d4d 2022-07-12)

rustup --version
rustup 1.25.1 (bb60b1e89 2022-07-12)

However, when i tried to get the version of the rust-analyzer to submit this comment I found that when i used the ‘Download rust analyzer’ button on the ‘Eclipse / Preferences / Rust’ window it downloaded rust-analyzer-x86_64-pc-windows-msvc.gz, to D:\Users\Hydra\.local\bin and extracted it in place so that I have: D:\Users\Hydra\.local\bin\rust-analyzer, but if you try and run that from a command prompt you get this:

image

Which is correct, because cmd.exe only runs commands that end in certain extensions, e.g. .exe. So I did this:

ren .local\bin\rust-analyzer rust-analyzer.exe

image

rust-analyzer 0.3.1148-standalone (2b472f668 2022-07-31)

Then I restarted Eclipse and it immediately complained about my rust config being incorrect, which because it was pointing at rust-analyzer not rust-analyzer.exe.

So I changed it, as below:

image

And now the waiting for cargo is gone and the outline view works correctly, as below:

image

My issue is likely a bug in Eclipse Corrosion, as it should download and extract files that have the correct file extensions for the operating system being used. I’ll try and find an issue on an appropriate repository and link to this comment.

EDIT: actually there is probably also a rust-analyzer distribution/artifacts/packaging issue, but I’m not sure who was responsible for creating the file that eclipse corrosion downloaded. Does anyone know if rust-analyzer-x86_64-pc-windows-msvc.gz is supposed to contain rust-analyzer.exe or rust-analyzer ? The latter is certainly an issue, as demonstrated above, for windows users.

Hope this helps someone, if it did, please ‘like/thumbs-up’ this comment so I know I’m not wasting my time writing up this solution.

Same problem.

Finally: I switch to the pre-release version and restart the VS Code. The problem seems disappear.

image

@khjcph @tranvnhan hey it’s the same error I’m facing still! There’s a few projects where even rust-analyzer is not able to properly load unless I run cargo check --workspace --message-format=json --manifest-path {path to your projects cargo toml} --all-targets before. It’s quite annoying. Did you guys found any workaround or have some insight of what might be causing this misbehavior?