Rust-analyzer failed to discover workspace

Hi, I'm try to configure the rust-analyzer extension to work with VSCode, but I'm running into a rust-analyzer failed to discover workspace error. I am on Windows 10, attempting a simple "hello world" project. rustc main.rs works and compiles, program runs. I'm new to Rust; so maybe I'm missing something...

I've made sure rust-src is installed (it was not installed automatically with the extension):

$ rustup component list
cargo-x86_64-pc-windows-msvc (installed) 
clippy-x86_64-pc-windows-msvc (installed) 
llvm-tools-preview-x86_64-pc-windows-msvc
rls-x86_64-pc-windows-msvc
rust-analysis-x86_64-pc-windows-msvc
rust-docs-x86_64-pc-windows-msvc (installed)
rust-src (installed)
...

I have tried on both "stable" and "nightly" update channels:

rust-analyzer version: 2020-08-17 (0b2b9a5)
rust-analyzer version: nightly (7d95a84)

I have configured the following recommended debugging settings:

"rust-analyzer.trace.extension": true,
"rust-analyzer.trace.server": "verbose",

as well as configuring RA_LOG=info in the environment.

Trying to run Status results in:

Command 'Rust Analyzer: Status' resulted in an error (cannot open rust-analyzer-status://status. Detail: Rust Analyzer is still loading...)

Output > Rust Analyzer Language Server does not show up in the output panel, despite the environment variable being set (I'm assuming because RA isn't starting.)

Server Trace is hammering the output window with tons of:

[Trace - 3:02:44 AM] Received response 'rust-analyzer/inlayHints - (142)' in 0ms. Request failed: Rust Analyzer is still loading... (-32801).
[Trace - 3:02:45 AM] Sending request 'rust-analyzer/inlayHints - (143)'.
Params: {
    "textDocument": {
        "uri": "file:///c%3A/Users/coryr/source/repos/rust-hello-world/main.rs"
    }
}

Client output window is peppered with tons of:

WARN [8/18/2020, 3:00:53 AM]: LSP request timed out {
  method: 'rust-analyzer/inlayHints',
  param: {
    textDocument: {
      uri: 'file:///c%3A/Users/coryr/source/repos/rust-hello-world/main.rs'
    }
  },
  error: [ResponseError: Rust Analyzer is still loading...
  	at handleResponse (c:\Users\coryr\.vscode\extensions\matklad.rust-analyzer-0.2.281\out\src\main.js:3413:48)
  	at processMessageQueue (c:\Users\coryr\.vscode\extensions\matklad.rust-analyzer-0.2.281\out\src\main.js:3238:17)
  	at Immediate.<anonymous> (c:\Users\coryr\.vscode\extensions\matklad.rust-analyzer-0.2.281\out\src\main.js:3222:13)
  	at processImmediate (internal/timers.js:439:21)] {
    code: -32801,
    data: undefined
  }
}

I've reinstalled the entire toolchain/rust-analyzer from scratch twice now; so I'm a little lost. Halp? Is there anything else useful to set for debugging? I've seen mentions of 100% CPU usage bringing RA down, but I've also confirmed that is not the case for me.

Edit: here's an entire startup output from Server Trace.

rust-analyzer doesn’t support zero-config single file mode at the moment (you can make it work, but that’s tricky). We currently focus on supporting cargo based project, so I suggest trying cargo new my-project and opening that in VS Code.

2 Likes

Ahhh, that was indeed it. I went back through the docs and couldn't find anywhere that I felt said that explicitly, but I may have missed it. It makes sense in this day and age, though, that we would want a project definition of sorts. :slight_smile: D'oh.

I've reread Non-Cargo Based Projects and I suppose that is the documentation I was supposed to grok. I suppose I should gone a bit more indepth with Rust before configuring an IDE.

I suppose since I didn't find too many others like me, I'm a one off case here and missed something I shouldn't have in the beginning of my Rust journey, so I won't recommend mentioning the cargo hard-recommendation earlier. Thanks again for your help @matklad !

Hello there,

What about cargo based project but not at the root of the workspace?
We are working on a C project that has a module written in Rust, and for now, I have to open another VSCode just at the Cargo.toml level in order for rust-analyzer to handle it properly, otherwise I get the unable to discover message.

It feels pretty obvious "why", but I'm wondering if there is any plan on implementing this feature of "deep" discovery in the future ?

Side node: using the VSCode workspace feature might also do the trick, but I'm not a big fan of changing the "layout" of dirs/files with this.

EDIT: Alright, nevermind, looks like this covers my need.

I think you need to use linkedProjects in settings.json:

    "rust-analyzer.linkedProjects": [
        "path/to/Cargo.toml"
    ]
2 Likes