-
Notifications
You must be signed in to change notification settings - Fork 168
Unresolved import
error highlighting when nothing is wrong
#513
Comments
@tuvtran, I had this same issue with Rust 1.32.0. Upgraded to version 1.33.0 and RLS stopped reporting these false-negatives. |
I'm running Rust 1.33.0 and RLS, and am still getting these issues - everything builds and runs fine, but an libraries pulled in from crates can't be resolved in the editor. Adding |
Could you post your |
@tuvtran, changing the |
@tuvtran I think you need to just change your VSCode theme, when you change everything should be much better. |
I had the problem described in the opening post running rustc 1.33.0. Most of my tools, including Rust itself and the Rust VSCode plugins, have been installed not a week ago. The project is freshly created with cargo new and had
That "fixed" it for me too. edit: @Xanewok
Where can I find the " |
@TobiasWehrum Hit Ctrl+, and click the "{}" button to the right to open the settings.json, you should have some options changed there. |
@Xanewok These is my whole settings.json:
|
So I had a simple use t;
use t::MyStruct; // pub struct MyStruct { ... } inside the src/lib.rs this works as expected. Could you possibly provide a very detailed, step-by-step reproduction? Do you start with a |
|
I have this same problem on Windows 10. I see the same behavior with deleting the line and re-typing the use line. I also had the above behavior with changing the year in Cargo.toml and changing it back. |
exit vscode and re-open, fixed the issue. |
I'm having the exact same issue while running These are the errors and warnings I am getting, although none of these show up as I compile and run the program: I had to follow @fzxu and restart vscode (and by extension RLS) |
I'm using rust v1.35.0 and VSCode 1.36.1 with Rust(rls) plugin v0.6.1. This trick worked for me too. |
press |
I tried all proposed solution the linting errors disappear but autocomplete does not work just when I add |
I also tried everything here and I'm still having this issue. i use arch btw |
Just had this issue recently and a couple of the suggestions worked (changing edition to something else, then back worked; also restarting the RLS worked). Could it be an RLS bug? |
I fix it with |
same happens to me with rls nightly and rust 1.40. restarting VS code fixes it. |
In VS Code I solve this issue by running the "reload window" command. |
None of the previous solutions helped unfortunately.
Basically Code:
Errors when running from code editor:
Adding
Changing NOTE: Basically, out of two editors (VSCode and Atom), that have Debugging capabilities, unlike |
After doing the Reload Window operation, I stop seeing the false-positive errors in the editor, but I do not get symbol completion for symbols in the lib.rs from main.rs (I'm also following the Book and doing the minigrep project.) I do seem to get symbol completion from within the lib.rs file while there though. |
@RebelCoderRU I'm getting exactly the same errors as you. |
Does your crate compile? I've had the same problem when autocompletion breaks down when there were compile errors in the crate (e.g. missing imports) |
I have the same "unresolved import"problem but autocompletion works fine, |
Seeing the errors as well, reloading the window fixed the issue for me |
FWIW, I am seeing this same issue with RLS in Emacs, so it looks like a language server issue, not a VSCode one. Restarting the server worked for me. |
For the record, I just got the same problem (code compiles fine, RLS can't find dependencies) with this loadout:
(In other words, it definitely looks like a problem in RLS, not the VSCode extension.) However, I may have a hint as to how to reproduce the problem and where it comes from. I don't currently have time to sit through another compile to verify that it'll reproduce it (I'm on an Athlon II X2 270 and have no global compiled dependency caching set up and the test involved actix's ~170 dependencies), but here's what triggered it for me:
...so a similar dance with adding dependencies might be able to reproduce it under VSCode, and I suspect it's some kind of cache invalidation bug within RLS. |
It was giving a weird error with importing libraries. rust-lang/vscode-rust#513
The issue still exists (as I came across the same situation #513 (comment) ) |
@SeanChao Yeah still got the problem here, restarting the rust language server works. The error keeps coming back. I ended up just adding a hotkey if I know that the import works and just hit it. The language server takes milliseconds to restart, if you have lots of imports your VSCode may take a second or two to catch up. |
me too.. |
🤣 When people have computer problems I often just roll my eyes and tell them "have you tried restarting?", and the problem is usually gone. But I can never remember my own advice when it's my own turn. |
This error is still reproducible, setup: VS Code (1.54.3), rustc 1.49.0 (e1884a8e3 2020-12-29), wsl 2 (Windows, but .. wsl 2, so ubuntu). |
@alessioalex Agreed using WSL2 as well and this issue is very annoying lol |
I found that it only worked after I built the lib.rs file for the first time, then saved my folder as a workspace (this reloaded the editor). So it may just be that you need to compile and reload, or there may be something to do having the folder in a vscode workspace. Either way, hope this helps someone |
2021 and I still have this. Autocompletion, running cargo run from terminal and visual studio doesn't work. Closing and reopening visual studio didn't work either, but the error was different this time. crate keyword doesn't autocomplete, but works. |
Had the same issue on Windows 10 - restarting VSCode fixed it. |
I got this doing the same exercise from the rust book in the original post... using vim + coc for autocomplete (coc-rls). I was able to get rid of the error by running |
I've had same issues above and I replaced extension rust with rust-analyzer. |
may 2022 and still an issue but it seems to be specifically an issue if you create your new rust project, open it in code and then add lib.rs manually and it is solved by closing vscode and opening it again. It seems something needs to be triggered on create of new files to update something somewhere that currently is only happening if you restart vscode or, perhaps as suggested a bit above, use the reload window command. |
It may not be the problem in every case, but in my own case I just encountered an instance of this that seems to have been because my project has multiple |
@HS-Dave, @EatThePath you should probably give https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer a try. |
@lnicola I already use it. |
I was following chapter 12.3 of the Rust book [0]. Particularly this snippet from Listing 12-14:
However, the VS Code extension threw me some errors:
Upon digging this issue, I found out that prior to the 2018 Edition, the Rust compiler would have caught these issues [1]. After updating Rust to 1.32.0 and adding
edition = "2018"
toCargo.toml
, my code ran just fine in the terminal. Yet, these errors still persist inside VS Code via the Rust extension. Is it just me or the extension never fixes this error?[0] https://doc.rust-lang.org/book/ch12-03-improving-error-handling-and-modularity.html
[1] rust-lang/book#1676 (comment)
The text was updated successfully, but these errors were encountered: