File tree Expand file tree Collapse file tree 2 files changed +61
-6
lines changed Expand file tree Collapse file tree 2 files changed +61
-6
lines changed Original file line number Diff line number Diff line change @@ -149,6 +149,56 @@ pub use std::fmt::Display;
149
149
) ;
150
150
}
151
151
152
+ #[ test]
153
+ fn skip_pub_crate_pub ( ) {
154
+ check_assist_not_applicable (
155
+ merge_imports,
156
+ r"
157
+ pub(crate) use std::fmt<|>::Debug;
158
+ pub use std::fmt::Display;
159
+ " ,
160
+ ) ;
161
+ }
162
+
163
+ #[ test]
164
+ fn skip_pub_pub_crate ( ) {
165
+ check_assist_not_applicable (
166
+ merge_imports,
167
+ r"
168
+ pub use std::fmt<|>::Debug;
169
+ pub(crate) use std::fmt::Display;
170
+ " ,
171
+ ) ;
172
+ }
173
+
174
+ #[ test]
175
+ fn merge_pub ( ) {
176
+ check_assist (
177
+ merge_imports,
178
+ r"
179
+ pub use std::fmt<|>::Debug;
180
+ pub use std::fmt::Display;
181
+ " ,
182
+ r"
183
+ pub use std::fmt::{Debug, Display};
184
+ " ,
185
+ )
186
+ }
187
+
188
+ #[ test]
189
+ fn merge_pub_crate ( ) {
190
+ check_assist (
191
+ merge_imports,
192
+ r"
193
+ pub(crate) use std::fmt<|>::Debug;
194
+ pub(crate) use std::fmt::Display;
195
+ " ,
196
+ r"
197
+ pub(crate) use std::fmt::{Debug, Display};
198
+ " ,
199
+ )
200
+ }
201
+
152
202
#[ test]
153
203
fn test_merge_nested ( ) {
154
204
check_assist (
Original file line number Diff line number Diff line change @@ -138,18 +138,23 @@ pub(crate) fn insert_use(
138
138
algo:: insert_children ( scope. as_syntax_node ( ) , insert_position, to_insert)
139
139
}
140
140
141
+ fn eq_visibility ( vis0 : Option < ast:: Visibility > , vis1 : Option < ast:: Visibility > ) -> bool {
142
+ match ( vis0, vis1) {
143
+ ( None , None ) => true ,
144
+ // FIXME: Don't use the string representation to check for equality
145
+ // spaces inside of the node would break this comparison
146
+ ( Some ( vis0) , Some ( vis1) ) => vis0. to_string ( ) == vis1. to_string ( ) ,
147
+ _ => false ,
148
+ }
149
+ }
150
+
141
151
pub ( crate ) fn try_merge_imports (
142
152
old : & ast:: Use ,
143
153
new : & ast:: Use ,
144
154
merge_behaviour : MergeBehaviour ,
145
155
) -> Option < ast:: Use > {
146
156
// don't merge imports with different visibilities
147
- if old
148
- . visibility ( )
149
- . and_then ( |vis| vis. pub_token ( ) )
150
- . or_else ( || new. visibility ( ) . and_then ( |vis| vis. pub_token ( ) ) )
151
- . is_some ( )
152
- {
157
+ if !eq_visibility ( old. visibility ( ) , new. visibility ( ) ) {
153
158
return None ;
154
159
}
155
160
let old_tree = old. use_tree ( ) ?;
You can’t perform that action at this time.
0 commit comments