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

Failing to suggest correctly for array.len() and thread_rng().gen_range() #541

Open
thoughton opened this issue May 8, 2016 · 5 comments

Comments

@thoughton
Copy link

Hi,

First of all I'd like to say I am very new to Rust, but racer, alongside Atom plugins and the rust-lang.org/book, have so far made the learning process a pleasure - thank you.

racer has been exceptionally useful, however whilst working through "the book" I have noticed the occasional situation where it seems to fail to suggest where I might expect it.

Please see a small example program below:

extern crate rand;
use rand::Rng;
fn main() {
    let days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
    let num_days = days.len();  // Why doesn't .len code-complete in racer?
    //------------------^
    println!("num_days = {}", num_days);
    let rnd_day_idx = rand::thread_rng().gen_range(0, num_days);  // Why doesn't .gen_range code-complete in racer?
    //-----------------------------------^
    let rnd_day = days[rnd_day_idx];
    println!("Randomly-chosen day idx {} is {}", rnd_day_idx, rnd_day);
}

This program compiles and runs successfully; however when I try to auto-complete at the locations marked by the comments, I get the following output:

racer_test$ racer complete 5 25 src/main.rs
PREFIX 24,25,l
- Could not match expr node type: ExprVec([expr(4294967295: "      "), expr(4294967295: "       "), expr(4294967295: "         "), expr(4294967295: "        "), expr(4294967295: "      "), expr(4294967295: "        "), expr(4294967295: "      ")])
END

And:

racer_test$ racer complete 8 42 src/main.rs
PREFIX 41,42,g
MATCH gen,420,7,~/.cargo/registry/src/github.com-88ac128001ac3a9a/rand-0.3.14/src/lib.rs,Function,fn gen<T: Rand>(&mut self) -> T where Self: Sized
MATCH gen_weighted_bool,480,7,~/.cargo/registry/src/github.com-88ac128001ac3a9a/rand-0.3.14/src/lib.rs,Function,fn gen_weighted_bool(&mut self, n: u32) -> bool where Self: Sized
END

I'm just curious as to whether this is a known issue and what the cause of it is, so I know what to look out for in the future; or, perhaps this could instead be caused by an incorrect local setup?

Many thanks!

@thoughton thoughton changed the title Failing to suggest for array.len() and hread_rng().gen_range() Failing to suggest for array.len() and thread_rng().gen_range() May 12, 2016
@thoughton thoughton changed the title Failing to suggest for array.len() and thread_rng().gen_range() Failing to suggest correctly for array.len() and thread_rng().gen_range() May 12, 2016
@thoughton
Copy link
Author

Hi, original poster here. (Apologies if replying to self is frowned upon.)

If it turns out the issues in my original post are in fact expected behaviour, I was just wondering whether anyone instead could point me towards some info that details what is and is not supported by racer?

I've had a quick look through the pages here at gihub but I couldn't find any obvious list of current limitations or planned future work.

I guess in the end all I'm really after is some kind of reassurance that I have my system setup correctly and that the limitations I'm seeing are the same as everyone else.

Thanks!

@bluss
Copy link
Contributor

bluss commented May 15, 2016

Seems like two different bugs. You could call it expected yes (racer isn't good at type inference) but it's a bug nonetheless.

@thoughton
Copy link
Author

Hey, thanks for the info @bluss. I wondered whether they might be two separate issues, but I wasn't sure whether they could also be symptomatic of the same underlying problem.

I'm not sure whether to keep this Issue open or not. If this is something that's simply outside the scope of racer then I'm happy for this to be closed.

Thanks again for the reply!

@jwilm
Copy link
Collaborator

jwilm commented May 16, 2016

@thoughton Racer should definitely be providing completions here. As @bluss mentioned, racer's type inference could use some love.

@thoughton
Copy link
Author

Ahha, thanks @jwilm! In that case I will leave this open then. :-)

I really wish I could help somehow, but like I said, I'm afraid I'm very much a Rust beginner right now.

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

No branches or pull requests

3 participants