Skip to content

VS Code: Renaming module from UpperCamelCase to snake_case leads to module being incorrectly reported as unlinked and unresolved #18273

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

Closed
Computerdores opened this issue Oct 9, 2024 · 5 comments
Labels
C-bug Category: bug

Comments

@Computerdores
Copy link

rust-analyzer version: rust-analyzer version: 0.3.2137-standalone (2b750da1a 2024-10-06) [c:\Users\<redacted>\.vscode\extensions\rust-lang.rust-analyzer-0.3.2137-win32-x64\server\rust-analyzer.exe]

rustc version: rustc 1.81.0 (eeb90cda1 2024-09-04)

editor or extension: VS Code Rust-Analyzer v0.3.2137

relevant settings: Not sure what qualifies here and the given examples (CARGO, RUSTC, RUSTUP_HOME or CARGO_HOME) all don't seem to be set (echo %CARGO% etc. outputs %CARGO%)

steps to reproduce:

  1. create a new cargo project (cargo new Test123)
  2. open VSCode (code .)
  3. in the src directory create a new directory with a captial first letter (e.g. Asd) and mod.rs
  4. in main.rs add pub mod Asd;
  5. VS Code / Rust Analyzer will rightfully complain that the module shouldn't start with a capital letter
  6. press F2 and rename to the lower case version (asd)
    • the Asd directory wasn't always renamed during my tests - if it wasn't rename it to asd by hand
    • in main.rs change pub mod Asd; to pub mod asd;

VS Code will now display an error from the rust-analyzer: unresolved module, can't find module file: asd.rs, or asd/mod.rs rust-analyzer[E0583](https://doc.rust-lang.org/stable/error_codes/E0583.html) (sometimes you need to modify the file for this to show up)
Further autocompletion will not work and if you add any code to the mod.rs (e.g. fn test() {}) it will be grayed out with the message:

This file is not included anywhere in the module tree, so rust-analyzer can't offer IDE services.

If you're intentionally working on unowned files, you can silence this warning by adding "unlinked-file" to rust-analyzer.diagnostics.disabled in your settings.rust-analyzer[unlinked-file](https://rust-analyzer.github.io/manual.html#unlinked-file)

I have tried:
The only way of fixing this seems to be having pub mod Asd; in main.rs.
I have not managed to get a module name out of this weird state, here is what I tried:

  • Close and reopen VSC
  • 'Close Workspace' and reopen
  • VSC Command to remove the directory of the project from the workspace and then open it again
  • reboot the pc
  • delete the target directory
  • 'Reload Workspace' and 'Restart Server' via extension hover menu (not idea what the actual name for the menu is)

other notes:
I found this on the forum, however it is closed and the person just stopped using VSC which isn't really a solution imo, but hey works for them ig)

I don't think there is an issue for this yet, however I have to be honest I don't know how people find anything in the github issues search.
It might be related in some way to #9173, since E0583 shows up there too and also compiles without a problem in both cases.

This does not affect other modules in the project they work just fine, however can also be brought into that state at the same time.

Hope this helps!

@Computerdores Computerdores added the C-bug Category: bug label Oct 9, 2024
@Computerdores
Copy link
Author

Two seconds after creating the issue I opened VS Code again and now the module where I originally noticed this works properly again. I can't say for sure why it fixed itself in this instance. I only know that I tested the reproduction steps twice and tried reproducing the bug on a temporary module in the original project (the directory for which I deleted before open VSC again)

@alibektas
Copy link
Member

I cannot reproduce this. In such cases it is useful to run cargo clean once and see if anything changes.

@alibektas
Copy link
Member

alibektas commented Oct 9, 2024

Can it just be that you have your rust-analyzer.checkOnSave set to false?

@Computerdores
Copy link
Author

Computerdores commented Oct 10, 2024

I cannot reproduce this.

Is there anything I could provide that would help with reproducing it?

In such cases it is useful to run cargo clean once and see if anything changes.

After starting VSC today the bug is back in the original project. Running cargo clean did not fix it.

Can it just be that you have your rust-analyzer.checkOnSave set to false?

I checked, it is enabled. (In general, I didn't change the default settings)

@Veykril
Copy link
Member

Veykril commented Oct 14, 2024

This is #9947, a vscode bug, it caches the casing on case insensitive file system, reporting wrong paths to the language server. You'll need to find the VSCode cache for your workspace and clear that

@Veykril Veykril closed this as completed Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

3 participants