1 use hir::db::HirDatabase;
3 TextUnit, AstNode, SyntaxKind::COLONCOLON,
8 use crate::{AssistCtx, Assist};
10 pub(crate) fn split_import(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
13 .find(|leaf| leaf.kind() == COLONCOLON)?;
14 let path = colon_colon.parent().and_then(ast::Path::cast)?;
15 let top_path = generate(Some(path), |it| it.parent_path()).last()?;
17 let use_tree = top_path.syntax().ancestors().find_map(ast::UseTree::cast);
18 if use_tree.is_none() {
22 let l_curly = colon_colon.range().end();
23 let r_curly = match top_path.syntax().parent().and_then(ast::UseTree::cast) {
24 Some(tree) => tree.syntax().range().end(),
25 None => top_path.syntax().range().end(),
28 ctx.build("split import", |edit| {
29 edit.insert(l_curly, "{");
30 edit.insert(r_curly, "}");
31 edit.set_cursor(l_curly + TextUnit::of_str("{"));
38 use crate::helpers::check_assist;
41 fn test_split_import() {
44 "use crate::<|>db::RootDatabase;",
45 "use crate::{<|>db::RootDatabase};",
50 fn split_import_works_with_trees() {
53 "use algo:<|>:visitor::{Visitor, visit}",
54 "use algo::{<|>visitor::{Visitor, visit}}",