Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unresolved module rust-analyzer error. #5484

Closed
RamiHg opened this issue Jul 22, 2020 · 14 comments · Fixed by #5756
Closed

Unresolved module rust-analyzer error. #5484

RamiHg opened this issue Jul 22, 2020 · 14 comments · Fixed by #5756

Comments

@RamiHg
Copy link

RamiHg commented Jul 22, 2020

Hello,

Ever since the latest update, I've been getting strange "unresolved module rust-analyzer" errors on lines that define modules. E.g.:

pub mod foo;  // unresolved module rust-analyzer
mod bar;
mod foobar; // unresolved module rust-analyzer

The problem occurs in only one library in my workspace. A seemingly random subset of 1-9 module defines have that error. Every time I restart VSCode, a slightly different subset of those 1-9 have that error. If a module has that error, rust-analyzer does not work for that module (no autocomplete, hints, etc).

There are no errors in the Rust Analyzer Language Trace, except for [ERROR ra_project_model] cyclic dependency <unrelated module> -> <unrelated module>. But that error has been there for months, and I suspect it's a separate issue (they are both dev-dependencies of one another).

I am however seeing errors in the "Extension Host" log. I've attached the full log (ra_errors.txt) with the callstack, but here are some of the error messages:

[2020-07-21 21:37:18.304] [exthost] [error] [matklad.rust-analyzer] provider FAILED
[2020-07-21 21:37:18.305] [exthost] [error] Error: Illegal value for `line`
...

[2020-07-21 21:35:45.772] [exthost] [error] [matklad.rust-analyzer] provider FAILED
[2020-07-21 21:35:45.773] [exthost] [error] Error: canceled by client
...

[2020-07-21 21:38:35.832] [exthost] [error] [matklad.rust-analyzer] provider FAILED
[2020-07-21 21:38:35.832] [exthost] [error] Error: content modified

Windows 10, rustc 1.45, rust-analyzer v0.2.248.

@bjorn3
Copy link
Member

bjorn3 commented Jul 22, 2020

Which VSCode version are you using?

@RamiHg
Copy link
Author

RamiHg commented Jul 22, 2020

The latest version at the time of this post. 1.47.2.

@DouglasLivingstone
Copy link

DouglasLivingstone commented Jul 23, 2020

I'm seeing this too, closing and re-opening the lib.rs file hides the error until lib.rs is edited. I'm also using VS Code 1.47.2 and rust-analyser 0.2.248.

@RamiHg
Copy link
Author

RamiHg commented Jul 28, 2020

I've been trying to figure out what's going on for the last couple of days to no avail. I've removed projects one-by-one from my workspace, removed the circular dev-dependencies, turned off all features, turned on all features, turned off proc-macro expansion, etc. I also enabled trace server logging, but nothing stood out to me. No error messages coming from the server at all.

When I tried building from source (to see if maybe the bug had been fixed), I ran into #5556. Could the two issues be related? The weird syntax errors happen to correlate with the modules I've been having problems with:

ra_bug

I'm happy to help give more information in any way I can. This bug is making RA unusable ATM :(. I'm having to gasp use RLS just to get some code-completion.

@wansa9
Copy link

wansa9 commented Jul 29, 2020

I'm seeing the same issue, VS Code 1.47.3, rust-analyzer 0.2.256.

@lnicola
Copy link
Member

lnicola commented Jul 29, 2020

@RamiHg is your project public so we could try to reproduce this? If not, could you try to minimize it (e.g. by removing modules, types, replacing function bodies with loop {}) until it no longer happens, or you're able to share the code?

@DouglasLivingstone
Copy link

The smallest reproducible example I have is attached. To reproduce:

  1. Extract the zip file to repo
  2. Open VS Code, eg code repo
  3. Open b/src/lib.rs
  4. Close VS Code
  5. Reopen VS Code

Should see:

image

It seems to be fine if lib.rs is not open when VS Code opens, so could this be a race condition somewhere?

repo.zip

@lnicola
Copy link
Member

lnicola commented Jul 29, 2020

It might be a race, as I couldn't reproduce it:

image

Does it get fixed if you reopen or edit the file? Does it ever happen again after startup?

@DouglasLivingstone
Copy link

If I close and reopen the file, the error is not shown until I edit it. The error is shown before save.

If I close all files, close VS Code, reopen VS Code, reopen lib.rs, add a new file y.rs, then add mod y; to lib.rs, then I get this state:

image

Closing lib.rs hides the error (so the file name on the left goes white). If I reopen the file, initially there is no error shown:

image

but if I edit the file, then it goes back to the first screenshot, with an error for y. If I open lib.rs then restart VS Code, both modules are highlighted:

image

@DouglasLivingstone
Copy link

DouglasLivingstone commented Jul 29, 2020

Also, if I delete the a package and remove it from the top-level Cargo.toml workspace section, then the lib.rs file works totally fine after restarting VS Code.

@RamiHg
Copy link
Author

RamiHg commented Jul 29, 2020

It might be a race, as I couldn't reproduce it:

image

Does it get fixed if you reopen or edit the file? Does it ever happen again after startup?

@DouglasLivingstone that looks like exactly the same steps + weird behavior that I encountered! @lnicola: I should mention that this was only happening on Windows. I could not reproduce the bug on either Mac OS or Linux. If you can't reproduce the bug with @DouglasLivingstone's use-case, I'll just make my repo public.

@Kimundi
Copy link
Member

Kimundi commented Jul 31, 2020

I can also confirm this behavior.

@pragmatrix
Copy link
Contributor

pragmatrix commented Aug 10, 2020

I had the same problem with a nested library package. After starting up VSCode and editing the lib.rs file, it showed a number unresolved module errors and the problem always appeared when I opened VSCode without the lib.rs opened in the editor. When lib.rs was opened and the frontmost file in the VSCode, everything worked as expected.

I tracked the problem down to a path normalization problem related to Vfs / FileSets. In my system, some paths enter the rust-analyzer with lowercase drive letters (in this case c:). After converting them to uppercase at two points in the code, the problem disappeared entirely. May be this helps tracking down the root cause from there.

Edit: I've isolated the problem to the VfsPath::encode function: f0d511e

@Johnrobmiller
Copy link

This bug replicated for me as of 1/3/2024. I fixed it simply by closing and reopening VSC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants