vscode-rust icon indicating copy to clipboard operation
vscode-rust copied to clipboard

Rust IDE Issues (VSCode, Atom)

Open rebelC0der opened this issue 5 years ago • 2 comments

Hello.

I can't get VSCode or Atom to work with Rust properly (in a productive way). This seems to be a very widespread issue:

  • Latest VSCode
  • Rust Beta (rustc 1.41.0-beta.1 (eb3f7c2d3 2019-12-17)) Same issue with other versions
  • rls 1.41.0 (8f1c275 2019-12-10)
  • Rust extension: Rust (rls)
  • Script running extension: Code Runner

Basically cargo run works just fine and runs the project. But VSCode can't figure out where crates are:

Code:

use rand::Rng;

fn main() {
    let rnd_num = rand::thread_rng().gen_range(1, 100);
    println!("Random number: {}", rnd_num);
}

cargo run from terminal:

[jurisl@JurisLinuxPC game]$ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/game`
Random number: 54

Errors when running from code editor:

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:4:19
  |
4 |     let rnd_num = rand::thread_rng().gen_range(1, 100);
  |                   ^^^^ use of undeclared type or module `rand`

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0432, E0433.
For more information about an error, try `rustc --explain E0432`.

Adding extern crate rand; results in the same error:

error[E0463]: can't find crate for `rand`
 --> main.rs:1:1
  |
1 | extern crate rand;
  | ^^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.

Changing edition = "2018" - Does not help. Restarting RLS/VSCode - Does not help.

NOTE:

  1. The exact same issue is present in Atom editor.
  2. Autocomplete almost does not work: image

Basically, out of two editors (VSCode and Atom), that have Debugging capabilities, unlike Intellij Rust, both don't work for me and I just can't code in Rust as tools are literally broken/not mature enough for productive work. Please let me know if I am wrong and it is just a case of one little flag, that everyone forgets to mention, is missing in some config.

rebelC0der avatar Jan 15 '20 23:01 rebelC0der

I have figured out one part: problems with running your code from within the VSCode. I had to modify default code-runner command for rust:

Original command:

"rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt",

Changed to:

"rust": "if [ $(basename $dir) = 'examples' ]; then cargo run --example $fileNameWithoutExt; else cargo run; fi",

And now it works, and I can run my code quickly.

Part 2: Autocomplete still is very very bad, unfortunately. I am using RLS. there is this thing racer. Is it a better choice?

I am wondering how people get a good autocomplete from Rust?

rebelC0der avatar Jan 16 '20 19:01 rebelC0der

@RebelCoderRU for better autocomplete you probably want to use https://github.com/rust-lang/rls-vscode instead (or https://rust-analyzer.github.io/ if you are adventurous) See https://github.com/editor-rs/vscode-rust/issues/391 for details.

newca12 avatar Feb 02 '20 09:02 newca12