diff options
Diffstat (limited to 'crates/ide_assists/src')
4 files changed, 69 insertions, 8 deletions
diff --git a/crates/ide_assists/src/handlers/auto_import.rs b/crates/ide_assists/src/handlers/auto_import.rs index d4748ef3a..8df8b060d 100644 --- a/crates/ide_assists/src/handlers/auto_import.rs +++ b/crates/ide_assists/src/handlers/auto_import.rs | |||
@@ -103,8 +103,9 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()> | |||
103 | let scope = match scope.clone() { | 103 | let scope = match scope.clone() { |
104 | ImportScope::File(it) => ImportScope::File(builder.make_mut(it)), | 104 | ImportScope::File(it) => ImportScope::File(builder.make_mut(it)), |
105 | ImportScope::Module(it) => ImportScope::Module(builder.make_mut(it)), | 105 | ImportScope::Module(it) => ImportScope::Module(builder.make_mut(it)), |
106 | ImportScope::Block(it) => ImportScope::Block(builder.make_mut(it)), | ||
106 | }; | 107 | }; |
107 | insert_use(&scope, mod_path_to_ast(&import.import_path), ctx.config.insert_use); | 108 | insert_use(&scope, mod_path_to_ast(&import.import_path), &ctx.config.insert_use); |
108 | }, | 109 | }, |
109 | ); | 110 | ); |
110 | } | 111 | } |
@@ -994,4 +995,62 @@ const _: () = { | |||
994 | "#, | 995 | "#, |
995 | ); | 996 | ); |
996 | } | 997 | } |
998 | |||
999 | #[test] | ||
1000 | fn respects_cfg_attr() { | ||
1001 | check_assist( | ||
1002 | auto_import, | ||
1003 | r#" | ||
1004 | mod bar { | ||
1005 | pub struct Bar; | ||
1006 | } | ||
1007 | |||
1008 | #[cfg(test)] | ||
1009 | fn foo() { | ||
1010 | Bar$0 | ||
1011 | } | ||
1012 | "#, | ||
1013 | r#" | ||
1014 | mod bar { | ||
1015 | pub struct Bar; | ||
1016 | } | ||
1017 | |||
1018 | #[cfg(test)] | ||
1019 | fn foo() { | ||
1020 | use bar::Bar; | ||
1021 | |||
1022 | Bar | ||
1023 | } | ||
1024 | "#, | ||
1025 | ); | ||
1026 | } | ||
1027 | |||
1028 | #[test] | ||
1029 | fn respects_cfg_attr2() { | ||
1030 | check_assist( | ||
1031 | auto_import, | ||
1032 | r#" | ||
1033 | mod bar { | ||
1034 | pub struct Bar; | ||
1035 | } | ||
1036 | |||
1037 | #[cfg(test)] | ||
1038 | const FOO: Bar = { | ||
1039 | Bar$0 | ||
1040 | } | ||
1041 | "#, | ||
1042 | r#" | ||
1043 | mod bar { | ||
1044 | pub struct Bar; | ||
1045 | } | ||
1046 | |||
1047 | #[cfg(test)] | ||
1048 | const FOO: Bar = { | ||
1049 | use bar::Bar; | ||
1050 | |||
1051 | Bar | ||
1052 | } | ||
1053 | "#, | ||
1054 | ); | ||
1055 | } | ||
997 | } | 1056 | } |
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 6c6ff16c2..430710448 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 | |||
@@ -236,7 +236,7 @@ fn apply_references( | |||
236 | import: Option<(ImportScope, hir::ModPath)>, | 236 | import: Option<(ImportScope, hir::ModPath)>, |
237 | ) { | 237 | ) { |
238 | if let Some((scope, path)) = import { | 238 | if let Some((scope, path)) = import { |
239 | insert_use(&scope, mod_path_to_ast(&path), insert_use_cfg); | 239 | insert_use(&scope, mod_path_to_ast(&path), &insert_use_cfg); |
240 | } | 240 | } |
241 | // deep clone to prevent cycle | 241 | // deep clone to prevent cycle |
242 | let path = make::path_from_segments(iter::once(segment.clone_subtree()), false); | 242 | let path = make::path_from_segments(iter::once(segment.clone_subtree()), false); |
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 39f5eb4ff..26778ee74 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 | |||
@@ -32,7 +32,6 @@ pub(crate) fn replace_qualified_name_with_use( | |||
32 | 32 | ||
33 | let target = path.syntax().text_range(); | 33 | let target = path.syntax().text_range(); |
34 | let scope = ImportScope::find_insert_use_container_with_macros(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(); | ||
36 | acc.add( | 35 | acc.add( |
37 | AssistId("replace_qualified_name_with_use", AssistKind::RefactorRewrite), | 36 | AssistId("replace_qualified_name_with_use", AssistKind::RefactorRewrite), |
38 | "Replace qualified path with use", | 37 | "Replace qualified path with use", |
@@ -40,11 +39,13 @@ pub(crate) fn replace_qualified_name_with_use( | |||
40 | |builder| { | 39 | |builder| { |
41 | // Now that we've brought the name into scope, re-qualify all paths that could be | 40 | // Now that we've brought the name into scope, re-qualify all paths that could be |
42 | // affected (that is, all paths inside the node we added the `use` to). | 41 | // affected (that is, all paths inside the node we added the `use` to). |
43 | let syntax = builder.make_syntax_mut(syntax.clone()); | 42 | let scope = match scope { |
44 | if let Some(ref import_scope) = ImportScope::from(syntax.clone()) { | 43 | ImportScope::File(it) => ImportScope::File(builder.make_mut(it)), |
45 | shorten_paths(&syntax, &path.clone_for_update()); | 44 | ImportScope::Module(it) => ImportScope::Module(builder.make_mut(it)), |
46 | insert_use(import_scope, path, ctx.config.insert_use); | 45 | ImportScope::Block(it) => ImportScope::Block(builder.make_mut(it)), |
47 | } | 46 | }; |
47 | shorten_paths(scope.as_syntax_node(), &path.clone_for_update()); | ||
48 | insert_use(&scope, path, &ctx.config.insert_use); | ||
48 | }, | 49 | }, |
49 | ) | 50 | ) |
50 | } | 51 | } |
diff --git a/crates/ide_assists/src/tests.rs b/crates/ide_assists/src/tests.rs index 4e96ff1ec..841537c77 100644 --- a/crates/ide_assists/src/tests.rs +++ b/crates/ide_assists/src/tests.rs | |||
@@ -28,6 +28,7 @@ pub(crate) const TEST_CONFIG: AssistConfig = AssistConfig { | |||
28 | prefix_kind: hir::PrefixKind::Plain, | 28 | prefix_kind: hir::PrefixKind::Plain, |
29 | enforce_granularity: true, | 29 | enforce_granularity: true, |
30 | group: true, | 30 | group: true, |
31 | skip_glob_imports: true, | ||
31 | }, | 32 | }, |
32 | }; | 33 | }; |
33 | 34 | ||