Skip to content

Commit d447a9a

Browse files
bors[bot]Veykril
andauthored
Merge #6240
6240: Document auto_import as a feature r=Veykril a=Veykril Closes #6225 Co-authored-by: Lukas Wirth <[email protected]>
2 parents 7dd09a7 + f8a7cc6 commit d447a9a

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

crates/assists/src/handlers/auto_import.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,61 @@ use crate::{
66
AssistContext, AssistId, AssistKind, Assists, GroupLabel,
77
};
88

9+
// Feature: Import Insertion
10+
//
11+
// Using the `auto-import` assist it is possible to insert missing imports for unresolved items.
12+
// When inserting an import it will do so in a structured manner by keeping imports grouped,
13+
// separated by a newline in the following order:
14+
//
15+
// - `std` and `core`
16+
// - External Crates
17+
// - Current Crate, paths prefixed by `crate`
18+
// - Current Module, paths prefixed by `self`
19+
// - Super Module, paths prefixed by `super`
20+
//
21+
// Example:
22+
// ```rust
23+
// use std::fs::File;
24+
//
25+
// use itertools::Itertools;
26+
// use syntax::ast;
27+
//
28+
// use crate::utils::insert_use;
29+
//
30+
// use self::auto_import;
31+
//
32+
// use super::AssistContext;
33+
// ```
34+
//
35+
// .Merge Behaviour
36+
//
37+
// It is possible to configure how use-trees are merged with the `importMergeBehaviour` setting.
38+
// It has the following configurations:
39+
//
40+
// - `full`: This setting will cause auto-import to always completely merge use-trees that share the
41+
// same path prefix while also merging inner trees that share the same path-prefix. This kind of
42+
// nesting is only supported in Rust versions later than 1.24.
43+
// - `last`: This setting will cause auto-import to merge use-trees as long as the resulting tree
44+
// will only contain a nesting of single segment paths at the very end.
45+
// - `none`: This setting will cause auto-import to never merge use-trees keeping them as simple
46+
// paths.
47+
//
48+
// In `VS Code` the configuration for this is `rust-analyzer.assist.importMergeBehaviour`.
49+
//
50+
// .Import Prefix
51+
//
52+
// The style of imports in the same crate is configurable through the `importPrefix` setting.
53+
// It has the following configurations:
54+
//
55+
// - `by_crate`: This setting will force paths to be always absolute, starting with the `crate`
56+
// prefix, unless the item is defined outside of the current crate.
57+
// - `by_self`: This setting will force paths that are relative to the current module to always
58+
// start with `self`. This will result in paths that always start with either `crate`, `self`,
59+
// `super` or an extern crate identifier.
60+
// - `plain`: This setting does not impose any restrictions in imports.
61+
//
62+
// In `VS Code` the configuration for this is `rust-analyzer.assist.importPrefix`.
63+
964
// Assist: auto_import
1065
//
1166
// If the name is unresolved, provides all possible imports for it.

0 commit comments

Comments
 (0)