Autocomplete seems to be very flaky, both on Windows x64, and Linux x64. Not sure, if this is due to RLS or the VS Code plugin itself.
Consider the following program (similar to the one in rust-book), that compiles and runs.
extern crate rand;
extern crate primal;
use std::io;
use std::cmp::Ordering;
use rand::Rng;
fn main() {
println!("Hello, world!");
use std::collections::HashMap;
let teams = vec![String::from("Blue"), String::from("Yellow")];
let mut initial_scores: Vec<String> = std::vec::Vec::new();
initial_scores.push("10".to_string());
let i = initial_scores.iter();
let scores: HashMap<_, _> = teams.iter().zip(initial_scores.iter()).collect();
let n = rand::thread_rng().gen_range(1, 10);
println!("Guess the number! ({})", n);
let mut guess = String::new();
io::stdin().read_line(&mut guess)
.expect("failed to read line");
let guess_number: u32 = guess.trim().parse()
.expect("not a number!");
match guess_number.cmp(&n) {
Ordering::Less => println!("Too small!"),
Ordering::Greater => println!("Too big!"),
Ordering::Equal => println!("You win!"),
}
println!("Your number: {}", guess);
println!("Good bye!");
}
Observations:
let teams = vec![String::from("Blue"), String::from("Yellow")]; - Doesn't seem to recognize the type of "teams", and no autocomplete on the variable beyond this.let i = initial_scores.iter(); - into_iter is shown - but not iter(). It seems to be a partial autocomplete list.let i = initial_scores.iter(); - Type i unresolved, and as such no auto-complete further (possibly due to the above)let scores: HashMap<_, _> = teams.iter().zip(initial_scores.iter()).collect(); - Unresolved type (possibly related again to the above).let mut guess = String::new(); - Type recognition works. But auto-complete is partial - methods like cmp not available.let guess_number: u32 = guess.trim().parse()
.expect("not a number!"); - No autocomplete even though the type is explicitly given. primal:: - Only displays test mod inside. All other types are missing. This is just an example. Most cargo package don't show up with proper auto-complete. Am I missing something? Documentation seems to claim auto-complete, and this was a bit surprising to see. The same behavior can also be seen while using rls on vscode-rust plugin.
PS: I'm on the latest nightly, and tested both msvc and gnu toolchains.
cc @jwilm - are these known issues?
We rely on Racer for code completions and Racer only has (essentially) syntactic knowledge so is sometimes limited (although it is pretty good overall). Long term, we plan to use the compiler for code completion like we do for 'goto def' and 'type on hover', etc. That should improve things, but requires some big changes to the Rust compiler for it to be fast enough.
@nrc - Now that you mention goto def and type on hover, that doesn't work either. Shouldn't that work if it currently uses compiler, albeit slowly? It only seems to work for the std libs, and certain crates. Seems like it only recognizes a few specific patterns.
In the above example, trying the goto def on the crate primal doesn't work. It just says no definition found. Though, interestingly, using vscode-rust plugin and setting it in Legacy mode where it uses Racer, rustfmt and rustsym, instead of RLS, goto def works as excepted. (Although that's about the only one that works better).
Do you have the whole project in a repo I can look at? Diagnosing the problem will probably depend on looking at the whole project.
@nrc - I chose the above code for the reason that that's pretty much it. That's the entire project with the added crates to the Cargo.toml from the default bin project.
Anyway, I've just created a repo here: https://github.com/prasannavl/rust-away : (rust-Are-We-Auto-complete-Yet) - Will add all the observations as comments in a bit, here so it's easy to track all of it.
@nrc - I've added "FIXME" prefix in comments to the ones that doesn't work, and added more observations there which doesn't seem to work.
Thanks @prasannavl I'll take a look in the next few days.
Does anyone have any more updates on this issue? There are crates for which there is literally no autocomplete at all. A good example is the rocksdb crate https://crates.io/crates/rocksdb.
@nrc - While this is very much relevant to vscode - perhaps, this issue should be moved to rls for tracking. Shall I create an issue there linking to this?
I think this is basically a Racer issue (unless @jwillm says otherwise) so there is not much we can do about it, sorry.
cc @jwilm
You can call it a Racer issue if you want, but we're not about to fix any of these issues. Real type inference, seeing through macros, and generalized generic support is just not easy to do with Racer's model of completion. Long term, RLS will need to implement these features. Or patch Racer. I suspect implementing in RLS with compiler internals will be a lot easier, though.
@nrc I feel this is becoming an issue that's just being thrown around pointing at other projects, since it's not an easy problem to solve for Rust.
I agree with @jwilm that this should come under RLS, since that makes the most sense.
As a follow up I am experiencing the same problem described by @prasannavl . I actually initially tested this using the Eclipse corrosion plugin. I experienced the same behavior. Thinking it was a problem with Eclipse corrosion I installed VSCode and relevant rust extension. Same result. .. So I don't think its the IDE - but rather rls .. and/or racer.
If I recall correctly, Racer was supposed to be a temporary solution when RLS came to existence, looks like it's not anymore?
Most helpful comment
You can call it a Racer issue if you want, but we're not about to fix any of these issues. Real type inference, seeing through macros, and generalized generic support is just not easy to do with Racer's model of completion. Long term, RLS will need to implement these features. Or patch Racer. I suspect implementing in RLS with compiler internals will be a lot easier, though.