diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-06-02 16:21:17 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-06-02 16:21:17 +0100 |
commit | 2022cfce44f7c3d82dd354abeb2d40b570fa3ef4 (patch) | |
tree | 2be11f2d6a4f1434c7e4b22290ce9922dde21760 /crates/ide_assists/src | |
parent | 9d7343719ded81805b977000b4ad805458fe69c8 (diff) | |
parent | 66a5fd375a60ec98c35acd9b4d5b03c6057aa36c (diff) |
Merge #9111
9111: fix: make "extract type alias" place extracted type alias outside of impl r=jonas-schievink a=jonas-schievink
bors r+
Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/ide_assists/src')
-rw-r--r-- | crates/ide_assists/src/handlers/extract_type_alias.rs | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/crates/ide_assists/src/handlers/extract_type_alias.rs b/crates/ide_assists/src/handlers/extract_type_alias.rs index 442a209b9..998e0de7b 100644 --- a/crates/ide_assists/src/handlers/extract_type_alias.rs +++ b/crates/ide_assists/src/handlers/extract_type_alias.rs | |||
@@ -25,7 +25,12 @@ pub(crate) fn extract_type_alias(acc: &mut Assists, ctx: &AssistContext) -> Opti | |||
25 | } | 25 | } |
26 | 26 | ||
27 | let node = ctx.find_node_at_range::<ast::Type>()?; | 27 | let node = ctx.find_node_at_range::<ast::Type>()?; |
28 | let insert = ctx.find_node_at_offset::<ast::Item>()?.syntax().text_range().start(); | 28 | let insert = ctx |
29 | .find_node_at_offset::<ast::Impl>() | ||
30 | .map(|imp| imp.syntax().clone()) | ||
31 | .or_else(|| ctx.find_node_at_offset::<ast::Item>().map(|item| item.syntax().clone()))? | ||
32 | .text_range() | ||
33 | .start(); | ||
29 | let target = node.syntax().text_range(); | 34 | let target = node.syntax().text_range(); |
30 | 35 | ||
31 | acc.add( | 36 | acc.add( |
@@ -146,4 +151,25 @@ struct S { | |||
146 | "#, | 151 | "#, |
147 | ); | 152 | ); |
148 | } | 153 | } |
154 | |||
155 | #[test] | ||
156 | fn extract_from_impl() { | ||
157 | // When invoked in an impl, extracted type alias should be placed next to the impl, not | ||
158 | // inside. | ||
159 | check_assist( | ||
160 | extract_type_alias, | ||
161 | r#" | ||
162 | impl S { | ||
163 | fn f() -> $0(u8, u8)$0 {} | ||
164 | } | ||
165 | "#, | ||
166 | r#" | ||
167 | type $0Type = (u8, u8); | ||
168 | |||
169 | impl S { | ||
170 | fn f() -> Type {} | ||
171 | } | ||
172 | "#, | ||
173 | ); | ||
174 | } | ||
149 | } | 175 | } |