Code completion
Auto-completion for your Rust code works as you type. You can also call it manually by pressing Ctrl+Space.
For example, completion is available for attributes and elements inside #[derive]
, including standard library traits:
For popular Rust crates, you will receive suggestions even if the crate hasn’t been added to dependencies:
Completion also works inside macro calls. The plugin knows the resulting macro substitution and suggests only the applicable items:
Note that completion is available in doctest comments as well:
Auto-import
RustRover takes care of out-of-scope items. If you select an out-of-scope item from the completion list or paste code containing such items, RustRover will automatically insert the missing use
declarations. This behavior is enabled by default, however you can always disable it in (Rust section).
Automatically add import statements
Optionally, you can turn on automatic import on the fly. This way, RustRover will add missing use
declarations as you type (unless there are several possible options).
Press Ctrl+Alt+S to open settings and then select
.In the Rust section, select the Add unambiguous imports on the fly checkbox, and apply the changes.
Disable completion and auto-import for certain items
You may want to exclude certain items from completion lists and make sure they never get auto-imported. For example, you may want to exclude functions and traits that are re-exported in irrelevant crates – this way, only original ones will be suggested.
Navigate to Rust section.
and locate theIn the table, list the items that you want to exclude from completion and auto-import.
The following rules apply:
Specify each path just as you would in a
use
declaration.Add
::*
to a path if you want to disable auto-import for all items whose paths include the given prefix.When excluding traits, use the Apply to dropdown menu to specify whether you want to disable auto-import only for trait methods or for the trait name too.
Note that exclusion settings are ignored for items already imported with a
use
declaration.
Automatically add popular crates as dependencies on paste
Pasting code to an .rs
file may require you to mention additional dependencies in Cargo.toml
. RustRover takes care of that. By default, each time you paste code that mentions a new crate, RustRover displays a dialog asking you to confirm the list of crates to be added.
Configure automatic dependencies on paste
Do one of the following:
Once the Add Crates confirmation dialog appears, select Always Add if you want the crates to be added silently or Never Add if you don't want RustRover to ever suggest any new dependencies.
In the Settings dialog (Ctrl+Alt+S) , go to , locate the section, and select the desired value in the Add crate dependencies on paste dropdown: Always, Never, or Ask.
ML completion
Machine learning assisted completion is enabled by default. The suggestions are sorted by their relevance based on the rules learned from data gathered anonymously during the IDE's Early Access Program. Note that your source code is never being collected, only the information about your interactions with the code completion UI.
If you prefer to disable the ML completion feature, clear the corresponding checkbox in
.Set the Mark position changes in the completion popup checkbox to view the elements that were reordered to the ML data:
Postfix completion
Postfix completion helps you reduce backward caret jumps as you type. You can transform an already-typed expression into a different one based on a postfix you type after the dot.
For example, type .assert
after an expression (or select it from the completion suggestion list) to insert an assert_eq!
invocation:
You can check and adjust the list of postfix templates in
:To add a custom template, click and select Rust:
Create custom postfix templates
Press Ctrl+Alt+S to open settings and then select
.Click the Add button () on the toolbar and select Rust.
In the Create New Template dialog that opens, specify Key, a combination of symbols after the dot that will invoke the template.
Select which expression types the new template will be applicable to, and type the target expression in the following format:
$EXPR$ <target_expression>
, for example,$EXPR$ =!null
.