diff options
-rw-r--r-- | crates/ra_assists/src/assists/add_import.rs | 21 | ||||
-rw-r--r-- | crates/ra_assists/src/doc_tests/generated.rs | 15 | ||||
-rw-r--r-- | docs/user/assists.md | 14 | ||||
-rw-r--r-- | docs/user/features.md | 20 |
4 files changed, 48 insertions, 22 deletions
diff --git a/crates/ra_assists/src/assists/add_import.rs b/crates/ra_assists/src/assists/add_import.rs index c522d6a5a..e87fae1af 100644 --- a/crates/ra_assists/src/assists/add_import.rs +++ b/crates/ra_assists/src/assists/add_import.rs | |||
@@ -1,5 +1,3 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
3 | use hir::{self, db::HirDatabase}; | 1 | use hir::{self, db::HirDatabase}; |
4 | use ra_syntax::{ | 2 | use ra_syntax::{ |
5 | ast::{self, NameOwner}, | 3 | ast::{self, NameOwner}, |
@@ -14,9 +12,9 @@ use crate::{ | |||
14 | AssistId, | 12 | AssistId, |
15 | }; | 13 | }; |
16 | 14 | ||
17 | // This function produces sequence of text edits into edit | 15 | /// This function produces sequence of text edits into edit |
18 | // to import the target path in the most appropriate scope given | 16 | /// to import the target path in the most appropriate scope given |
19 | // the cursor position | 17 | /// the cursor position |
20 | pub fn auto_import_text_edit( | 18 | pub fn auto_import_text_edit( |
21 | // Ideally the position of the cursor, used to | 19 | // Ideally the position of the cursor, used to |
22 | position: &SyntaxNode, | 20 | position: &SyntaxNode, |
@@ -39,6 +37,19 @@ pub fn auto_import_text_edit( | |||
39 | } | 37 | } |
40 | } | 38 | } |
41 | 39 | ||
40 | // Assist: add_import | ||
41 | // | ||
42 | // Adds a use statement for a given fully-qualified path. | ||
43 | // | ||
44 | // ``` | ||
45 | // fn process(map: std::collections::<|>HashMap<String, String>) {} | ||
46 | // ``` | ||
47 | // -> | ||
48 | // ``` | ||
49 | // use std::collections::HashMap; | ||
50 | // | ||
51 | // fn process(map: HashMap<String, String>) {} | ||
52 | // ``` | ||
42 | pub(crate) fn add_import(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | 53 | pub(crate) fn add_import(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { |
43 | let path: ast::Path = ctx.find_node_at_offset()?; | 54 | let path: ast::Path = ctx.find_node_at_offset()?; |
44 | // We don't want to mess with use statements | 55 | // We don't want to mess with use statements |
diff --git a/crates/ra_assists/src/doc_tests/generated.rs b/crates/ra_assists/src/doc_tests/generated.rs index ebe49aecf..1bee76f59 100644 --- a/crates/ra_assists/src/doc_tests/generated.rs +++ b/crates/ra_assists/src/doc_tests/generated.rs | |||
@@ -142,6 +142,21 @@ impl T for () { | |||
142 | } | 142 | } |
143 | 143 | ||
144 | #[test] | 144 | #[test] |
145 | fn doctest_add_import() { | ||
146 | check( | ||
147 | "add_import", | ||
148 | r#####" | ||
149 | fn process(map: std::collections::<|>HashMap<String, String>) {} | ||
150 | "#####, | ||
151 | r#####" | ||
152 | use std::collections::HashMap; | ||
153 | |||
154 | fn process(map: HashMap<String, String>) {} | ||
155 | "#####, | ||
156 | ) | ||
157 | } | ||
158 | |||
159 | #[test] | ||
145 | fn doctest_apply_demorgan() { | 160 | fn doctest_apply_demorgan() { |
146 | check( | 161 | check( |
147 | "apply_demorgan", | 162 | "apply_demorgan", |
diff --git a/docs/user/assists.md b/docs/user/assists.md index b1fe44d84..303353e74 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md | |||
@@ -136,6 +136,20 @@ impl T for () { | |||
136 | } | 136 | } |
137 | ``` | 137 | ``` |
138 | 138 | ||
139 | ## `add_import` | ||
140 | |||
141 | Adds a use statement for a given fully-qualified path. | ||
142 | |||
143 | ```rust | ||
144 | // BEFORE | ||
145 | fn process(map: std::collections::┃HashMap<String, String>) {} | ||
146 | |||
147 | // AFTER | ||
148 | use std::collections::HashMap; | ||
149 | |||
150 | fn process(map: HashMap<String, String>) {} | ||
151 | ``` | ||
152 | |||
139 | ## `apply_demorgan` | 153 | ## `apply_demorgan` |
140 | 154 | ||
141 | Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws). | 155 | Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws). |
diff --git a/docs/user/features.md b/docs/user/features.md index 7ae2ca7b6..c160dd70b 100644 --- a/docs/user/features.md +++ b/docs/user/features.md | |||
@@ -99,24 +99,10 @@ Stop `cargo watch` | |||
99 | 99 | ||
100 | ### Assists (Code Actions) | 100 | ### Assists (Code Actions) |
101 | 101 | ||
102 | These are triggered in a particular context via light bulb. We use custom code on | 102 | Assists, or code actions, are small local refactorings, available in a particular context. |
103 | the VS Code side to be able to position cursor. `<|>` signifies cursor | 103 | They are usually triggered by a shortcut or by clicking a light bulb icon in the editor. |
104 | 104 | ||
105 | See [assists.md](./assists.md) | 105 | See [assists.md](./assists.md) for the list of available assists. |
106 | |||
107 | - Import path | ||
108 | |||
109 | ```rust | ||
110 | // before: | ||
111 | impl std::fmt::Debug<|> for Foo { | ||
112 | } | ||
113 | |||
114 | // after: | ||
115 | use std::fmt::Debug; | ||
116 | |||
117 | impl Debug<|> for Foo { | ||
118 | } | ||
119 | ``` | ||
120 | 106 | ||
121 | ### Magic Completions | 107 | ### Magic Completions |
122 | 108 | ||