Vscode-rust: Adding dependencies to Cargo.toml requires restarting VScode

Created on 26 Jul 2017  ·  22Comments  ·  Source: rust-lang/vscode-rust

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'
P-High bug

Most helpful comment

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

All 22 comments

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

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)

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?

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

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

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

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.

@rohel01 is this all fixed now?

Yes, it is fixed.

Thanks !

2017-08-21 11:32 GMT+02:00 Nick Cameron notifications@github.com:

@rohel01 https://github.com/rohel01 is this all fixed now?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/rust-lang-nursery/rls-vscode/issues/98#issuecomment-323695292,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AI7wK6GTqSMMPRXHYaW8gb1Avm2ts-Dyks5saU6ygaJpZM4OkhMq
.

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)

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.

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

@sylints

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

same here

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

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)

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

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

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.

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.

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.

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.

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'
Was this page helpful?
0 / 5 - 0 ratings