diff options
author | Aleksey Kladov <[email protected]> | 2019-09-25 12:29:41 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-09-25 12:29:41 +0100 |
commit | f32081fa185b3a9df021f277c2c27fbd123d0951 (patch) | |
tree | 0032bc2f09dc0f323ae5b77bbc2b7d891173f398 /crates/ra_assists/src/split_import.rs | |
parent | d9b4835625ac96c7628e2ef66ef6e26cc48d231f (diff) |
move assists to subdir
Diffstat (limited to 'crates/ra_assists/src/split_import.rs')
-rw-r--r-- | crates/ra_assists/src/split_import.rs | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/crates/ra_assists/src/split_import.rs b/crates/ra_assists/src/split_import.rs deleted file mode 100644 index 2c1edddb9..000000000 --- a/crates/ra_assists/src/split_import.rs +++ /dev/null | |||
@@ -1,61 +0,0 @@ | |||
1 | use std::iter::successors; | ||
2 | |||
3 | use hir::db::HirDatabase; | ||
4 | use ra_syntax::{ast, AstNode, TextUnit, T}; | ||
5 | |||
6 | use crate::{Assist, AssistCtx, AssistId}; | ||
7 | |||
8 | pub(crate) fn split_import(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | ||
9 | let colon_colon = ctx.token_at_offset().find(|leaf| leaf.kind() == T![::])?; | ||
10 | let path = ast::Path::cast(colon_colon.parent())?; | ||
11 | let top_path = successors(Some(path), |it| it.parent_path()).last()?; | ||
12 | |||
13 | let use_tree = top_path.syntax().ancestors().find_map(ast::UseTree::cast); | ||
14 | if use_tree.is_none() { | ||
15 | return None; | ||
16 | } | ||
17 | |||
18 | let l_curly = colon_colon.text_range().end(); | ||
19 | let r_curly = match top_path.syntax().parent().and_then(ast::UseTree::cast) { | ||
20 | Some(tree) => tree.syntax().text_range().end(), | ||
21 | None => top_path.syntax().text_range().end(), | ||
22 | }; | ||
23 | |||
24 | ctx.add_action(AssistId("split_import"), "split import", |edit| { | ||
25 | edit.target(colon_colon.text_range()); | ||
26 | edit.insert(l_curly, "{"); | ||
27 | edit.insert(r_curly, "}"); | ||
28 | edit.set_cursor(l_curly + TextUnit::of_str("{")); | ||
29 | }); | ||
30 | |||
31 | ctx.build() | ||
32 | } | ||
33 | |||
34 | #[cfg(test)] | ||
35 | mod tests { | ||
36 | use super::*; | ||
37 | use crate::helpers::{check_assist, check_assist_target}; | ||
38 | |||
39 | #[test] | ||
40 | fn test_split_import() { | ||
41 | check_assist( | ||
42 | split_import, | ||
43 | "use crate::<|>db::RootDatabase;", | ||
44 | "use crate::{<|>db::RootDatabase};", | ||
45 | ) | ||
46 | } | ||
47 | |||
48 | #[test] | ||
49 | fn split_import_works_with_trees() { | ||
50 | check_assist( | ||
51 | split_import, | ||
52 | "use algo:<|>:visitor::{Visitor, visit}", | ||
53 | "use algo::{<|>visitor::{Visitor, visit}}", | ||
54 | ) | ||
55 | } | ||
56 | |||
57 | #[test] | ||
58 | fn split_import_target() { | ||
59 | check_assist_target(split_import, "use algo::<|>visitor::{Visitor, visit}", "::"); | ||
60 | } | ||
61 | } | ||