Open Joelius300 opened 5 years ago
It would be nice to know how I can work around this issue because VS Code will stop displaying errors for new code as long as there are still old ones. This means I have to manually build the project to see if it compiles. VS Code thinks there are still unfixed errors and doesn't even attempt to compile it again (that's what I'm assuming).
Same issue here. Running cargo run arg1 arg1
works perfectly but the vscode editor shows errors.
Until this issue is fixed in rls-vscode
, here is a temporary workaround:
mod lib; //.. instead of 'use minigrep'
use lib::Config; //.. instead of 'use minigrep::Config'
An alternative solution is to reload as per https://github.com/rust-lang/rls-vscode/issues/715
Newer versions may not suffer from this, although I've not tested it
Reloading VSCode worked for me
i get these private field errors even after making the respective changesa as mentioned above:
Compiling minigrep v0.1.0 (C:\Users\veeks\USERPROFILES\projects\minigrep)
error[E0616]: field query
of struct minigrep::Config
is private
--> src\main.rs:13:41
|
13 | println!("Searching for {}", config.query);
| ^^^^^ private field
error[E0616]: field filename
of struct minigrep::Config
is private
--> src\main.rs:14:35
|
14 | println!("In file {}", config.filename);
| ^^^^^^^^ private field
error: aborting due to 2 previous errors
For more information about this error, try rustc --explain E0616
.
error: could not compile minigrep
.
i get these private field errors even after making the respective changesa as mentioned above: Compiling minigrep v0.1.0 (C:\Users\veeks\USERPROFILES\projects\minigrep) error[E0616]: field
query
of structminigrep::Config
is private --> src\main.rs:13:41 | 13 | println!("Searching for {}", config.query); | ^^^^^ private fielderror[E0616]: field
filename
of structminigrep::Config
is private --> src\main.rs:14:35 | 14 | println!("In file {}", config.filename); | ^^^^^^^^ private fielderror: aborting due to 2 previous errors
For more information about this error, try
rustc --explain E0616
. error: could not compileminigrep
.
Remember to modify the file lib.rs, designating the variables and functions used in main.rs to pub after spliting that part of code into a seperate file lib.rs.
It is still happening.
Still a bug, and also discovered whilst working through the book :(
Bizzarely, re-loading VS code also fixed the issue for me.
Seems like most of the people who came here for this bug is doing the RUST BOOK studies 😄 (including me) Hope this bug get fixed in next update
I am getting this as well. Reloading helps.
Reloading helps for me but i noticed vscode cant "see" the types. I know the intellisense is not that important, but its a really convinient way to look for my modules. For example the vscode does not know the query is a string. Not showing any error but it feels wrong a little. :)
this is still an issue. however, it's not necessary to reload the full vscode window. press ctrl+shift+p and type "rust", select "Rust: Restart the Rust server".
i feel like this is definitely an issue with the language server not recognizing newly created files whatsoever. this happens all the time whenever you create a new rs file.
It is still happening.
@DerGernTod I agree, I just hit this and reloading the server seems to pick up new files.
It is still happening.
Seems to be a bug with some sort of caching on rust server. It can't detect the creation of a new lib inside de package, thus not finding the new lib as a valid import.
That's the reason why restarting code's window or restarting rust server works, it goes through the files and dependencies to get all valid imports.
Now, this is just a guess, I'm doing the tutorial same as everyone here, but it's something around what I would implement in order to improve performance.
So it's a bug, but can easily be worked around and most likely improves performance by a lot. Since the only way I can personally see to fix this would be to watch the root directory for changes and rebuild de package tree every time a file is changed (or created, but I don't think it's possible do differentiate between the two), I don't see this getting fixed anytime soon (most days you wont be creating new libs anyway).
You could give rust-analyzer
a try instead.
Cargo.toml add [workspace]
[package] name = "minigrep" version = "0.1.0" edition = "2021"
[workspace] minigrep = ["lib"]
[dependencies]
Still happening, and reloading fix it
邮件已经收到,我会尽快回复。
I'm currently working through the book and found what seems to be a bug in the VS Code extension. I'm in part 3 of building this cli-application and have just moved some logic from
main.rs
tolib.rs
. Just like it says in the book, I useduse minigrep::Config
andminigrep::run
to refer to the stuff defined inlib.rs
. It works perfectly fine if I build/run it with cargo but VS Code shows the following errors:For
use minigrep::Config;
For
minigrep::run(config)
:Here's the code in
main.rs
:Probably unnecessary but here's
lib.rs
:Again, building and running it with cargo works perfectly fine and the package name defined in
Cargo.toml
isminigrep
, just like it's supposed to be. In case it's not obvious, it was all done step-by-step following the book.