In CLion Rust, how do I get code completion suggestions for a package dependency I add to Cargo.toml?

已完成

I'm using CLion for Rust. For builtin and std library types, code completion works fine. For example, if I type `String::f`, a nice menu pops up with `from`, `from_utc8_unchecked`, etc.

However, if I add an external dependency to Cargo.toml, like `rand = "0.8.5"` in the [dependencies] section, there's no completion suggestions. For example, if I type `rand::thr`, I'm expecting to see a menu pop up with `rand::thread_rng` as one of the items, but instead nothing pops up.

Am I doing something wrong, or is this a known missing feature?

EDIT: I already have `use rand;` so the code compiles and works. There's just no completion suggestions (I don't know what that menu is called specifically)

0

I am not sure if you would need to add `use rand;` in order to get code completion to work...

0

I already have use rand; the code compiles fine, but the completion doesn't work.

0

Xdavidliu Does Help | Find Action > Refresh Cargo Projects help?

1

I wasn't able to test "Refresh Cargo Projects" because of the following:

Interestingly, when I restarted CLion, the suggestions started working, i.e. when I typed "rand::th", suggestions menu successfully came up, including "rand::thread_rng".

I'll see if I reproduce this error.

0

Update: "Refresh Cargo Projects" indeed fixed the issue. In my comment above, I noticed that when I restarted CLion, my previous project, which already had rand as a dependency, had suggestions working, so in order to reproduce, I deleted the project and started a new one, then noticed the issue again. This time, I used "Refresh Cargo Projects" and suggestions started working again.

0

请先登录再写评论。