diff options
author | Lukas Wirth <[email protected]> | 2021-04-20 18:28:18 +0100 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2021-04-20 18:34:43 +0100 |
commit | b290cd578260f307e872a95f971e5a7c656a80ed (patch) | |
tree | 25e94bc1e043745d2b6bed3efa2ffe699a3cee7c /crates | |
parent | 2c8f1b5c301a5d7a84d3c74a9fc48ef76cd11bd6 (diff) |
Add cov_marks to insert_use tests
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ide_assists/src/handlers/auto_import.rs | 2 | ||||
-rw-r--r-- | crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs | 55 | ||||
-rw-r--r-- | crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs | 18 | ||||
-rw-r--r-- | crates/ide_completion/src/completions/flyimport.rs | 2 | ||||
-rw-r--r-- | crates/ide_completion/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ide_db/src/helpers/insert_use.rs | 17 | ||||
-rw-r--r-- | crates/ide_db/src/helpers/insert_use/tests.rs | 23 |
7 files changed, 77 insertions, 42 deletions
diff --git a/crates/ide_assists/src/handlers/auto_import.rs b/crates/ide_assists/src/handlers/auto_import.rs index 6db2d2edd..a454a2af3 100644 --- a/crates/ide_assists/src/handlers/auto_import.rs +++ b/crates/ide_assists/src/handlers/auto_import.rs | |||
@@ -93,7 +93,7 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()> | |||
93 | 93 | ||
94 | let range = ctx.sema.original_range(&syntax_under_caret).range; | 94 | let range = ctx.sema.original_range(&syntax_under_caret).range; |
95 | let group_label = group_label(import_assets.import_candidate()); | 95 | let group_label = group_label(import_assets.import_candidate()); |
96 | let scope = ImportScope::find_insert_use_container(&syntax_under_caret, &ctx.sema)?; | 96 | let scope = ImportScope::find_insert_use_container_with_macros(&syntax_under_caret, &ctx.sema)?; |
97 | for import in proposed_imports { | 97 | for import in proposed_imports { |
98 | acc.add_group( | 98 | acc.add_group( |
99 | &group_label, | 99 | &group_label, |
diff --git a/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs index 1f800f82b..66f274fa7 100644 --- a/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs | |||
@@ -5,7 +5,7 @@ use hir::{Module, ModuleDef, Name, Variant}; | |||
5 | use ide_db::{ | 5 | use ide_db::{ |
6 | defs::Definition, | 6 | defs::Definition, |
7 | helpers::{ | 7 | helpers::{ |
8 | insert_use::{insert_use, ImportScope}, | 8 | insert_use::{insert_use, ImportScope, InsertUseConfig}, |
9 | mod_path_to_ast, | 9 | mod_path_to_ast, |
10 | }, | 10 | }, |
11 | search::FileReference, | 11 | search::FileReference, |
@@ -79,16 +79,8 @@ pub(crate) fn extract_struct_from_enum_variant( | |||
79 | &variant_hir_name, | 79 | &variant_hir_name, |
80 | references, | 80 | references, |
81 | ); | 81 | ); |
82 | processed.into_iter().for_each(|(segment, node, import)| { | 82 | processed.into_iter().for_each(|(path, node, import)| { |
83 | if let Some((scope, path)) = import { | 83 | apply_references(ctx.config.insert_use, path, node, import) |
84 | insert_use(&scope, mod_path_to_ast(&path), ctx.config.insert_use); | ||
85 | } | ||
86 | ted::insert_raw( | ||
87 | ted::Position::before(segment.syntax()), | ||
88 | make::path_from_text(&format!("{}", segment)).clone_for_update().syntax(), | ||
89 | ); | ||
90 | ted::insert_raw(ted::Position::before(segment.syntax()), make::token(T!['('])); | ||
91 | ted::insert_raw(ted::Position::after(&node), make::token(T![')'])); | ||
92 | }); | 84 | }); |
93 | } | 85 | } |
94 | builder.edit_file(ctx.frange.file_id); | 86 | builder.edit_file(ctx.frange.file_id); |
@@ -103,21 +95,12 @@ pub(crate) fn extract_struct_from_enum_variant( | |||
103 | &variant_hir_name, | 95 | &variant_hir_name, |
104 | references, | 96 | references, |
105 | ); | 97 | ); |
106 | processed.into_iter().for_each(|(segment, node, import)| { | 98 | processed.into_iter().for_each(|(path, node, import)| { |
107 | if let Some((scope, path)) = import { | 99 | apply_references(ctx.config.insert_use, path, node, import) |
108 | insert_use(&scope, mod_path_to_ast(&path), ctx.config.insert_use); | ||
109 | } | ||
110 | ted::insert_raw( | ||
111 | ted::Position::before(segment.syntax()), | ||
112 | make::path_from_text(&format!("{}", segment)).clone_for_update().syntax(), | ||
113 | ); | ||
114 | ted::insert_raw(ted::Position::before(segment.syntax()), make::token(T!['('])); | ||
115 | ted::insert_raw(ted::Position::after(&node), make::token(T![')'])); | ||
116 | }); | 100 | }); |
117 | } | 101 | } |
118 | 102 | ||
119 | let def = create_struct_def(variant_name.clone(), &field_list, enum_ast.visibility()) | 103 | let def = create_struct_def(variant_name.clone(), &field_list, enum_ast.visibility()); |
120 | .unwrap(); | ||
121 | let start_offset = &variant.parent_enum().syntax().clone(); | 104 | let start_offset = &variant.parent_enum().syntax().clone(); |
122 | ted::insert_raw(ted::Position::before(start_offset), def.syntax()); | 105 | ted::insert_raw(ted::Position::before(start_offset), def.syntax()); |
123 | ted::insert_raw(ted::Position::before(start_offset), &make::tokens::blank_line()); | 106 | ted::insert_raw(ted::Position::before(start_offset), &make::tokens::blank_line()); |
@@ -167,7 +150,7 @@ fn create_struct_def( | |||
167 | variant_name: ast::Name, | 150 | variant_name: ast::Name, |
168 | field_list: &Either<ast::RecordFieldList, ast::TupleFieldList>, | 151 | field_list: &Either<ast::RecordFieldList, ast::TupleFieldList>, |
169 | visibility: Option<ast::Visibility>, | 152 | visibility: Option<ast::Visibility>, |
170 | ) -> Option<ast::Struct> { | 153 | ) -> ast::Struct { |
171 | let pub_vis = Some(make::visibility_pub()); | 154 | let pub_vis = Some(make::visibility_pub()); |
172 | let field_list = match field_list { | 155 | let field_list = match field_list { |
173 | Either::Left(field_list) => { | 156 | Either::Left(field_list) => { |
@@ -184,7 +167,7 @@ fn create_struct_def( | |||
184 | .into(), | 167 | .into(), |
185 | }; | 168 | }; |
186 | 169 | ||
187 | Some(make::struct_(visibility, variant_name, None, field_list).clone_for_update()) | 170 | make::struct_(visibility, variant_name, None, field_list).clone_for_update() |
188 | } | 171 | } |
189 | 172 | ||
190 | fn update_variant(variant: &ast::Variant) -> Option<()> { | 173 | fn update_variant(variant: &ast::Variant) -> Option<()> { |
@@ -199,6 +182,23 @@ fn update_variant(variant: &ast::Variant) -> Option<()> { | |||
199 | Some(()) | 182 | Some(()) |
200 | } | 183 | } |
201 | 184 | ||
185 | fn apply_references( | ||
186 | insert_use_cfg: InsertUseConfig, | ||
187 | segment: ast::PathSegment, | ||
188 | node: SyntaxNode, | ||
189 | import: Option<(ImportScope, hir::ModPath)>, | ||
190 | ) { | ||
191 | if let Some((scope, path)) = import { | ||
192 | insert_use(&scope, mod_path_to_ast(&path), insert_use_cfg); | ||
193 | } | ||
194 | ted::insert_raw( | ||
195 | ted::Position::before(segment.syntax()), | ||
196 | make::path_from_text(&format!("{}", segment)).clone_for_update().syntax(), | ||
197 | ); | ||
198 | ted::insert_raw(ted::Position::before(segment.syntax()), make::token(T!['('])); | ||
199 | ted::insert_raw(ted::Position::after(&node), make::token(T![')'])); | ||
200 | } | ||
201 | |||
202 | fn process_references( | 202 | fn process_references( |
203 | ctx: &AssistContext, | 203 | ctx: &AssistContext, |
204 | visited_modules: &mut FxHashSet<Module>, | 204 | visited_modules: &mut FxHashSet<Module>, |
@@ -207,6 +207,8 @@ fn process_references( | |||
207 | variant_hir_name: &Name, | 207 | variant_hir_name: &Name, |
208 | refs: Vec<FileReference>, | 208 | refs: Vec<FileReference>, |
209 | ) -> Vec<(ast::PathSegment, SyntaxNode, Option<(ImportScope, hir::ModPath)>)> { | 209 | ) -> Vec<(ast::PathSegment, SyntaxNode, Option<(ImportScope, hir::ModPath)>)> { |
210 | // we have to recollect here eagerly as we are about to edit the tree we need to calculate the changes | ||
211 | // and corresponding nodes up front | ||
210 | refs.into_iter() | 212 | refs.into_iter() |
211 | .flat_map(|reference| { | 213 | .flat_map(|reference| { |
212 | let (segment, scope_node, module) = | 214 | let (segment, scope_node, module) = |
@@ -220,8 +222,7 @@ fn process_references( | |||
220 | if let Some(mut mod_path) = mod_path { | 222 | if let Some(mut mod_path) = mod_path { |
221 | mod_path.pop_segment(); | 223 | mod_path.pop_segment(); |
222 | mod_path.push_segment(variant_hir_name.clone()); | 224 | mod_path.push_segment(variant_hir_name.clone()); |
223 | // uuuh this wont properly work, find_insert_use_container ascends macros so we might a get new syntax node??? | 225 | let scope = ImportScope::find_insert_use_container(&scope_node)?; |
224 | let scope = ImportScope::find_insert_use_container(&scope_node, &ctx.sema)?; | ||
225 | visited_modules.insert(module); | 226 | visited_modules.insert(module); |
226 | return Some((segment, scope_node, Some((scope, mod_path)))); | 227 | return Some((segment, scope_node, Some((scope, mod_path)))); |
227 | } | 228 | } |
diff --git a/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs b/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs index 2f2306fcc..99ba79860 100644 --- a/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs +++ b/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs | |||
@@ -31,7 +31,7 @@ pub(crate) fn replace_qualified_name_with_use( | |||
31 | } | 31 | } |
32 | 32 | ||
33 | let target = path.syntax().text_range(); | 33 | let target = path.syntax().text_range(); |
34 | let scope = ImportScope::find_insert_use_container(path.syntax(), &ctx.sema)?; | 34 | let scope = ImportScope::find_insert_use_container_with_macros(path.syntax(), &ctx.sema)?; |
35 | let syntax = scope.as_syntax_node(); | 35 | let syntax = scope.as_syntax_node(); |
36 | acc.add( | 36 | acc.add( |
37 | AssistId("replace_qualified_name_with_use", AssistKind::RefactorRewrite), | 37 | AssistId("replace_qualified_name_with_use", AssistKind::RefactorRewrite), |
@@ -42,15 +42,15 @@ pub(crate) fn replace_qualified_name_with_use( | |||
42 | // affected (that is, all paths inside the node we added the `use` to). | 42 | // affected (that is, all paths inside the node we added the `use` to). |
43 | let syntax = builder.make_mut(syntax.clone()); | 43 | let syntax = builder.make_mut(syntax.clone()); |
44 | if let Some(ref import_scope) = ImportScope::from(syntax.clone()) { | 44 | if let Some(ref import_scope) = ImportScope::from(syntax.clone()) { |
45 | insert_use(import_scope, path.clone(), ctx.config.insert_use); | 45 | shorten_paths(&syntax, &path.clone_for_update()); |
46 | insert_use(import_scope, path, ctx.config.insert_use); | ||
46 | } | 47 | } |
47 | shorten_paths(syntax.clone(), &path.clone_for_update()); | ||
48 | }, | 48 | }, |
49 | ) | 49 | ) |
50 | } | 50 | } |
51 | 51 | ||
52 | /// Adds replacements to `re` that shorten `path` in all descendants of `node`. | 52 | /// Adds replacements to `re` that shorten `path` in all descendants of `node`. |
53 | fn shorten_paths(node: SyntaxNode, path: &ast::Path) { | 53 | fn shorten_paths(node: &SyntaxNode, path: &ast::Path) { |
54 | for child in node.children() { | 54 | for child in node.children() { |
55 | match_ast! { | 55 | match_ast! { |
56 | match child { | 56 | match child { |
@@ -59,14 +59,10 @@ fn shorten_paths(node: SyntaxNode, path: &ast::Path) { | |||
59 | ast::Use(_it) => continue, | 59 | ast::Use(_it) => continue, |
60 | // Don't descend into submodules, they don't have the same `use` items in scope. | 60 | // Don't descend into submodules, they don't have the same `use` items in scope. |
61 | ast::Module(_it) => continue, | 61 | ast::Module(_it) => continue, |
62 | 62 | ast::Path(p) => if maybe_replace_path(p.clone(), path.clone()).is_none() { | |
63 | ast::Path(p) => { | 63 | shorten_paths(p.syntax(), path); |
64 | match maybe_replace_path(p.clone(), path.clone()) { | ||
65 | Some(()) => {}, | ||
66 | None => shorten_paths(p.syntax().clone(), path), | ||
67 | } | ||
68 | }, | 64 | }, |
69 | _ => shorten_paths(child, path), | 65 | _ => shorten_paths(&child, path), |
70 | } | 66 | } |
71 | } | 67 | } |
72 | } | 68 | } |
diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs index 8e211ae1e..9d5b61562 100644 --- a/crates/ide_completion/src/completions/flyimport.rs +++ b/crates/ide_completion/src/completions/flyimport.rs | |||
@@ -132,7 +132,7 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) | |||
132 | 132 | ||
133 | let user_input_lowercased = potential_import_name.to_lowercase(); | 133 | let user_input_lowercased = potential_import_name.to_lowercase(); |
134 | let import_assets = import_assets(ctx, potential_import_name)?; | 134 | let import_assets = import_assets(ctx, potential_import_name)?; |
135 | let import_scope = ImportScope::find_insert_use_container( | 135 | let import_scope = ImportScope::find_insert_use_container_with_macros( |
136 | position_for_import(ctx, Some(import_assets.import_candidate()))?, | 136 | position_for_import(ctx, Some(import_assets.import_candidate()))?, |
137 | &ctx.sema, | 137 | &ctx.sema, |
138 | )?; | 138 | )?; |
diff --git a/crates/ide_completion/src/lib.rs b/crates/ide_completion/src/lib.rs index 6f3d5c5c5..e32633565 100644 --- a/crates/ide_completion/src/lib.rs +++ b/crates/ide_completion/src/lib.rs | |||
@@ -179,7 +179,7 @@ pub fn resolve_completion_edits( | |||
179 | ) -> Option<Vec<TextEdit>> { | 179 | ) -> Option<Vec<TextEdit>> { |
180 | let ctx = CompletionContext::new(db, position, config)?; | 180 | let ctx = CompletionContext::new(db, position, config)?; |
181 | let position_for_import = position_for_import(&ctx, None)?; | 181 | let position_for_import = position_for_import(&ctx, None)?; |
182 | let scope = ImportScope::find_insert_use_container(position_for_import, &ctx.sema)?; | 182 | let scope = ImportScope::find_insert_use_container_with_macros(position_for_import, &ctx.sema)?; |
183 | 183 | ||
184 | let current_module = ctx.sema.scope(position_for_import).module()?; | 184 | let current_module = ctx.sema.scope(position_for_import).module()?; |
185 | let current_crate = current_module.krate(); | 185 | let current_crate = current_module.krate(); |
diff --git a/crates/ide_db/src/helpers/insert_use.rs b/crates/ide_db/src/helpers/insert_use.rs index 498d76f72..a43504a27 100644 --- a/crates/ide_db/src/helpers/insert_use.rs +++ b/crates/ide_db/src/helpers/insert_use.rs | |||
@@ -38,13 +38,18 @@ impl ImportScope { | |||
38 | } | 38 | } |
39 | 39 | ||
40 | /// Determines the containing syntax node in which to insert a `use` statement affecting `position`. | 40 | /// Determines the containing syntax node in which to insert a `use` statement affecting `position`. |
41 | pub fn find_insert_use_container( | 41 | pub fn find_insert_use_container_with_macros( |
42 | position: &SyntaxNode, | 42 | position: &SyntaxNode, |
43 | sema: &Semantics<'_, RootDatabase>, | 43 | sema: &Semantics<'_, RootDatabase>, |
44 | ) -> Option<Self> { | 44 | ) -> Option<Self> { |
45 | sema.ancestors_with_macros(position.clone()).find_map(Self::from) | 45 | sema.ancestors_with_macros(position.clone()).find_map(Self::from) |
46 | } | 46 | } |
47 | 47 | ||
48 | /// Determines the containing syntax node in which to insert a `use` statement affecting `position`. | ||
49 | pub fn find_insert_use_container(position: &SyntaxNode) -> Option<Self> { | ||
50 | std::iter::successors(Some(position.clone()), SyntaxNode::parent).find_map(Self::from) | ||
51 | } | ||
52 | |||
48 | pub fn as_syntax_node(&self) -> &SyntaxNode { | 53 | pub fn as_syntax_node(&self) -> &SyntaxNode { |
49 | match self { | 54 | match self { |
50 | ImportScope::File(file) => file.syntax(), | 55 | ImportScope::File(file) => file.syntax(), |
@@ -446,8 +451,10 @@ fn insert_use_( | |||
446 | 451 | ||
447 | if !group_imports { | 452 | if !group_imports { |
448 | if let Some((_, _, node)) = path_node_iter.last() { | 453 | if let Some((_, _, node)) = path_node_iter.last() { |
454 | cov_mark::hit!(insert_no_grouping_last); | ||
449 | ted::insert(ted::Position::after(node), use_item.syntax()); | 455 | ted::insert(ted::Position::after(node), use_item.syntax()); |
450 | } else { | 456 | } else { |
457 | cov_mark::hit!(insert_no_grouping_last2); | ||
451 | ted::insert(ted::Position::first_child_of(scope_syntax), make::tokens::blank_line()); | 458 | ted::insert(ted::Position::first_child_of(scope_syntax), make::tokens::blank_line()); |
452 | ted::insert(ted::Position::first_child_of(scope_syntax), use_item.syntax()); | 459 | ted::insert(ted::Position::first_child_of(scope_syntax), use_item.syntax()); |
453 | } | 460 | } |
@@ -471,10 +478,12 @@ fn insert_use_( | |||
471 | }); | 478 | }); |
472 | 479 | ||
473 | if let Some((.., node)) = post_insert { | 480 | if let Some((.., node)) = post_insert { |
481 | cov_mark::hit!(insert_group); | ||
474 | // insert our import before that element | 482 | // insert our import before that element |
475 | return ted::insert(ted::Position::before(node), use_item.syntax()); | 483 | return ted::insert(ted::Position::before(node), use_item.syntax()); |
476 | } | 484 | } |
477 | if let Some(node) = last { | 485 | if let Some(node) = last { |
486 | cov_mark::hit!(insert_group_last); | ||
478 | // there is no element after our new import, so append it to the end of the group | 487 | // there is no element after our new import, so append it to the end of the group |
479 | return ted::insert(ted::Position::after(node), use_item.syntax()); | 488 | return ted::insert(ted::Position::after(node), use_item.syntax()); |
480 | } | 489 | } |
@@ -487,6 +496,7 @@ fn insert_use_( | |||
487 | .inspect(|(.., node)| last = Some(node.clone())) | 496 | .inspect(|(.., node)| last = Some(node.clone())) |
488 | .find(|(p, ..)| ImportGroup::new(p) > group); | 497 | .find(|(p, ..)| ImportGroup::new(p) > group); |
489 | if let Some((.., node)) = post_group { | 498 | if let Some((.., node)) = post_group { |
499 | cov_mark::hit!(insert_group_new_group); | ||
490 | ted::insert(ted::Position::before(&node), use_item.syntax()); | 500 | ted::insert(ted::Position::before(&node), use_item.syntax()); |
491 | if let Some(node) = algo::non_trivia_sibling(node.into(), Direction::Prev) { | 501 | if let Some(node) = algo::non_trivia_sibling(node.into(), Direction::Prev) { |
492 | ted::insert(ted::Position::after(node), make::tokens::single_newline()); | 502 | ted::insert(ted::Position::after(node), make::tokens::single_newline()); |
@@ -495,6 +505,7 @@ fn insert_use_( | |||
495 | } | 505 | } |
496 | // there is no such group, so append after the last one | 506 | // there is no such group, so append after the last one |
497 | if let Some(node) = last { | 507 | if let Some(node) = last { |
508 | cov_mark::hit!(insert_group_no_group); | ||
498 | ted::insert(ted::Position::after(&node), use_item.syntax()); | 509 | ted::insert(ted::Position::after(&node), use_item.syntax()); |
499 | ted::insert(ted::Position::after(node), make::tokens::single_newline()); | 510 | ted::insert(ted::Position::after(node), make::tokens::single_newline()); |
500 | return; | 511 | return; |
@@ -508,22 +519,26 @@ fn insert_use_( | |||
508 | }) | 519 | }) |
509 | .last() | 520 | .last() |
510 | { | 521 | { |
522 | cov_mark::hit!(insert_group_empty_inner_attr); | ||
511 | ted::insert(ted::Position::after(&last_inner_element), use_item.syntax()); | 523 | ted::insert(ted::Position::after(&last_inner_element), use_item.syntax()); |
512 | ted::insert(ted::Position::after(last_inner_element), make::tokens::single_newline()); | 524 | ted::insert(ted::Position::after(last_inner_element), make::tokens::single_newline()); |
513 | return; | 525 | return; |
514 | } | 526 | } |
515 | match scope { | 527 | match scope { |
516 | ImportScope::File(_) => { | 528 | ImportScope::File(_) => { |
529 | cov_mark::hit!(insert_group_empty_file); | ||
517 | ted::insert(ted::Position::first_child_of(scope_syntax), make::tokens::blank_line()); | 530 | ted::insert(ted::Position::first_child_of(scope_syntax), make::tokens::blank_line()); |
518 | ted::insert(ted::Position::first_child_of(scope_syntax), use_item.syntax()) | 531 | ted::insert(ted::Position::first_child_of(scope_syntax), use_item.syntax()) |
519 | } | 532 | } |
520 | // don't insert the imports before the item list's opening curly brace | 533 | // don't insert the imports before the item list's opening curly brace |
521 | ImportScope::Module(item_list) => match item_list.l_curly_token() { | 534 | ImportScope::Module(item_list) => match item_list.l_curly_token() { |
522 | Some(b) => { | 535 | Some(b) => { |
536 | cov_mark::hit!(insert_group_empty_module); | ||
523 | ted::insert(ted::Position::after(&b), make::tokens::single_newline()); | 537 | ted::insert(ted::Position::after(&b), make::tokens::single_newline()); |
524 | ted::insert(ted::Position::after(&b), use_item.syntax()); | 538 | ted::insert(ted::Position::after(&b), use_item.syntax()); |
525 | } | 539 | } |
526 | None => { | 540 | None => { |
541 | // This should never happens, broken module syntax node | ||
527 | ted::insert( | 542 | ted::insert( |
528 | ted::Position::first_child_of(scope_syntax), | 543 | ted::Position::first_child_of(scope_syntax), |
529 | make::tokens::blank_line(), | 544 | make::tokens::blank_line(), |
diff --git a/crates/ide_db/src/helpers/insert_use/tests.rs b/crates/ide_db/src/helpers/insert_use/tests.rs index a3464d606..048c213e2 100644 --- a/crates/ide_db/src/helpers/insert_use/tests.rs +++ b/crates/ide_db/src/helpers/insert_use/tests.rs | |||
@@ -5,6 +5,7 @@ use test_utils::assert_eq_text; | |||
5 | 5 | ||
6 | #[test] | 6 | #[test] |
7 | fn insert_not_group() { | 7 | fn insert_not_group() { |
8 | cov_mark::check!(insert_no_grouping_last); | ||
8 | check( | 9 | check( |
9 | "use external_crate2::bar::A", | 10 | "use external_crate2::bar::A", |
10 | r" | 11 | r" |
@@ -27,6 +28,21 @@ use external_crate2::bar::A;", | |||
27 | } | 28 | } |
28 | 29 | ||
29 | #[test] | 30 | #[test] |
31 | fn insert_not_group_empty() { | ||
32 | cov_mark::check!(insert_no_grouping_last2); | ||
33 | check( | ||
34 | "use external_crate2::bar::A", | ||
35 | r"", | ||
36 | r"use external_crate2::bar::A; | ||
37 | |||
38 | ", | ||
39 | None, | ||
40 | false, | ||
41 | false, | ||
42 | ); | ||
43 | } | ||
44 | |||
45 | #[test] | ||
30 | fn insert_existing() { | 46 | fn insert_existing() { |
31 | check_full("std::fs", "use std::fs;", "use std::fs;") | 47 | check_full("std::fs", "use std::fs;", "use std::fs;") |
32 | } | 48 | } |
@@ -65,6 +81,7 @@ fn insert_start_indent() { | |||
65 | 81 | ||
66 | #[test] | 82 | #[test] |
67 | fn insert_middle() { | 83 | fn insert_middle() { |
84 | cov_mark::check!(insert_group); | ||
68 | check_none( | 85 | check_none( |
69 | "std::bar::EE", | 86 | "std::bar::EE", |
70 | r" | 87 | r" |
@@ -101,6 +118,7 @@ fn insert_middle_indent() { | |||
101 | 118 | ||
102 | #[test] | 119 | #[test] |
103 | fn insert_end() { | 120 | fn insert_end() { |
121 | cov_mark::check!(insert_group_last); | ||
104 | check_none( | 122 | check_none( |
105 | "std::bar::ZZ", | 123 | "std::bar::ZZ", |
106 | r" | 124 | r" |
@@ -199,6 +217,7 @@ fn insert_first_matching_group() { | |||
199 | 217 | ||
200 | #[test] | 218 | #[test] |
201 | fn insert_missing_group_std() { | 219 | fn insert_missing_group_std() { |
220 | cov_mark::check!(insert_group_new_group); | ||
202 | check_none( | 221 | check_none( |
203 | "std::fmt", | 222 | "std::fmt", |
204 | r" | 223 | r" |
@@ -214,6 +233,7 @@ fn insert_missing_group_std() { | |||
214 | 233 | ||
215 | #[test] | 234 | #[test] |
216 | fn insert_missing_group_self() { | 235 | fn insert_missing_group_self() { |
236 | cov_mark::check!(insert_group_no_group); | ||
217 | check_none( | 237 | check_none( |
218 | "self::fmt", | 238 | "self::fmt", |
219 | r" | 239 | r" |
@@ -240,6 +260,7 @@ fn main() {}", | |||
240 | 260 | ||
241 | #[test] | 261 | #[test] |
242 | fn insert_empty_file() { | 262 | fn insert_empty_file() { |
263 | cov_mark::check!(insert_group_empty_file); | ||
243 | // empty files will get two trailing newlines | 264 | // empty files will get two trailing newlines |
244 | // this is due to the test case insert_no_imports above | 265 | // this is due to the test case insert_no_imports above |
245 | check_full( | 266 | check_full( |
@@ -253,6 +274,7 @@ fn insert_empty_file() { | |||
253 | 274 | ||
254 | #[test] | 275 | #[test] |
255 | fn insert_empty_module() { | 276 | fn insert_empty_module() { |
277 | cov_mark::check!(insert_group_empty_module); | ||
256 | check( | 278 | check( |
257 | "foo::bar", | 279 | "foo::bar", |
258 | "mod x {}", | 280 | "mod x {}", |
@@ -267,6 +289,7 @@ fn insert_empty_module() { | |||
267 | 289 | ||
268 | #[test] | 290 | #[test] |
269 | fn insert_after_inner_attr() { | 291 | fn insert_after_inner_attr() { |
292 | cov_mark::check!(insert_group_empty_inner_attr); | ||
270 | check_full( | 293 | check_full( |
271 | "foo::bar", | 294 | "foo::bar", |
272 | r"#![allow(unused_imports)]", | 295 | r"#![allow(unused_imports)]", |