diff options
author | Lukas Wirth <[email protected]> | 2020-09-05 15:15:16 +0100 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2020-09-05 15:15:16 +0100 |
commit | 74b755d23366bcfa5437df25b023f5a2451e1ea6 (patch) | |
tree | 064d14350b07990caabce384e4529ccbbe7f50b7 /crates/assists/src/utils/insert_use.rs | |
parent | 7ccb198af81d8f33ccad66a417ae6529f91df625 (diff) |
Allow merge_imports assists to merge imports of equal visibility
Diffstat (limited to 'crates/assists/src/utils/insert_use.rs')
-rw-r--r-- | crates/assists/src/utils/insert_use.rs | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/crates/assists/src/utils/insert_use.rs b/crates/assists/src/utils/insert_use.rs index a920e12c5..98553b2e0 100644 --- a/crates/assists/src/utils/insert_use.rs +++ b/crates/assists/src/utils/insert_use.rs | |||
@@ -138,18 +138,23 @@ pub(crate) fn insert_use( | |||
138 | algo::insert_children(scope.as_syntax_node(), insert_position, to_insert) | 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 | pub(crate) fn try_merge_imports( | 151 | pub(crate) fn try_merge_imports( |
142 | old: &ast::Use, | 152 | old: &ast::Use, |
143 | new: &ast::Use, | 153 | new: &ast::Use, |
144 | merge_behaviour: MergeBehaviour, | 154 | merge_behaviour: MergeBehaviour, |
145 | ) -> Option<ast::Use> { | 155 | ) -> Option<ast::Use> { |
146 | // don't merge imports with different visibilities | 156 | // don't merge imports with different visibilities |
147 | if old | 157 | if !eq_visibility(old.visibility(), new.visibility()) { |
148 | .visibility() | ||
149 | .and_then(|vis| vis.pub_token()) | ||
150 | .or_else(|| new.visibility().and_then(|vis| vis.pub_token())) | ||
151 | .is_some() | ||
152 | { | ||
153 | return None; | 158 | return None; |
154 | } | 159 | } |
155 | let old_tree = old.use_tree()?; | 160 | let old_tree = old.use_tree()?; |