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

Adding dependencies to Cargo.toml requires restarting VScode #98

Closed
rohel01 opened this issue Jul 26, 2017 · 22 comments
Closed

Adding dependencies to Cargo.toml requires restarting VScode #98

rohel01 opened this issue Jul 26, 2017 · 22 comments

Comments

@rohel01
Copy link

@rohel01 rohel01 commented Jul 26, 2017

Fedora 25 x86_64
VSCode 1.14.2
Rust (rls) 0.1.0

Rust toolchain installed with rustup and up to date.

When adding new crates as dependencies of my library crate, I find that I have to manually restart VSCode so that newly added crates are taken into accound by Rust (rls).

Without restarting, I get the following error in the problem view, although my crate compiles just fine through the command line

severity: 'Error'
message: 'use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, and unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead? (see issue #27812)'
at: '7,1'
source: 'rustc'
@nrc
Copy link
Member

@nrc nrc commented Jul 26, 2017

This should be fixed by updating the RLS (run rustup update from the command line).

@rohel01
Copy link
Author

@rohel01 rohel01 commented Jul 27, 2017

Thanks for the quick response.

I have just updated RLS and it seems to work: RLS monitors my Cargo.toml file and triggers a new analysis when it changes.

The update changed the error message I got and I am not sure it is intended. I am working on the mpq crate which contains both a library and a binary. So, I am using the "rust.build_lib": true setting.

If my Cargo.toml file is missing a crate dependency, I now get the following error

file: 'file:///<removed>/mpq-rust/src/main.rs'
severity: 'Error'
message: 'can't find crate for `mpq`'
at: '3,1'
source: 'rustc'

Also, warning display no longer works ("rust.show_warnings": true in my VSCode settings)

@nrc
Copy link
Member

@nrc nrc commented Jul 27, 2017

The update changed the error message I got and I am not sure it is intended.

This sounds like the right error? Does it go away when you add the dep for mpq to the Cargo.toml?

You usually don't get warnings if there are any errors - could that be the problem with warnings?

@rohel01
Copy link
Author

@rohel01 rohel01 commented Jul 30, 2017

mpq is the crate I am working on. So basically, RLS cannot find the current project.
Also, this error comes from the main.rs file, while I am working on the library part of the crate. I assumed setting rust.build_lib": true would prevent RLS from analysing that file.

I have experimented a bit and found that warnings and errors are no longer shown in VSCode. I edited both the source code and the Cargo.toml to introduce syntax errors but they remain unflagged in the UI.

The can't find crate for mpq error appears randomly after a few edit/save cycles of my files. When it appears, I usually have to restart VSCode to make it disappear.

I have made available my current repo here if you want to reproduce the issues

For reference, here are my Rust related settings in VSCode

  "rust.build_lib": true,
  "rust.show_warnings": true,
  "rust.unstable_features": false

@nrc nrc added the bug label Jul 30, 2017
@nrc
Copy link
Member

@nrc nrc commented Jul 30, 2017

cc @Xanewok maybe a problem with lib/bin stuff after a forced rebuild?

@rohel01
Copy link
Author

@rohel01 rohel01 commented Aug 1, 2017

I believe this issue is related to rust-lang/rls#431

@Xanewok
Copy link
Member

@Xanewok Xanewok commented Aug 1, 2017

cc @Xanewok maybe a problem with lib/bin stuff after a forced rebuild?

I'll take a look at why the settings doesn't work as expected now.

@nrc
Copy link
Member

@nrc nrc commented Aug 21, 2017

@rohel01 is this all fixed now?

@rohel01
Copy link
Author

@rohel01 rohel01 commented Aug 21, 2017

@nrc nrc closed this as completed Aug 21, 2017
@rlguarino
Copy link

@rlguarino rlguarino commented Dec 30, 2017

I seem to still have this issue:

2017-12-30_10-44-10

rustup run nightly rls --version
rls-preview 0.124.0-nightly (299a6a9 2017-12-25)

@chamons
Copy link

@chamons chamons commented Feb 25, 2018

I can confirm this issue still exists, and is pretty trivial to hit for new users

  1. Work through https://doc.rust-lang.org/book/second-edition/ch02-00-guessing-game-tutorial.html until you hit "Generating a Secret Number"
  2. Hit "use of unstable library feature 'rustc_private`" warning and google until you hit this issue.

@nrc nrc added the P-High label Mar 22, 2018
@sylints
Copy link

@sylints sylints commented Apr 7, 2018

Can confirm, am new user working through the Guessing Game tutorial and hit this bug, google'd it and landed here.

@sagudev
Copy link

@sagudev sagudev commented May 3, 2018

@sylints

Can confirm, am new user working through the Guessing Game tutorial and hit this bug, google'd it and landed here.

same here

@wukann
Copy link

@wukann wukann commented Jun 16, 2018

I encountered the same problem through the Guessing Game tutorial.
When restarting VSCode, the problem no longer occurred.

@dlukes
Copy link

@dlukes dlukes commented Jul 21, 2018

FWIW, I wasn't able to reproduce this, so maybe it has been fixed? (macOS, VSCode 1.25.1, rls-vscode 0.4.9, rustup toolchain stable, rustc 1.27.2)

@covertbert
Copy link

@covertbert covertbert commented Jul 29, 2018

It's definitely still an issue as I just encountered it! Restarting VSCode fixed it for me

@Xanewok
Copy link
Member

@Xanewok Xanewok commented Jul 29, 2018

Unfortunately this occured for Windows for me, fix is pending at https://github.com/Xanewok/rls/tree/windows-watch-cargo

@TallonRain
Copy link

@TallonRain TallonRain commented Aug 4, 2018

As sylints said. Same here, running through the Guessing Game tutorial with the latest stable releases as of this writing, ran into the error. Compiles and runs fine regardless. Can also confirm that restarting VSCode fixes it.

@BarePotato
Copy link

@BarePotato BarePotato commented Oct 16, 2018

Working through the book, chapter 2 guessing game tutorial generated this problem as well. build and run fine, restart vscode clears, and continues to build and run fine.

@plstreatmewell
Copy link

@plstreatmewell plstreatmewell commented Oct 23, 2018

I've also been working on the tutorial and encountered this problem as well.
Build and run work fine via command line.
But unlike the cases above, restarting vscode doesn't fix the problem.
I also rebooted the computer but the error still occurs.
Any idea?

Thanks for reading.

jamesray1 added a commit to jamesray1/rust-libp2p that referenced this issue Jan 17, 2019
pulling,
this is probably due to an issue with rls-vscode: e.g.
rust-lang/vscode-rust#364 and
rust-lang/vscode-rust#98.
* Other changes that were again meant to be in the
previous commit, as mentioned there (rm unused imports,
custom_error fixes, compiler fixes such as adding
imports and removing unused ones, use the type Error =
rror and connection_keep_alive for ProtocolsHandler,
etc.)
* gossipsub v 0.2.2 -> 0.2.0
* Change remove and remove_peer_from_topic methods of
mesh, using a match to return peers or an added custom
error. Use in layer.
* Compiler fixes: add cloning, return types, etc.
*
@Xanewok
Copy link
Member

@Xanewok Xanewok commented Apr 7, 2019

I just tested the guessing game and it works as expected using RLS from master (should be most recent nightly but is curently breaked for a couple of days) and the most recent VSCode extension. Please reopen if this is still an issue.

@Xanewok Xanewok closed this as completed Apr 7, 2019
@RebelCoderRU
Copy link

@RebelCoderRU RebelCoderRU commented Jan 15, 2020

Latest VSCode, Latest Rust (Stable), latest Rust (rls) plugin:

Using 'code runner':

use rand::Rng;
use std::io;

fn main() {
    println!("Guess the number!");

    let sec_num = rand::thread_rng().gen_range(1, 101);

    println!("Generated number is: {}", sec_num);

    println!("Please input your guess.");

    // let mut guess = String::new();

    // io::stdin()
    //     .read_line(&mut guess)
    //     .expect("Failed to read line");

    // println!("You guessed: {}", guess);
}

ERROR:

error[E0432]: unresolved import `rand`
 --> main.rs:1:5
  |
1 | use rand::Rng;
  |     ^^^^ maybe a missing crate `rand`?

error[E0433]: failed to resolve: use of undeclared type or module `rand`
 --> main.rs:7:19
  |
7 |     let sec_num = rand::thread_rng().gen_range(1, 101);
  |                   ^^^^ use of undeclared type or module `rand`

Did anyone manage to make VSCode work properly with Rust (rls) plugin? Auto completion seems to be very bad and not always working.

I also had to add this flag to the settings.json:
"rust-client.enableMultiProjectSetup": true to avoid this error:

'error: could not find `Cargo.toml` in `/media/Work/Work/rust_code`
or any parent directory'

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

No branches or pull requests