diff options
Diffstat (limited to 'crates/assists')
59 files changed, 1923 insertions, 1021 deletions
diff --git a/crates/assists/Cargo.toml b/crates/assists/Cargo.toml index 3fd8327d6..ed8ad666f 100644 --- a/crates/assists/Cargo.toml +++ b/crates/assists/Cargo.toml | |||
@@ -11,7 +11,7 @@ doctest = false | |||
11 | 11 | ||
12 | [dependencies] | 12 | [dependencies] |
13 | rustc-hash = "1.1.0" | 13 | rustc-hash = "1.1.0" |
14 | itertools = "0.9.0" | 14 | itertools = "0.10.0" |
15 | either = "1.6.1" | 15 | either = "1.6.1" |
16 | 16 | ||
17 | stdx = { path = "../stdx", version = "0.0.0" } | 17 | stdx = { path = "../stdx", version = "0.0.0" } |
diff --git a/crates/assists/src/assist_config.rs b/crates/assists/src/assist_config.rs index c458d9054..4fe8ea761 100644 --- a/crates/assists/src/assist_config.rs +++ b/crates/assists/src/assist_config.rs | |||
@@ -4,8 +4,7 @@ | |||
4 | //! module, and we use to statically check that we only produce snippet | 4 | //! module, and we use to statically check that we only produce snippet |
5 | //! assists if we are allowed to. | 5 | //! assists if we are allowed to. |
6 | 6 | ||
7 | use hir::PrefixKind; | 7 | use ide_db::helpers::{insert_use::MergeBehavior, SnippetCap}; |
8 | use ide_db::helpers::insert_use::MergeBehavior; | ||
9 | 8 | ||
10 | use crate::AssistKind; | 9 | use crate::AssistKind; |
11 | 10 | ||
@@ -16,35 +15,8 @@ pub struct AssistConfig { | |||
16 | pub insert_use: InsertUseConfig, | 15 | pub insert_use: InsertUseConfig, |
17 | } | 16 | } |
18 | 17 | ||
19 | impl AssistConfig { | ||
20 | pub fn allow_snippets(&mut self, yes: bool) { | ||
21 | self.snippet_cap = if yes { Some(SnippetCap { _private: () }) } else { None } | ||
22 | } | ||
23 | } | ||
24 | |||
25 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
26 | pub struct SnippetCap { | ||
27 | _private: (), | ||
28 | } | ||
29 | |||
30 | impl Default for AssistConfig { | ||
31 | fn default() -> Self { | ||
32 | AssistConfig { | ||
33 | snippet_cap: Some(SnippetCap { _private: () }), | ||
34 | allowed: None, | ||
35 | insert_use: InsertUseConfig::default(), | ||
36 | } | ||
37 | } | ||
38 | } | ||
39 | |||
40 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] | 18 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
41 | pub struct InsertUseConfig { | 19 | pub struct InsertUseConfig { |
42 | pub merge: Option<MergeBehavior>, | 20 | pub merge: Option<MergeBehavior>, |
43 | pub prefix_kind: PrefixKind, | 21 | pub prefix_kind: hir::PrefixKind, |
44 | } | ||
45 | |||
46 | impl Default for InsertUseConfig { | ||
47 | fn default() -> Self { | ||
48 | InsertUseConfig { merge: Some(MergeBehavior::Full), prefix_kind: PrefixKind::Plain } | ||
49 | } | ||
50 | } | 22 | } |
diff --git a/crates/assists/src/assist_context.rs b/crates/assists/src/assist_context.rs index 4f59d39a9..91cc63427 100644 --- a/crates/assists/src/assist_context.rs +++ b/crates/assists/src/assist_context.rs | |||
@@ -4,7 +4,10 @@ use std::mem; | |||
4 | 4 | ||
5 | use algo::find_covering_element; | 5 | use algo::find_covering_element; |
6 | use hir::Semantics; | 6 | use hir::Semantics; |
7 | use ide_db::base_db::{AnchoredPathBuf, FileId, FileRange}; | 7 | use ide_db::{ |
8 | base_db::{AnchoredPathBuf, FileId, FileRange}, | ||
9 | helpers::SnippetCap, | ||
10 | }; | ||
8 | use ide_db::{ | 11 | use ide_db::{ |
9 | label::Label, | 12 | label::Label, |
10 | source_change::{FileSystemEdit, SourceChange, SourceFileEdit}, | 13 | source_change::{FileSystemEdit, SourceChange, SourceFileEdit}, |
@@ -17,10 +20,7 @@ use syntax::{ | |||
17 | }; | 20 | }; |
18 | use text_edit::{TextEdit, TextEditBuilder}; | 21 | use text_edit::{TextEdit, TextEditBuilder}; |
19 | 22 | ||
20 | use crate::{ | 23 | use crate::{assist_config::AssistConfig, Assist, AssistId, AssistKind, GroupLabel}; |
21 | assist_config::{AssistConfig, SnippetCap}, | ||
22 | Assist, AssistId, AssistKind, GroupLabel, | ||
23 | }; | ||
24 | 24 | ||
25 | /// `AssistContext` allows to apply an assist or check if it could be applied. | 25 | /// `AssistContext` allows to apply an assist or check if it could be applied. |
26 | /// | 26 | /// |
diff --git a/crates/assists/src/ast_transform.rs b/crates/assists/src/ast_transform.rs index da94e9987..4a3ed7783 100644 --- a/crates/assists/src/ast_transform.rs +++ b/crates/assists/src/ast_transform.rs | |||
@@ -204,7 +204,8 @@ impl<'a> AstTransform<'a> for QualifyPaths<'a> { | |||
204 | } | 204 | } |
205 | PathResolution::Local(_) | 205 | PathResolution::Local(_) |
206 | | PathResolution::TypeParam(_) | 206 | | PathResolution::TypeParam(_) |
207 | | PathResolution::SelfType(_) => None, | 207 | | PathResolution::SelfType(_) |
208 | | PathResolution::ConstParam(_) => None, | ||
208 | PathResolution::Macro(_) => None, | 209 | PathResolution::Macro(_) => None, |
209 | PathResolution::AssocItem(_) => None, | 210 | PathResolution::AssocItem(_) => None, |
210 | } | 211 | } |
diff --git a/crates/assists/src/handlers/add_explicit_type.rs b/crates/assists/src/handlers/add_explicit_type.rs index 563cbf505..cb1548cef 100644 --- a/crates/assists/src/handlers/add_explicit_type.rs +++ b/crates/assists/src/handlers/add_explicit_type.rs | |||
@@ -12,7 +12,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; | |||
12 | // | 12 | // |
13 | // ``` | 13 | // ``` |
14 | // fn main() { | 14 | // fn main() { |
15 | // let x<|> = 92; | 15 | // let x$0 = 92; |
16 | // } | 16 | // } |
17 | // ``` | 17 | // ``` |
18 | // -> | 18 | // -> |
@@ -81,21 +81,17 @@ mod tests { | |||
81 | 81 | ||
82 | #[test] | 82 | #[test] |
83 | fn add_explicit_type_target() { | 83 | fn add_explicit_type_target() { |
84 | check_assist_target(add_explicit_type, "fn f() { let a<|> = 1; }", "a"); | 84 | check_assist_target(add_explicit_type, "fn f() { let a$0 = 1; }", "a"); |
85 | } | 85 | } |
86 | 86 | ||
87 | #[test] | 87 | #[test] |
88 | fn add_explicit_type_works_for_simple_expr() { | 88 | fn add_explicit_type_works_for_simple_expr() { |
89 | check_assist(add_explicit_type, "fn f() { let a<|> = 1; }", "fn f() { let a: i32 = 1; }"); | 89 | check_assist(add_explicit_type, "fn f() { let a$0 = 1; }", "fn f() { let a: i32 = 1; }"); |
90 | } | 90 | } |
91 | 91 | ||
92 | #[test] | 92 | #[test] |
93 | fn add_explicit_type_works_for_underscore() { | 93 | fn add_explicit_type_works_for_underscore() { |
94 | check_assist( | 94 | check_assist(add_explicit_type, "fn f() { let a$0: _ = 1; }", "fn f() { let a: i32 = 1; }"); |
95 | add_explicit_type, | ||
96 | "fn f() { let a<|>: _ = 1; }", | ||
97 | "fn f() { let a: i32 = 1; }", | ||
98 | ); | ||
99 | } | 95 | } |
100 | 96 | ||
101 | #[test] | 97 | #[test] |
@@ -109,7 +105,7 @@ mod tests { | |||
109 | } | 105 | } |
110 | 106 | ||
111 | fn f() { | 107 | fn f() { |
112 | let a<|>: Option<_> = Option::Some(1); | 108 | let a$0: Option<_> = Option::Some(1); |
113 | }"#, | 109 | }"#, |
114 | r#" | 110 | r#" |
115 | enum Option<T> { | 111 | enum Option<T> { |
@@ -127,7 +123,7 @@ mod tests { | |||
127 | fn add_explicit_type_works_for_macro_call() { | 123 | fn add_explicit_type_works_for_macro_call() { |
128 | check_assist( | 124 | check_assist( |
129 | add_explicit_type, | 125 | add_explicit_type, |
130 | r"macro_rules! v { () => {0u64} } fn f() { let a<|> = v!(); }", | 126 | r"macro_rules! v { () => {0u64} } fn f() { let a$0 = v!(); }", |
131 | r"macro_rules! v { () => {0u64} } fn f() { let a: u64 = v!(); }", | 127 | r"macro_rules! v { () => {0u64} } fn f() { let a: u64 = v!(); }", |
132 | ); | 128 | ); |
133 | } | 129 | } |
@@ -136,31 +132,31 @@ mod tests { | |||
136 | fn add_explicit_type_works_for_macro_call_recursive() { | 132 | fn add_explicit_type_works_for_macro_call_recursive() { |
137 | check_assist( | 133 | check_assist( |
138 | add_explicit_type, | 134 | add_explicit_type, |
139 | r#"macro_rules! u { () => {0u64} } macro_rules! v { () => {u!()} } fn f() { let a<|> = v!(); }"#, | 135 | r#"macro_rules! u { () => {0u64} } macro_rules! v { () => {u!()} } fn f() { let a$0 = v!(); }"#, |
140 | r#"macro_rules! u { () => {0u64} } macro_rules! v { () => {u!()} } fn f() { let a: u64 = v!(); }"#, | 136 | r#"macro_rules! u { () => {0u64} } macro_rules! v { () => {u!()} } fn f() { let a: u64 = v!(); }"#, |
141 | ); | 137 | ); |
142 | } | 138 | } |
143 | 139 | ||
144 | #[test] | 140 | #[test] |
145 | fn add_explicit_type_not_applicable_if_ty_not_inferred() { | 141 | fn add_explicit_type_not_applicable_if_ty_not_inferred() { |
146 | check_assist_not_applicable(add_explicit_type, "fn f() { let a<|> = None; }"); | 142 | check_assist_not_applicable(add_explicit_type, "fn f() { let a$0 = None; }"); |
147 | } | 143 | } |
148 | 144 | ||
149 | #[test] | 145 | #[test] |
150 | fn add_explicit_type_not_applicable_if_ty_already_specified() { | 146 | fn add_explicit_type_not_applicable_if_ty_already_specified() { |
151 | check_assist_not_applicable(add_explicit_type, "fn f() { let a<|>: i32 = 1; }"); | 147 | check_assist_not_applicable(add_explicit_type, "fn f() { let a$0: i32 = 1; }"); |
152 | } | 148 | } |
153 | 149 | ||
154 | #[test] | 150 | #[test] |
155 | fn add_explicit_type_not_applicable_if_specified_ty_is_tuple() { | 151 | fn add_explicit_type_not_applicable_if_specified_ty_is_tuple() { |
156 | check_assist_not_applicable(add_explicit_type, "fn f() { let a<|>: (i32, i32) = (3, 4); }"); | 152 | check_assist_not_applicable(add_explicit_type, "fn f() { let a$0: (i32, i32) = (3, 4); }"); |
157 | } | 153 | } |
158 | 154 | ||
159 | #[test] | 155 | #[test] |
160 | fn add_explicit_type_not_applicable_if_cursor_after_equals() { | 156 | fn add_explicit_type_not_applicable_if_cursor_after_equals() { |
161 | check_assist_not_applicable( | 157 | check_assist_not_applicable( |
162 | add_explicit_type, | 158 | add_explicit_type, |
163 | "fn f() {let a =<|> match 1 {2 => 3, 3 => 5};}", | 159 | "fn f() {let a =$0 match 1 {2 => 3, 3 => 5};}", |
164 | ) | 160 | ) |
165 | } | 161 | } |
166 | 162 | ||
@@ -168,7 +164,7 @@ mod tests { | |||
168 | fn add_explicit_type_not_applicable_if_cursor_before_let() { | 164 | fn add_explicit_type_not_applicable_if_cursor_before_let() { |
169 | check_assist_not_applicable( | 165 | check_assist_not_applicable( |
170 | add_explicit_type, | 166 | add_explicit_type, |
171 | "fn f() <|>{let a = match 1 {2 => 3, 3 => 5};}", | 167 | "fn f() $0{let a = match 1 {2 => 3, 3 => 5};}", |
172 | ) | 168 | ) |
173 | } | 169 | } |
174 | 170 | ||
@@ -178,7 +174,7 @@ mod tests { | |||
178 | add_explicit_type, | 174 | add_explicit_type, |
179 | r#" | 175 | r#" |
180 | fn main() { | 176 | fn main() { |
181 | let multiply_by_two<|> = |i| i * 3; | 177 | let multiply_by_two$0 = |i| i * 3; |
182 | let six = multiply_by_two(2); | 178 | let six = multiply_by_two(2); |
183 | }"#, | 179 | }"#, |
184 | ) | 180 | ) |
@@ -195,7 +191,7 @@ struct Test<K, T = u8> { | |||
195 | } | 191 | } |
196 | 192 | ||
197 | fn main() { | 193 | fn main() { |
198 | let test<|> = Test { t: 23u8, k: 33 }; | 194 | let test$0 = Test { t: 23u8, k: 33 }; |
199 | }"#, | 195 | }"#, |
200 | r#" | 196 | r#" |
201 | struct Test<K, T = u8> { | 197 | struct Test<K, T = u8> { |
diff --git a/crates/assists/src/handlers/add_missing_impl_members.rs b/crates/assists/src/handlers/add_missing_impl_members.rs index 7df05b841..63cea754d 100644 --- a/crates/assists/src/handlers/add_missing_impl_members.rs +++ b/crates/assists/src/handlers/add_missing_impl_members.rs | |||
@@ -20,7 +20,7 @@ use crate::{ | |||
20 | // fn bar(&self) {} | 20 | // fn bar(&self) {} |
21 | // } | 21 | // } |
22 | // | 22 | // |
23 | // impl Trait<u32> for () {<|> | 23 | // impl Trait<u32> for () {$0 |
24 | // | 24 | // |
25 | // } | 25 | // } |
26 | // ``` | 26 | // ``` |
@@ -63,7 +63,7 @@ pub(crate) fn add_missing_impl_members(acc: &mut Assists, ctx: &AssistContext) - | |||
63 | // | 63 | // |
64 | // impl Trait for () { | 64 | // impl Trait for () { |
65 | // type X = (); | 65 | // type X = (); |
66 | // fn foo(&self) {}<|> | 66 | // fn foo(&self) {}$0 |
67 | // | 67 | // |
68 | // } | 68 | // } |
69 | // ``` | 69 | // ``` |
@@ -166,7 +166,7 @@ struct S; | |||
166 | 166 | ||
167 | impl Foo for S { | 167 | impl Foo for S { |
168 | fn bar(&self) {} | 168 | fn bar(&self) {} |
169 | <|> | 169 | $0 |
170 | }"#, | 170 | }"#, |
171 | r#" | 171 | r#" |
172 | trait Foo { | 172 | trait Foo { |
@@ -214,7 +214,7 @@ struct S; | |||
214 | 214 | ||
215 | impl Foo for S { | 215 | impl Foo for S { |
216 | fn bar(&self) {} | 216 | fn bar(&self) {} |
217 | <|> | 217 | $0 |
218 | }"#, | 218 | }"#, |
219 | r#" | 219 | r#" |
220 | trait Foo { | 220 | trait Foo { |
@@ -242,7 +242,7 @@ impl Foo for S { | |||
242 | r#" | 242 | r#" |
243 | trait Foo { fn foo(&self); } | 243 | trait Foo { fn foo(&self); } |
244 | struct S; | 244 | struct S; |
245 | impl Foo for S { <|> }"#, | 245 | impl Foo for S { $0 }"#, |
246 | r#" | 246 | r#" |
247 | trait Foo { fn foo(&self); } | 247 | trait Foo { fn foo(&self); } |
248 | struct S; | 248 | struct S; |
@@ -261,7 +261,7 @@ impl Foo for S { | |||
261 | r#" | 261 | r#" |
262 | trait Foo { fn foo(&self); } | 262 | trait Foo { fn foo(&self); } |
263 | struct S; | 263 | struct S; |
264 | impl Foo for S<|>"#, | 264 | impl Foo for S$0"#, |
265 | r#" | 265 | r#" |
266 | trait Foo { fn foo(&self); } | 266 | trait Foo { fn foo(&self); } |
267 | struct S; | 267 | struct S; |
@@ -280,7 +280,7 @@ impl Foo for S { | |||
280 | r#" | 280 | r#" |
281 | trait Foo<T> { fn foo(&self, t: T) -> &T; } | 281 | trait Foo<T> { fn foo(&self, t: T) -> &T; } |
282 | struct S; | 282 | struct S; |
283 | impl Foo<u32> for S { <|> }"#, | 283 | impl Foo<u32> for S { $0 }"#, |
284 | r#" | 284 | r#" |
285 | trait Foo<T> { fn foo(&self, t: T) -> &T; } | 285 | trait Foo<T> { fn foo(&self, t: T) -> &T; } |
286 | struct S; | 286 | struct S; |
@@ -299,7 +299,7 @@ impl Foo<u32> for S { | |||
299 | r#" | 299 | r#" |
300 | trait Foo<T> { fn foo(&self, t: T) -> &T; } | 300 | trait Foo<T> { fn foo(&self, t: T) -> &T; } |
301 | struct S; | 301 | struct S; |
302 | impl<U> Foo<U> for S { <|> }"#, | 302 | impl<U> Foo<U> for S { $0 }"#, |
303 | r#" | 303 | r#" |
304 | trait Foo<T> { fn foo(&self, t: T) -> &T; } | 304 | trait Foo<T> { fn foo(&self, t: T) -> &T; } |
305 | struct S; | 305 | struct S; |
@@ -318,7 +318,7 @@ impl<U> Foo<U> for S { | |||
318 | r#" | 318 | r#" |
319 | trait Foo { fn foo(&self); } | 319 | trait Foo { fn foo(&self); } |
320 | struct S; | 320 | struct S; |
321 | impl Foo for S {}<|>"#, | 321 | impl Foo for S {}$0"#, |
322 | r#" | 322 | r#" |
323 | trait Foo { fn foo(&self); } | 323 | trait Foo { fn foo(&self); } |
324 | struct S; | 324 | struct S; |
@@ -340,7 +340,7 @@ mod foo { | |||
340 | trait Foo { fn foo(&self, bar: Bar); } | 340 | trait Foo { fn foo(&self, bar: Bar); } |
341 | } | 341 | } |
342 | struct S; | 342 | struct S; |
343 | impl foo::Foo for S { <|> }"#, | 343 | impl foo::Foo for S { $0 }"#, |
344 | r#" | 344 | r#" |
345 | mod foo { | 345 | mod foo { |
346 | pub struct Bar; | 346 | pub struct Bar; |
@@ -370,7 +370,7 @@ mod foo { | |||
370 | use foo::bar; | 370 | use foo::bar; |
371 | 371 | ||
372 | struct S; | 372 | struct S; |
373 | impl bar::Foo for S { <|> }"#, | 373 | impl bar::Foo for S { $0 }"#, |
374 | r#" | 374 | r#" |
375 | mod foo { | 375 | mod foo { |
376 | pub mod bar { | 376 | pub mod bar { |
@@ -400,7 +400,7 @@ mod foo { | |||
400 | trait Foo { fn foo(&self, bar: Bar<u32>); } | 400 | trait Foo { fn foo(&self, bar: Bar<u32>); } |
401 | } | 401 | } |
402 | struct S; | 402 | struct S; |
403 | impl foo::Foo for S { <|> }"#, | 403 | impl foo::Foo for S { $0 }"#, |
404 | r#" | 404 | r#" |
405 | mod foo { | 405 | mod foo { |
406 | pub struct Bar<T>; | 406 | pub struct Bar<T>; |
@@ -425,7 +425,7 @@ mod foo { | |||
425 | trait Foo<T> { fn foo(&self, bar: Bar<T>); } | 425 | trait Foo<T> { fn foo(&self, bar: Bar<T>); } |
426 | } | 426 | } |
427 | struct S; | 427 | struct S; |
428 | impl foo::Foo<u32> for S { <|> }"#, | 428 | impl foo::Foo<u32> for S { $0 }"#, |
429 | r#" | 429 | r#" |
430 | mod foo { | 430 | mod foo { |
431 | pub struct Bar<T>; | 431 | pub struct Bar<T>; |
@@ -452,7 +452,7 @@ mod foo { | |||
452 | } | 452 | } |
453 | struct Param; | 453 | struct Param; |
454 | struct S; | 454 | struct S; |
455 | impl foo::Foo<Param> for S { <|> }"#, | 455 | impl foo::Foo<Param> for S { $0 }"#, |
456 | r#" | 456 | r#" |
457 | mod foo { | 457 | mod foo { |
458 | trait Foo<T> { fn foo(&self, bar: T); } | 458 | trait Foo<T> { fn foo(&self, bar: T); } |
@@ -479,7 +479,7 @@ mod foo { | |||
479 | trait Foo { fn foo(&self, bar: Bar<u32>::Assoc); } | 479 | trait Foo { fn foo(&self, bar: Bar<u32>::Assoc); } |
480 | } | 480 | } |
481 | struct S; | 481 | struct S; |
482 | impl foo::Foo for S { <|> }"#, | 482 | impl foo::Foo for S { $0 }"#, |
483 | r#" | 483 | r#" |
484 | mod foo { | 484 | mod foo { |
485 | pub struct Bar<T>; | 485 | pub struct Bar<T>; |
@@ -506,7 +506,7 @@ mod foo { | |||
506 | trait Foo { fn foo(&self, bar: Bar<Baz>); } | 506 | trait Foo { fn foo(&self, bar: Bar<Baz>); } |
507 | } | 507 | } |
508 | struct S; | 508 | struct S; |
509 | impl foo::Foo for S { <|> }"#, | 509 | impl foo::Foo for S { $0 }"#, |
510 | r#" | 510 | r#" |
511 | mod foo { | 511 | mod foo { |
512 | pub struct Bar<T>; | 512 | pub struct Bar<T>; |
@@ -532,7 +532,7 @@ mod foo { | |||
532 | trait Foo { fn foo(&self, bar: dyn Fn(u32) -> i32); } | 532 | trait Foo { fn foo(&self, bar: dyn Fn(u32) -> i32); } |
533 | } | 533 | } |
534 | struct S; | 534 | struct S; |
535 | impl foo::Foo for S { <|> }"#, | 535 | impl foo::Foo for S { $0 }"#, |
536 | r#" | 536 | r#" |
537 | mod foo { | 537 | mod foo { |
538 | pub trait Fn<Args> { type Output; } | 538 | pub trait Fn<Args> { type Output; } |
@@ -554,7 +554,7 @@ impl foo::Foo for S { | |||
554 | r#" | 554 | r#" |
555 | trait Foo; | 555 | trait Foo; |
556 | struct S; | 556 | struct S; |
557 | impl Foo for S { <|> }"#, | 557 | impl Foo for S { $0 }"#, |
558 | ) | 558 | ) |
559 | } | 559 | } |
560 | 560 | ||
@@ -568,7 +568,7 @@ trait Foo { | |||
568 | fn valid(some: u32) -> bool { false } | 568 | fn valid(some: u32) -> bool { false } |
569 | } | 569 | } |
570 | struct S; | 570 | struct S; |
571 | impl Foo for S { <|> }"#, | 571 | impl Foo for S { $0 }"#, |
572 | ) | 572 | ) |
573 | } | 573 | } |
574 | 574 | ||
@@ -586,7 +586,7 @@ trait Foo { | |||
586 | fn foo(&self); | 586 | fn foo(&self); |
587 | } | 587 | } |
588 | struct S; | 588 | struct S; |
589 | impl Foo for S {}<|>"#, | 589 | impl Foo for S {}$0"#, |
590 | r#" | 590 | r#" |
591 | #[doc(alias = "test alias")] | 591 | #[doc(alias = "test alias")] |
592 | trait Foo { | 592 | trait Foo { |
@@ -621,7 +621,7 @@ trait Foo { | |||
621 | fn foo(some: u32) -> bool; | 621 | fn foo(some: u32) -> bool; |
622 | } | 622 | } |
623 | struct S; | 623 | struct S; |
624 | impl Foo for S { <|> }"#, | 624 | impl Foo for S { $0 }"#, |
625 | r#" | 625 | r#" |
626 | trait Foo { | 626 | trait Foo { |
627 | type Output; | 627 | type Output; |
@@ -648,7 +648,7 @@ trait Foo<T = Self> { | |||
648 | } | 648 | } |
649 | 649 | ||
650 | struct S; | 650 | struct S; |
651 | impl Foo for S { <|> }"#, | 651 | impl Foo for S { $0 }"#, |
652 | r#" | 652 | r#" |
653 | trait Foo<T = Self> { | 653 | trait Foo<T = Self> { |
654 | fn bar(&self, other: &T); | 654 | fn bar(&self, other: &T); |
@@ -673,7 +673,7 @@ trait Foo<T1, T2 = Self> { | |||
673 | } | 673 | } |
674 | 674 | ||
675 | struct S<T>; | 675 | struct S<T>; |
676 | impl Foo<T> for S<T> { <|> }"#, | 676 | impl Foo<T> for S<T> { $0 }"#, |
677 | r#" | 677 | r#" |
678 | trait Foo<T1, T2 = Self> { | 678 | trait Foo<T1, T2 = Self> { |
679 | fn bar(&self, this: &T1, that: &T2); | 679 | fn bar(&self, this: &T1, that: &T2); |
@@ -697,7 +697,7 @@ trait Tr { | |||
697 | type Ty: Copy + 'static; | 697 | type Ty: Copy + 'static; |
698 | } | 698 | } |
699 | 699 | ||
700 | impl Tr for ()<|> { | 700 | impl Tr for ()$0 { |
701 | }"#, | 701 | }"#, |
702 | r#" | 702 | r#" |
703 | trait Tr { | 703 | trait Tr { |
@@ -719,7 +719,7 @@ trait Tr { | |||
719 | fn foo(); | 719 | fn foo(); |
720 | } | 720 | } |
721 | 721 | ||
722 | impl Tr for ()<|> { | 722 | impl Tr for ()$0 { |
723 | +++ | 723 | +++ |
724 | }"#, | 724 | }"#, |
725 | r#" | 725 | r#" |
@@ -745,7 +745,7 @@ trait Tr { | |||
745 | fn foo(); | 745 | fn foo(); |
746 | } | 746 | } |
747 | 747 | ||
748 | impl Tr for ()<|> { | 748 | impl Tr for ()$0 { |
749 | // very important | 749 | // very important |
750 | }"#, | 750 | }"#, |
751 | r#" | 751 | r#" |
@@ -771,7 +771,7 @@ trait Test { | |||
771 | fn foo(&self, x: crate) | 771 | fn foo(&self, x: crate) |
772 | } | 772 | } |
773 | impl Test for () { | 773 | impl Test for () { |
774 | <|> | 774 | $0 |
775 | } | 775 | } |
776 | "#, | 776 | "#, |
777 | r#" | 777 | r#" |
@@ -796,7 +796,7 @@ trait Foo<BAR> { | |||
796 | fn foo(&self, bar: BAR); | 796 | fn foo(&self, bar: BAR); |
797 | } | 797 | } |
798 | impl Foo for () { | 798 | impl Foo for () { |
799 | <|> | 799 | $0 |
800 | } | 800 | } |
801 | "#, | 801 | "#, |
802 | r#" | 802 | r#" |
diff --git a/crates/assists/src/handlers/add_turbo_fish.rs b/crates/assists/src/handlers/add_turbo_fish.rs index 1f486c013..8e9ea4fad 100644 --- a/crates/assists/src/handlers/add_turbo_fish.rs +++ b/crates/assists/src/handlers/add_turbo_fish.rs | |||
@@ -14,7 +14,7 @@ use crate::{ | |||
14 | // ``` | 14 | // ``` |
15 | // fn make<T>() -> T { todo!() } | 15 | // fn make<T>() -> T { todo!() } |
16 | // fn main() { | 16 | // fn main() { |
17 | // let x = make<|>(); | 17 | // let x = make$0(); |
18 | // } | 18 | // } |
19 | // ``` | 19 | // ``` |
20 | // -> | 20 | // -> |
@@ -77,7 +77,7 @@ mod tests { | |||
77 | r#" | 77 | r#" |
78 | fn make<T>() -> T {} | 78 | fn make<T>() -> T {} |
79 | fn main() { | 79 | fn main() { |
80 | make<|>(); | 80 | make$0(); |
81 | } | 81 | } |
82 | "#, | 82 | "#, |
83 | r#" | 83 | r#" |
@@ -97,7 +97,7 @@ fn main() { | |||
97 | r#" | 97 | r#" |
98 | fn make<T>() -> T {} | 98 | fn make<T>() -> T {} |
99 | fn main() { | 99 | fn main() { |
100 | make()<|>; | 100 | make()$0; |
101 | } | 101 | } |
102 | "#, | 102 | "#, |
103 | r#" | 103 | r#" |
@@ -119,7 +119,7 @@ impl S { | |||
119 | fn make<T>(&self) -> T {} | 119 | fn make<T>(&self) -> T {} |
120 | } | 120 | } |
121 | fn main() { | 121 | fn main() { |
122 | S.make<|>(); | 122 | S.make$0(); |
123 | } | 123 | } |
124 | "#, | 124 | "#, |
125 | r#" | 125 | r#" |
@@ -142,7 +142,7 @@ fn main() { | |||
142 | r#" | 142 | r#" |
143 | fn make<T>() -> T {} | 143 | fn make<T>() -> T {} |
144 | fn main() { | 144 | fn main() { |
145 | make<|>::<()>(); | 145 | make$0::<()>(); |
146 | } | 146 | } |
147 | "#, | 147 | "#, |
148 | ); | 148 | ); |
@@ -156,7 +156,7 @@ fn main() { | |||
156 | r#" | 156 | r#" |
157 | fn make() -> () {} | 157 | fn make() -> () {} |
158 | fn main() { | 158 | fn main() { |
159 | make<|>(); | 159 | make$0(); |
160 | } | 160 | } |
161 | "#, | 161 | "#, |
162 | ); | 162 | ); |
diff --git a/crates/assists/src/handlers/apply_demorgan.rs b/crates/assists/src/handlers/apply_demorgan.rs index 1a6fdafda..ed4d11455 100644 --- a/crates/assists/src/handlers/apply_demorgan.rs +++ b/crates/assists/src/handlers/apply_demorgan.rs | |||
@@ -12,7 +12,7 @@ use crate::{utils::invert_boolean_expression, AssistContext, AssistId, AssistKin | |||
12 | // | 12 | // |
13 | // ``` | 13 | // ``` |
14 | // fn main() { | 14 | // fn main() { |
15 | // if x != 4 ||<|> !y {} | 15 | // if x != 4 ||$0 !y {} |
16 | // } | 16 | // } |
17 | // ``` | 17 | // ``` |
18 | // -> | 18 | // -> |
@@ -68,26 +68,26 @@ mod tests { | |||
68 | 68 | ||
69 | #[test] | 69 | #[test] |
70 | fn demorgan_turns_and_into_or() { | 70 | fn demorgan_turns_and_into_or() { |
71 | check_assist(apply_demorgan, "fn f() { !x &&<|> !x }", "fn f() { !(x || x) }") | 71 | check_assist(apply_demorgan, "fn f() { !x &&$0 !x }", "fn f() { !(x || x) }") |
72 | } | 72 | } |
73 | 73 | ||
74 | #[test] | 74 | #[test] |
75 | fn demorgan_turns_or_into_and() { | 75 | fn demorgan_turns_or_into_and() { |
76 | check_assist(apply_demorgan, "fn f() { !x ||<|> !x }", "fn f() { !(x && x) }") | 76 | check_assist(apply_demorgan, "fn f() { !x ||$0 !x }", "fn f() { !(x && x) }") |
77 | } | 77 | } |
78 | 78 | ||
79 | #[test] | 79 | #[test] |
80 | fn demorgan_removes_inequality() { | 80 | fn demorgan_removes_inequality() { |
81 | check_assist(apply_demorgan, "fn f() { x != x ||<|> !x }", "fn f() { !(x == x && x) }") | 81 | check_assist(apply_demorgan, "fn f() { x != x ||$0 !x }", "fn f() { !(x == x && x) }") |
82 | } | 82 | } |
83 | 83 | ||
84 | #[test] | 84 | #[test] |
85 | fn demorgan_general_case() { | 85 | fn demorgan_general_case() { |
86 | check_assist(apply_demorgan, "fn f() { x ||<|> x }", "fn f() { !(!x && !x) }") | 86 | check_assist(apply_demorgan, "fn f() { x ||$0 x }", "fn f() { !(!x && !x) }") |
87 | } | 87 | } |
88 | 88 | ||
89 | #[test] | 89 | #[test] |
90 | fn demorgan_doesnt_apply_with_cursor_not_on_op() { | 90 | fn demorgan_doesnt_apply_with_cursor_not_on_op() { |
91 | check_assist_not_applicable(apply_demorgan, "fn f() { <|> !x || !x }") | 91 | check_assist_not_applicable(apply_demorgan, "fn f() { $0 !x || !x }") |
92 | } | 92 | } |
93 | } | 93 | } |
diff --git a/crates/assists/src/handlers/auto_import.rs b/crates/assists/src/handlers/auto_import.rs index bd5bba646..55620f0f3 100644 --- a/crates/assists/src/handlers/auto_import.rs +++ b/crates/assists/src/handlers/auto_import.rs | |||
@@ -70,7 +70,7 @@ use crate::{ | |||
70 | // | 70 | // |
71 | // ``` | 71 | // ``` |
72 | // fn main() { | 72 | // fn main() { |
73 | // let map = HashMap<|>::new(); | 73 | // let map = HashMap$0::new(); |
74 | // } | 74 | // } |
75 | // # pub mod std { pub mod collections { pub struct HashMap { } } } | 75 | // # pub mod std { pub mod collections { pub struct HashMap { } } } |
76 | // ``` | 76 | // ``` |
@@ -151,7 +151,7 @@ mod tests { | |||
151 | 151 | ||
152 | use std::fmt; | 152 | use std::fmt; |
153 | 153 | ||
154 | <|>Formatter | 154 | $0Formatter |
155 | ", | 155 | ", |
156 | r" | 156 | r" |
157 | mod std { | 157 | mod std { |
@@ -172,7 +172,7 @@ mod tests { | |||
172 | check_assist( | 172 | check_assist( |
173 | auto_import, | 173 | auto_import, |
174 | r" | 174 | r" |
175 | <|>PubStruct | 175 | $0PubStruct |
176 | 176 | ||
177 | pub mod PubMod { | 177 | pub mod PubMod { |
178 | pub struct PubStruct; | 178 | pub struct PubStruct; |
@@ -198,7 +198,7 @@ mod tests { | |||
198 | macro_rules! foo { | 198 | macro_rules! foo { |
199 | ($i:ident) => { fn foo(a: $i) {} } | 199 | ($i:ident) => { fn foo(a: $i) {} } |
200 | } | 200 | } |
201 | foo!(Pub<|>Struct); | 201 | foo!(Pub$0Struct); |
202 | 202 | ||
203 | pub mod PubMod { | 203 | pub mod PubMod { |
204 | pub struct PubStruct; | 204 | pub struct PubStruct; |
@@ -227,7 +227,7 @@ mod tests { | |||
227 | use PubMod::PubStruct1; | 227 | use PubMod::PubStruct1; |
228 | 228 | ||
229 | struct Test { | 229 | struct Test { |
230 | test: Pub<|>Struct2<u8>, | 230 | test: Pub$0Struct2<u8>, |
231 | } | 231 | } |
232 | 232 | ||
233 | pub mod PubMod { | 233 | pub mod PubMod { |
@@ -259,7 +259,7 @@ mod tests { | |||
259 | check_assist( | 259 | check_assist( |
260 | auto_import, | 260 | auto_import, |
261 | r" | 261 | r" |
262 | PubSt<|>ruct | 262 | PubSt$0ruct |
263 | 263 | ||
264 | pub mod PubMod1 { | 264 | pub mod PubMod1 { |
265 | pub struct PubStruct; | 265 | pub struct PubStruct; |
@@ -296,7 +296,7 @@ mod tests { | |||
296 | r" | 296 | r" |
297 | use PubMod::PubStruct; | 297 | use PubMod::PubStruct; |
298 | 298 | ||
299 | PubStruct<|> | 299 | PubStruct$0 |
300 | 300 | ||
301 | pub mod PubMod { | 301 | pub mod PubMod { |
302 | pub struct PubStruct; | 302 | pub struct PubStruct; |
@@ -310,7 +310,7 @@ mod tests { | |||
310 | check_assist_not_applicable( | 310 | check_assist_not_applicable( |
311 | auto_import, | 311 | auto_import, |
312 | r" | 312 | r" |
313 | PrivateStruct<|> | 313 | PrivateStruct$0 |
314 | 314 | ||
315 | pub mod PubMod { | 315 | pub mod PubMod { |
316 | struct PrivateStruct; | 316 | struct PrivateStruct; |
@@ -324,7 +324,7 @@ mod tests { | |||
324 | check_assist_not_applicable( | 324 | check_assist_not_applicable( |
325 | auto_import, | 325 | auto_import, |
326 | " | 326 | " |
327 | PubStruct<|>", | 327 | PubStruct$0", |
328 | ); | 328 | ); |
329 | } | 329 | } |
330 | 330 | ||
@@ -333,7 +333,7 @@ mod tests { | |||
333 | check_assist_not_applicable( | 333 | check_assist_not_applicable( |
334 | auto_import, | 334 | auto_import, |
335 | r" | 335 | r" |
336 | use PubStruct<|>; | 336 | use PubStruct$0; |
337 | 337 | ||
338 | pub mod PubMod { | 338 | pub mod PubMod { |
339 | pub struct PubStruct; | 339 | pub struct PubStruct; |
@@ -346,7 +346,7 @@ mod tests { | |||
346 | check_assist( | 346 | check_assist( |
347 | auto_import, | 347 | auto_import, |
348 | r" | 348 | r" |
349 | test_function<|> | 349 | test_function$0 |
350 | 350 | ||
351 | pub mod PubMod { | 351 | pub mod PubMod { |
352 | pub fn test_function() {}; | 352 | pub fn test_function() {}; |
@@ -377,7 +377,7 @@ macro_rules! foo { | |||
377 | 377 | ||
378 | //- /main.rs crate:main deps:crate_with_macro | 378 | //- /main.rs crate:main deps:crate_with_macro |
379 | fn main() { | 379 | fn main() { |
380 | foo<|> | 380 | foo$0 |
381 | } | 381 | } |
382 | ", | 382 | ", |
383 | r"use crate_with_macro::foo; | 383 | r"use crate_with_macro::foo; |
@@ -395,7 +395,7 @@ fn main() { | |||
395 | auto_import, | 395 | auto_import, |
396 | r" | 396 | r" |
397 | struct AssistInfo { | 397 | struct AssistInfo { |
398 | group_label: Option<<|>GroupLabel>, | 398 | group_label: Option<$0GroupLabel>, |
399 | } | 399 | } |
400 | 400 | ||
401 | mod m { pub struct GroupLabel; } | 401 | mod m { pub struct GroupLabel; } |
@@ -419,7 +419,7 @@ fn main() { | |||
419 | 419 | ||
420 | use mod1::mod2; | 420 | use mod1::mod2; |
421 | fn main() { | 421 | fn main() { |
422 | mod2::mod3::TestStruct<|> | 422 | mod2::mod3::TestStruct$0 |
423 | } | 423 | } |
424 | ", | 424 | ", |
425 | ); | 425 | ); |
@@ -436,7 +436,7 @@ fn main() { | |||
436 | 436 | ||
437 | use test_mod::test_function; | 437 | use test_mod::test_function; |
438 | fn main() { | 438 | fn main() { |
439 | test_function<|> | 439 | test_function$0 |
440 | } | 440 | } |
441 | ", | 441 | ", |
442 | ); | 442 | ); |
@@ -455,7 +455,7 @@ fn main() { | |||
455 | } | 455 | } |
456 | 456 | ||
457 | fn main() { | 457 | fn main() { |
458 | TestStruct::test_function<|> | 458 | TestStruct::test_function$0 |
459 | } | 459 | } |
460 | ", | 460 | ", |
461 | r" | 461 | r" |
@@ -488,7 +488,7 @@ fn main() { | |||
488 | } | 488 | } |
489 | 489 | ||
490 | fn main() { | 490 | fn main() { |
491 | TestStruct::TEST_CONST<|> | 491 | TestStruct::TEST_CONST$0 |
492 | } | 492 | } |
493 | ", | 493 | ", |
494 | r" | 494 | r" |
@@ -524,7 +524,7 @@ fn main() { | |||
524 | } | 524 | } |
525 | 525 | ||
526 | fn main() { | 526 | fn main() { |
527 | test_mod::TestStruct::test_function<|> | 527 | test_mod::TestStruct::test_function$0 |
528 | } | 528 | } |
529 | ", | 529 | ", |
530 | r" | 530 | r" |
@@ -573,7 +573,7 @@ fn main() { | |||
573 | 573 | ||
574 | use test_mod::TestTrait2; | 574 | use test_mod::TestTrait2; |
575 | fn main() { | 575 | fn main() { |
576 | test_mod::TestEnum::test_function<|>; | 576 | test_mod::TestEnum::test_function$0; |
577 | } | 577 | } |
578 | ", | 578 | ", |
579 | ) | 579 | ) |
@@ -595,7 +595,7 @@ fn main() { | |||
595 | } | 595 | } |
596 | 596 | ||
597 | fn main() { | 597 | fn main() { |
598 | test_mod::TestStruct::TEST_CONST<|> | 598 | test_mod::TestStruct::TEST_CONST$0 |
599 | } | 599 | } |
600 | ", | 600 | ", |
601 | r" | 601 | r" |
@@ -644,7 +644,7 @@ fn main() { | |||
644 | 644 | ||
645 | use test_mod::TestTrait2; | 645 | use test_mod::TestTrait2; |
646 | fn main() { | 646 | fn main() { |
647 | test_mod::TestEnum::TEST_CONST<|>; | 647 | test_mod::TestEnum::TEST_CONST$0; |
648 | } | 648 | } |
649 | ", | 649 | ", |
650 | ) | 650 | ) |
@@ -667,7 +667,7 @@ fn main() { | |||
667 | 667 | ||
668 | fn main() { | 668 | fn main() { |
669 | let test_struct = test_mod::TestStruct {}; | 669 | let test_struct = test_mod::TestStruct {}; |
670 | test_struct.test_meth<|>od() | 670 | test_struct.test_meth$0od() |
671 | } | 671 | } |
672 | ", | 672 | ", |
673 | r" | 673 | r" |
@@ -699,7 +699,7 @@ fn main() { | |||
699 | //- /main.rs crate:main deps:dep | 699 | //- /main.rs crate:main deps:dep |
700 | fn main() { | 700 | fn main() { |
701 | let test_struct = dep::test_mod::TestStruct {}; | 701 | let test_struct = dep::test_mod::TestStruct {}; |
702 | test_struct.test_meth<|>od() | 702 | test_struct.test_meth$0od() |
703 | } | 703 | } |
704 | //- /dep.rs crate:dep | 704 | //- /dep.rs crate:dep |
705 | pub mod test_mod { | 705 | pub mod test_mod { |
@@ -730,7 +730,7 @@ fn main() { | |||
730 | r" | 730 | r" |
731 | //- /main.rs crate:main deps:dep | 731 | //- /main.rs crate:main deps:dep |
732 | fn main() { | 732 | fn main() { |
733 | dep::test_mod::TestStruct::test_func<|>tion | 733 | dep::test_mod::TestStruct::test_func$0tion |
734 | } | 734 | } |
735 | //- /dep.rs crate:dep | 735 | //- /dep.rs crate:dep |
736 | pub mod test_mod { | 736 | pub mod test_mod { |
@@ -760,7 +760,7 @@ fn main() { | |||
760 | r" | 760 | r" |
761 | //- /main.rs crate:main deps:dep | 761 | //- /main.rs crate:main deps:dep |
762 | fn main() { | 762 | fn main() { |
763 | dep::test_mod::TestStruct::CONST<|> | 763 | dep::test_mod::TestStruct::CONST$0 |
764 | } | 764 | } |
765 | //- /dep.rs crate:dep | 765 | //- /dep.rs crate:dep |
766 | pub mod test_mod { | 766 | pub mod test_mod { |
@@ -791,7 +791,7 @@ fn main() { | |||
791 | //- /main.rs crate:main deps:dep | 791 | //- /main.rs crate:main deps:dep |
792 | fn main() { | 792 | fn main() { |
793 | let test_struct = dep::test_mod::TestStruct {}; | 793 | let test_struct = dep::test_mod::TestStruct {}; |
794 | test_struct.test_func<|>tion() | 794 | test_struct.test_func$0tion() |
795 | } | 795 | } |
796 | //- /dep.rs crate:dep | 796 | //- /dep.rs crate:dep |
797 | pub mod test_mod { | 797 | pub mod test_mod { |
@@ -815,7 +815,7 @@ fn main() { | |||
815 | //- /main.rs crate:main deps:dep | 815 | //- /main.rs crate:main deps:dep |
816 | fn main() { | 816 | fn main() { |
817 | let test_struct = dep::test_mod::TestStruct {}; | 817 | let test_struct = dep::test_mod::TestStruct {}; |
818 | test_struct.test_meth<|>od() | 818 | test_struct.test_meth$0od() |
819 | } | 819 | } |
820 | //- /dep.rs crate:dep | 820 | //- /dep.rs crate:dep |
821 | pub mod test_mod { | 821 | pub mod test_mod { |
@@ -858,7 +858,7 @@ fn main() { | |||
858 | use test_mod::TestTrait2; | 858 | use test_mod::TestTrait2; |
859 | fn main() { | 859 | fn main() { |
860 | let one = test_mod::TestEnum::One; | 860 | let one = test_mod::TestEnum::One; |
861 | one.test<|>_method(); | 861 | one.test$0_method(); |
862 | } | 862 | } |
863 | ", | 863 | ", |
864 | ) | 864 | ) |
@@ -874,7 +874,7 @@ pub struct Struct; | |||
874 | 874 | ||
875 | //- /main.rs crate:main deps:dep | 875 | //- /main.rs crate:main deps:dep |
876 | fn main() { | 876 | fn main() { |
877 | Struct<|> | 877 | Struct$0 |
878 | } | 878 | } |
879 | ", | 879 | ", |
880 | r"use dep::Struct; | 880 | r"use dep::Struct; |
@@ -902,7 +902,7 @@ pub fn panic_fmt() {} | |||
902 | //- /main.rs crate:main deps:dep | 902 | //- /main.rs crate:main deps:dep |
903 | struct S; | 903 | struct S; |
904 | 904 | ||
905 | impl f<|>mt::Display for S {} | 905 | impl f$0mt::Display for S {} |
906 | ", | 906 | ", |
907 | r"use dep::fmt; | 907 | r"use dep::fmt; |
908 | 908 | ||
@@ -930,7 +930,7 @@ mac!(); | |||
930 | 930 | ||
931 | //- /main.rs crate:main deps:dep | 931 | //- /main.rs crate:main deps:dep |
932 | fn main() { | 932 | fn main() { |
933 | Cheese<|>; | 933 | Cheese$0; |
934 | } | 934 | } |
935 | ", | 935 | ", |
936 | r"use dep::Cheese; | 936 | r"use dep::Cheese; |
@@ -954,7 +954,7 @@ pub struct fmt; | |||
954 | 954 | ||
955 | //- /main.rs crate:main deps:dep | 955 | //- /main.rs crate:main deps:dep |
956 | fn main() { | 956 | fn main() { |
957 | FMT<|>; | 957 | FMT$0; |
958 | } | 958 | } |
959 | ", | 959 | ", |
960 | r"use dep::FMT; | 960 | r"use dep::FMT; |
diff --git a/crates/assists/src/handlers/change_visibility.rs b/crates/assists/src/handlers/change_visibility.rs index 22d7c95d9..ac8c44124 100644 --- a/crates/assists/src/handlers/change_visibility.rs +++ b/crates/assists/src/handlers/change_visibility.rs | |||
@@ -13,7 +13,7 @@ use crate::{utils::vis_offset, AssistContext, AssistId, AssistKind, Assists}; | |||
13 | // Adds or changes existing visibility specifier. | 13 | // Adds or changes existing visibility specifier. |
14 | // | 14 | // |
15 | // ``` | 15 | // ``` |
16 | // <|>fn frobnicate() {} | 16 | // $0fn frobnicate() {} |
17 | // ``` | 17 | // ``` |
18 | // -> | 18 | // -> |
19 | // ``` | 19 | // ``` |
@@ -118,23 +118,23 @@ mod tests { | |||
118 | 118 | ||
119 | #[test] | 119 | #[test] |
120 | fn change_visibility_adds_pub_crate_to_items() { | 120 | fn change_visibility_adds_pub_crate_to_items() { |
121 | check_assist(change_visibility, "<|>fn foo() {}", "pub(crate) fn foo() {}"); | 121 | check_assist(change_visibility, "$0fn foo() {}", "pub(crate) fn foo() {}"); |
122 | check_assist(change_visibility, "f<|>n foo() {}", "pub(crate) fn foo() {}"); | 122 | check_assist(change_visibility, "f$0n foo() {}", "pub(crate) fn foo() {}"); |
123 | check_assist(change_visibility, "<|>struct Foo {}", "pub(crate) struct Foo {}"); | 123 | check_assist(change_visibility, "$0struct Foo {}", "pub(crate) struct Foo {}"); |
124 | check_assist(change_visibility, "<|>mod foo {}", "pub(crate) mod foo {}"); | 124 | check_assist(change_visibility, "$0mod foo {}", "pub(crate) mod foo {}"); |
125 | check_assist(change_visibility, "<|>trait Foo {}", "pub(crate) trait Foo {}"); | 125 | check_assist(change_visibility, "$0trait Foo {}", "pub(crate) trait Foo {}"); |
126 | check_assist(change_visibility, "m<|>od {}", "pub(crate) mod {}"); | 126 | check_assist(change_visibility, "m$0od {}", "pub(crate) mod {}"); |
127 | check_assist(change_visibility, "unsafe f<|>n foo() {}", "pub(crate) unsafe fn foo() {}"); | 127 | check_assist(change_visibility, "unsafe f$0n foo() {}", "pub(crate) unsafe fn foo() {}"); |
128 | } | 128 | } |
129 | 129 | ||
130 | #[test] | 130 | #[test] |
131 | fn change_visibility_works_with_struct_fields() { | 131 | fn change_visibility_works_with_struct_fields() { |
132 | check_assist( | 132 | check_assist( |
133 | change_visibility, | 133 | change_visibility, |
134 | r"struct S { <|>field: u32 }", | 134 | r"struct S { $0field: u32 }", |
135 | r"struct S { pub(crate) field: u32 }", | 135 | r"struct S { pub(crate) field: u32 }", |
136 | ); | 136 | ); |
137 | check_assist(change_visibility, r"struct S ( <|>u32 )", r"struct S ( pub(crate) u32 )"); | 137 | check_assist(change_visibility, r"struct S ( $0u32 )", r"struct S ( pub(crate) u32 )"); |
138 | } | 138 | } |
139 | 139 | ||
140 | #[test] | 140 | #[test] |
@@ -142,33 +142,33 @@ mod tests { | |||
142 | mark::check!(change_visibility_field_false_positive); | 142 | mark::check!(change_visibility_field_false_positive); |
143 | check_assist_not_applicable( | 143 | check_assist_not_applicable( |
144 | change_visibility, | 144 | change_visibility, |
145 | r"struct S { field: [(); { let <|>x = ();}] }", | 145 | r"struct S { field: [(); { let $0x = ();}] }", |
146 | ) | 146 | ) |
147 | } | 147 | } |
148 | 148 | ||
149 | #[test] | 149 | #[test] |
150 | fn change_visibility_pub_to_pub_crate() { | 150 | fn change_visibility_pub_to_pub_crate() { |
151 | check_assist(change_visibility, "<|>pub fn foo() {}", "pub(crate) fn foo() {}") | 151 | check_assist(change_visibility, "$0pub fn foo() {}", "pub(crate) fn foo() {}") |
152 | } | 152 | } |
153 | 153 | ||
154 | #[test] | 154 | #[test] |
155 | fn change_visibility_pub_crate_to_pub() { | 155 | fn change_visibility_pub_crate_to_pub() { |
156 | check_assist(change_visibility, "<|>pub(crate) fn foo() {}", "pub fn foo() {}") | 156 | check_assist(change_visibility, "$0pub(crate) fn foo() {}", "pub fn foo() {}") |
157 | } | 157 | } |
158 | 158 | ||
159 | #[test] | 159 | #[test] |
160 | fn change_visibility_const() { | 160 | fn change_visibility_const() { |
161 | check_assist(change_visibility, "<|>const FOO = 3u8;", "pub(crate) const FOO = 3u8;"); | 161 | check_assist(change_visibility, "$0const FOO = 3u8;", "pub(crate) const FOO = 3u8;"); |
162 | } | 162 | } |
163 | 163 | ||
164 | #[test] | 164 | #[test] |
165 | fn change_visibility_static() { | 165 | fn change_visibility_static() { |
166 | check_assist(change_visibility, "<|>static FOO = 3u8;", "pub(crate) static FOO = 3u8;"); | 166 | check_assist(change_visibility, "$0static FOO = 3u8;", "pub(crate) static FOO = 3u8;"); |
167 | } | 167 | } |
168 | 168 | ||
169 | #[test] | 169 | #[test] |
170 | fn change_visibility_type_alias() { | 170 | fn change_visibility_type_alias() { |
171 | check_assist(change_visibility, "<|>type T = ();", "pub(crate) type T = ();"); | 171 | check_assist(change_visibility, "$0type T = ();", "pub(crate) type T = ();"); |
172 | } | 172 | } |
173 | 173 | ||
174 | #[test] | 174 | #[test] |
@@ -181,7 +181,7 @@ mod tests { | |||
181 | // comments | 181 | // comments |
182 | 182 | ||
183 | #[derive(Debug)] | 183 | #[derive(Debug)] |
184 | <|>struct Foo; | 184 | $0struct Foo; |
185 | ", | 185 | ", |
186 | r" | 186 | r" |
187 | /// docs | 187 | /// docs |
@@ -199,14 +199,14 @@ mod tests { | |||
199 | check_assist_not_applicable( | 199 | check_assist_not_applicable( |
200 | change_visibility, | 200 | change_visibility, |
201 | r"mod foo { pub enum Foo {Foo1} } | 201 | r"mod foo { pub enum Foo {Foo1} } |
202 | fn main() { foo::Foo::Foo1<|> } ", | 202 | fn main() { foo::Foo::Foo1$0 } ", |
203 | ); | 203 | ); |
204 | } | 204 | } |
205 | 205 | ||
206 | #[test] | 206 | #[test] |
207 | fn change_visibility_target() { | 207 | fn change_visibility_target() { |
208 | check_assist_target(change_visibility, "<|>fn foo() {}", "fn"); | 208 | check_assist_target(change_visibility, "$0fn foo() {}", "fn"); |
209 | check_assist_target(change_visibility, "pub(crate)<|> fn foo() {}", "pub(crate)"); | 209 | check_assist_target(change_visibility, "pub(crate)$0 fn foo() {}", "pub(crate)"); |
210 | check_assist_target(change_visibility, "struct S { <|>field: u32 }", "field"); | 210 | check_assist_target(change_visibility, "struct S { $0field: u32 }", "field"); |
211 | } | 211 | } |
212 | } | 212 | } |
diff --git a/crates/assists/src/handlers/convert_integer_literal.rs b/crates/assists/src/handlers/convert_integer_literal.rs index 667115382..a8a819cfc 100644 --- a/crates/assists/src/handlers/convert_integer_literal.rs +++ b/crates/assists/src/handlers/convert_integer_literal.rs | |||
@@ -7,7 +7,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists, GroupLabel}; | |||
7 | // Converts the base of integer literals to other bases. | 7 | // Converts the base of integer literals to other bases. |
8 | // | 8 | // |
9 | // ``` | 9 | // ``` |
10 | // const _: i32 = 10<|>; | 10 | // const _: i32 = 10$0; |
11 | // ``` | 11 | // ``` |
12 | // -> | 12 | // -> |
13 | // ``` | 13 | // ``` |
@@ -65,47 +65,47 @@ mod tests { | |||
65 | 65 | ||
66 | #[test] | 66 | #[test] |
67 | fn binary_target() { | 67 | fn binary_target() { |
68 | check_assist_target(convert_integer_literal, "const _: i32 = 0b1010<|>;", "0b1010"); | 68 | check_assist_target(convert_integer_literal, "const _: i32 = 0b1010$0;", "0b1010"); |
69 | } | 69 | } |
70 | 70 | ||
71 | #[test] | 71 | #[test] |
72 | fn octal_target() { | 72 | fn octal_target() { |
73 | check_assist_target(convert_integer_literal, "const _: i32 = 0o12<|>;", "0o12"); | 73 | check_assist_target(convert_integer_literal, "const _: i32 = 0o12$0;", "0o12"); |
74 | } | 74 | } |
75 | 75 | ||
76 | #[test] | 76 | #[test] |
77 | fn decimal_target() { | 77 | fn decimal_target() { |
78 | check_assist_target(convert_integer_literal, "const _: i32 = 10<|>;", "10"); | 78 | check_assist_target(convert_integer_literal, "const _: i32 = 10$0;", "10"); |
79 | } | 79 | } |
80 | 80 | ||
81 | #[test] | 81 | #[test] |
82 | fn hexadecimal_target() { | 82 | fn hexadecimal_target() { |
83 | check_assist_target(convert_integer_literal, "const _: i32 = 0xA<|>;", "0xA"); | 83 | check_assist_target(convert_integer_literal, "const _: i32 = 0xA$0;", "0xA"); |
84 | } | 84 | } |
85 | 85 | ||
86 | #[test] | 86 | #[test] |
87 | fn binary_target_with_underscores() { | 87 | fn binary_target_with_underscores() { |
88 | check_assist_target(convert_integer_literal, "const _: i32 = 0b10_10<|>;", "0b10_10"); | 88 | check_assist_target(convert_integer_literal, "const _: i32 = 0b10_10$0;", "0b10_10"); |
89 | } | 89 | } |
90 | 90 | ||
91 | #[test] | 91 | #[test] |
92 | fn octal_target_with_underscores() { | 92 | fn octal_target_with_underscores() { |
93 | check_assist_target(convert_integer_literal, "const _: i32 = 0o1_2<|>;", "0o1_2"); | 93 | check_assist_target(convert_integer_literal, "const _: i32 = 0o1_2$0;", "0o1_2"); |
94 | } | 94 | } |
95 | 95 | ||
96 | #[test] | 96 | #[test] |
97 | fn decimal_target_with_underscores() { | 97 | fn decimal_target_with_underscores() { |
98 | check_assist_target(convert_integer_literal, "const _: i32 = 1_0<|>;", "1_0"); | 98 | check_assist_target(convert_integer_literal, "const _: i32 = 1_0$0;", "1_0"); |
99 | } | 99 | } |
100 | 100 | ||
101 | #[test] | 101 | #[test] |
102 | fn hexadecimal_target_with_underscores() { | 102 | fn hexadecimal_target_with_underscores() { |
103 | check_assist_target(convert_integer_literal, "const _: i32 = 0x_A<|>;", "0x_A"); | 103 | check_assist_target(convert_integer_literal, "const _: i32 = 0x_A$0;", "0x_A"); |
104 | } | 104 | } |
105 | 105 | ||
106 | #[test] | 106 | #[test] |
107 | fn convert_decimal_integer() { | 107 | fn convert_decimal_integer() { |
108 | let before = "const _: i32 = 1000<|>;"; | 108 | let before = "const _: i32 = 1000$0;"; |
109 | 109 | ||
110 | check_assist_by_label( | 110 | check_assist_by_label( |
111 | convert_integer_literal, | 111 | convert_integer_literal, |
@@ -131,7 +131,7 @@ mod tests { | |||
131 | 131 | ||
132 | #[test] | 132 | #[test] |
133 | fn convert_hexadecimal_integer() { | 133 | fn convert_hexadecimal_integer() { |
134 | let before = "const _: i32 = 0xFF<|>;"; | 134 | let before = "const _: i32 = 0xFF$0;"; |
135 | 135 | ||
136 | check_assist_by_label( | 136 | check_assist_by_label( |
137 | convert_integer_literal, | 137 | convert_integer_literal, |
@@ -157,7 +157,7 @@ mod tests { | |||
157 | 157 | ||
158 | #[test] | 158 | #[test] |
159 | fn convert_binary_integer() { | 159 | fn convert_binary_integer() { |
160 | let before = "const _: i32 = 0b11111111<|>;"; | 160 | let before = "const _: i32 = 0b11111111$0;"; |
161 | 161 | ||
162 | check_assist_by_label( | 162 | check_assist_by_label( |
163 | convert_integer_literal, | 163 | convert_integer_literal, |
@@ -183,7 +183,7 @@ mod tests { | |||
183 | 183 | ||
184 | #[test] | 184 | #[test] |
185 | fn convert_octal_integer() { | 185 | fn convert_octal_integer() { |
186 | let before = "const _: i32 = 0o377<|>;"; | 186 | let before = "const _: i32 = 0o377$0;"; |
187 | 187 | ||
188 | check_assist_by_label( | 188 | check_assist_by_label( |
189 | convert_integer_literal, | 189 | convert_integer_literal, |
@@ -209,7 +209,7 @@ mod tests { | |||
209 | 209 | ||
210 | #[test] | 210 | #[test] |
211 | fn convert_integer_with_underscores() { | 211 | fn convert_integer_with_underscores() { |
212 | let before = "const _: i32 = 1_00_0<|>;"; | 212 | let before = "const _: i32 = 1_00_0$0;"; |
213 | 213 | ||
214 | check_assist_by_label( | 214 | check_assist_by_label( |
215 | convert_integer_literal, | 215 | convert_integer_literal, |
@@ -235,7 +235,7 @@ mod tests { | |||
235 | 235 | ||
236 | #[test] | 236 | #[test] |
237 | fn convert_integer_with_suffix() { | 237 | fn convert_integer_with_suffix() { |
238 | let before = "const _: i32 = 1000i32<|>;"; | 238 | let before = "const _: i32 = 1000i32$0;"; |
239 | 239 | ||
240 | check_assist_by_label( | 240 | check_assist_by_label( |
241 | convert_integer_literal, | 241 | convert_integer_literal, |
@@ -262,7 +262,7 @@ mod tests { | |||
262 | #[test] | 262 | #[test] |
263 | fn convert_overflowing_literal() { | 263 | fn convert_overflowing_literal() { |
264 | let before = "const _: i32 = | 264 | let before = "const _: i32 = |
265 | 111111111111111111111111111111111111111111111111111111111111111111111111<|>;"; | 265 | 111111111111111111111111111111111111111111111111111111111111111111111111$0;"; |
266 | check_assist_not_applicable(convert_integer_literal, before); | 266 | check_assist_not_applicable(convert_integer_literal, before); |
267 | } | 267 | } |
268 | } | 268 | } |
diff --git a/crates/assists/src/handlers/early_return.rs b/crates/assists/src/handlers/early_return.rs index 7bcc318a9..8bbbb7ed5 100644 --- a/crates/assists/src/handlers/early_return.rs +++ b/crates/assists/src/handlers/early_return.rs | |||
@@ -24,7 +24,7 @@ use crate::{ | |||
24 | // | 24 | // |
25 | // ``` | 25 | // ``` |
26 | // fn main() { | 26 | // fn main() { |
27 | // <|>if cond { | 27 | // $0if cond { |
28 | // foo(); | 28 | // foo(); |
29 | // bar(); | 29 | // bar(); |
30 | // } | 30 | // } |
@@ -69,7 +69,7 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext) | |||
69 | 69 | ||
70 | let parent_block = if_expr.syntax().parent()?.ancestors().find_map(ast::BlockExpr::cast)?; | 70 | let parent_block = if_expr.syntax().parent()?.ancestors().find_map(ast::BlockExpr::cast)?; |
71 | 71 | ||
72 | if parent_block.expr()? != if_expr.clone().into() { | 72 | if parent_block.tail_expr()? != if_expr.clone().into() { |
73 | return None; | 73 | return None; |
74 | } | 74 | } |
75 | 75 | ||
@@ -200,7 +200,7 @@ mod tests { | |||
200 | r#" | 200 | r#" |
201 | fn main() { | 201 | fn main() { |
202 | bar(); | 202 | bar(); |
203 | if<|> true { | 203 | if$0 true { |
204 | foo(); | 204 | foo(); |
205 | 205 | ||
206 | //comment | 206 | //comment |
@@ -230,7 +230,7 @@ mod tests { | |||
230 | r#" | 230 | r#" |
231 | fn main(n: Option<String>) { | 231 | fn main(n: Option<String>) { |
232 | bar(); | 232 | bar(); |
233 | if<|> let Some(n) = n { | 233 | if$0 let Some(n) = n { |
234 | foo(n); | 234 | foo(n); |
235 | 235 | ||
236 | //comment | 236 | //comment |
@@ -260,7 +260,7 @@ mod tests { | |||
260 | convert_to_guarded_return, | 260 | convert_to_guarded_return, |
261 | r#" | 261 | r#" |
262 | fn main() { | 262 | fn main() { |
263 | if<|> let Ok(x) = Err(92) { | 263 | if$0 let Ok(x) = Err(92) { |
264 | foo(x); | 264 | foo(x); |
265 | } | 265 | } |
266 | } | 266 | } |
@@ -284,7 +284,7 @@ mod tests { | |||
284 | r#" | 284 | r#" |
285 | fn main(n: Option<String>) { | 285 | fn main(n: Option<String>) { |
286 | bar(); | 286 | bar(); |
287 | if<|> let Ok(n) = n { | 287 | if$0 let Ok(n) = n { |
288 | foo(n); | 288 | foo(n); |
289 | 289 | ||
290 | //comment | 290 | //comment |
@@ -315,7 +315,7 @@ mod tests { | |||
315 | r#" | 315 | r#" |
316 | fn main() { | 316 | fn main() { |
317 | while true { | 317 | while true { |
318 | if<|> true { | 318 | if$0 true { |
319 | foo(); | 319 | foo(); |
320 | bar(); | 320 | bar(); |
321 | } | 321 | } |
@@ -343,7 +343,7 @@ mod tests { | |||
343 | r#" | 343 | r#" |
344 | fn main() { | 344 | fn main() { |
345 | while true { | 345 | while true { |
346 | if<|> let Some(n) = n { | 346 | if$0 let Some(n) = n { |
347 | foo(n); | 347 | foo(n); |
348 | bar(); | 348 | bar(); |
349 | } | 349 | } |
@@ -372,7 +372,7 @@ mod tests { | |||
372 | r#" | 372 | r#" |
373 | fn main() { | 373 | fn main() { |
374 | loop { | 374 | loop { |
375 | if<|> true { | 375 | if$0 true { |
376 | foo(); | 376 | foo(); |
377 | bar(); | 377 | bar(); |
378 | } | 378 | } |
@@ -400,7 +400,7 @@ mod tests { | |||
400 | r#" | 400 | r#" |
401 | fn main() { | 401 | fn main() { |
402 | loop { | 402 | loop { |
403 | if<|> let Some(n) = n { | 403 | if$0 let Some(n) = n { |
404 | foo(n); | 404 | foo(n); |
405 | bar(); | 405 | bar(); |
406 | } | 406 | } |
@@ -428,7 +428,7 @@ mod tests { | |||
428 | convert_to_guarded_return, | 428 | convert_to_guarded_return, |
429 | r#" | 429 | r#" |
430 | fn main() { | 430 | fn main() { |
431 | if<|> true { | 431 | if$0 true { |
432 | return; | 432 | return; |
433 | } | 433 | } |
434 | } | 434 | } |
@@ -443,7 +443,7 @@ mod tests { | |||
443 | r#" | 443 | r#" |
444 | fn main() { | 444 | fn main() { |
445 | loop { | 445 | loop { |
446 | if<|> true { | 446 | if$0 true { |
447 | continue; | 447 | continue; |
448 | } | 448 | } |
449 | } | 449 | } |
@@ -458,7 +458,7 @@ mod tests { | |||
458 | convert_to_guarded_return, | 458 | convert_to_guarded_return, |
459 | r#" | 459 | r#" |
460 | fn main() { | 460 | fn main() { |
461 | if<|> true { | 461 | if$0 true { |
462 | return | 462 | return |
463 | } | 463 | } |
464 | } | 464 | } |
@@ -472,7 +472,7 @@ mod tests { | |||
472 | convert_to_guarded_return, | 472 | convert_to_guarded_return, |
473 | r#" | 473 | r#" |
474 | fn main() { | 474 | fn main() { |
475 | if<|> true { | 475 | if$0 true { |
476 | foo(); | 476 | foo(); |
477 | } else { | 477 | } else { |
478 | bar() | 478 | bar() |
@@ -488,7 +488,7 @@ mod tests { | |||
488 | convert_to_guarded_return, | 488 | convert_to_guarded_return, |
489 | r#" | 489 | r#" |
490 | fn main() { | 490 | fn main() { |
491 | if<|> true { | 491 | if$0 true { |
492 | foo(); | 492 | foo(); |
493 | } | 493 | } |
494 | bar(); | 494 | bar(); |
@@ -504,7 +504,7 @@ mod tests { | |||
504 | r#" | 504 | r#" |
505 | fn main() { | 505 | fn main() { |
506 | if false { | 506 | if false { |
507 | if<|> true { | 507 | if$0 true { |
508 | foo(); | 508 | foo(); |
509 | } | 509 | } |
510 | } | 510 | } |
diff --git a/crates/assists/src/handlers/expand_glob_import.rs b/crates/assists/src/handlers/expand_glob_import.rs index f51a9a4ad..5fe617ba4 100644 --- a/crates/assists/src/handlers/expand_glob_import.rs +++ b/crates/assists/src/handlers/expand_glob_import.rs | |||
@@ -25,7 +25,7 @@ use crate::{ | |||
25 | // pub struct Baz; | 25 | // pub struct Baz; |
26 | // } | 26 | // } |
27 | // | 27 | // |
28 | // use foo::*<|>; | 28 | // use foo::*$0; |
29 | // | 29 | // |
30 | // fn qux(bar: Bar, baz: Baz) {} | 30 | // fn qux(bar: Bar, baz: Baz) {} |
31 | // ``` | 31 | // ``` |
@@ -201,7 +201,7 @@ fn is_mod_visible_from(ctx: &AssistContext, module: Module, from: Module) -> boo | |||
201 | // } | 201 | // } |
202 | // | 202 | // |
203 | // ↓ --------------- | 203 | // ↓ --------------- |
204 | // use foo::*<|>; | 204 | // use foo::*$0; |
205 | // use baz::Baz; | 205 | // use baz::Baz; |
206 | // ↑ --------------- | 206 | // ↑ --------------- |
207 | fn find_imported_defs(ctx: &AssistContext, star: SyntaxToken) -> Option<Vec<Def>> { | 207 | fn find_imported_defs(ctx: &AssistContext, star: SyntaxToken) -> Option<Vec<Def>> { |
@@ -303,7 +303,7 @@ mod foo { | |||
303 | pub fn f() {} | 303 | pub fn f() {} |
304 | } | 304 | } |
305 | 305 | ||
306 | use foo::*<|>; | 306 | use foo::*$0; |
307 | 307 | ||
308 | fn qux(bar: Bar, baz: Baz) { | 308 | fn qux(bar: Bar, baz: Baz) { |
309 | f(); | 309 | f(); |
@@ -340,7 +340,7 @@ mod foo { | |||
340 | pub fn f() {} | 340 | pub fn f() {} |
341 | } | 341 | } |
342 | 342 | ||
343 | use foo::{*<|>, f}; | 343 | use foo::{*$0, f}; |
344 | 344 | ||
345 | fn qux(bar: Bar, baz: Baz) { | 345 | fn qux(bar: Bar, baz: Baz) { |
346 | f(); | 346 | f(); |
@@ -378,7 +378,7 @@ mod foo { | |||
378 | } | 378 | } |
379 | 379 | ||
380 | use foo::Bar; | 380 | use foo::Bar; |
381 | use foo::{*<|>, f}; | 381 | use foo::{*$0, f}; |
382 | 382 | ||
383 | fn qux(bar: Bar, baz: Baz) { | 383 | fn qux(bar: Bar, baz: Baz) { |
384 | f(); | 384 | f(); |
@@ -422,7 +422,7 @@ mod foo { | |||
422 | } | 422 | } |
423 | } | 423 | } |
424 | 424 | ||
425 | use foo::{bar::{*<|>, f}, baz::*}; | 425 | use foo::{bar::{*$0, f}, baz::*}; |
426 | 426 | ||
427 | fn qux(bar: Bar, baz: Baz) { | 427 | fn qux(bar: Bar, baz: Baz) { |
428 | f(); | 428 | f(); |
@@ -470,7 +470,7 @@ mod foo { | |||
470 | } | 470 | } |
471 | } | 471 | } |
472 | 472 | ||
473 | use foo::{bar::{Bar, Baz, f}, baz::*<|>}; | 473 | use foo::{bar::{Bar, Baz, f}, baz::*$0}; |
474 | 474 | ||
475 | fn qux(bar: Bar, baz: Baz) { | 475 | fn qux(bar: Bar, baz: Baz) { |
476 | f(); | 476 | f(); |
@@ -529,7 +529,7 @@ mod foo { | |||
529 | 529 | ||
530 | use foo::{ | 530 | use foo::{ |
531 | bar::{*, f}, | 531 | bar::{*, f}, |
532 | baz::{g, qux::*<|>} | 532 | baz::{g, qux::*$0} |
533 | }; | 533 | }; |
534 | 534 | ||
535 | fn qux(bar: Bar, baz: Baz) { | 535 | fn qux(bar: Bar, baz: Baz) { |
@@ -605,7 +605,7 @@ mod foo { | |||
605 | 605 | ||
606 | use foo::{ | 606 | use foo::{ |
607 | bar::{*, f}, | 607 | bar::{*, f}, |
608 | baz::{g, qux::{h, q::*<|>}} | 608 | baz::{g, qux::{h, q::*$0}} |
609 | }; | 609 | }; |
610 | 610 | ||
611 | fn qux(bar: Bar, baz: Baz) { | 611 | fn qux(bar: Bar, baz: Baz) { |
@@ -681,7 +681,7 @@ mod foo { | |||
681 | 681 | ||
682 | use foo::{ | 682 | use foo::{ |
683 | bar::{*, f}, | 683 | bar::{*, f}, |
684 | baz::{g, qux::{q::j, *<|>}} | 684 | baz::{g, qux::{q::j, *$0}} |
685 | }; | 685 | }; |
686 | 686 | ||
687 | fn qux(bar: Bar, baz: Baz) { | 687 | fn qux(bar: Bar, baz: Baz) { |
@@ -747,7 +747,7 @@ fn qux(bar: Bar, baz: Baz) { | |||
747 | // pub fn baz() {} | 747 | // pub fn baz() {} |
748 | 748 | ||
749 | // //- /main.rs crate:main deps:foo | 749 | // //- /main.rs crate:main deps:foo |
750 | // use foo::*<|>; | 750 | // use foo::*$0; |
751 | 751 | ||
752 | // fn main() { | 752 | // fn main() { |
753 | // bar!(); | 753 | // bar!(); |
@@ -777,7 +777,7 @@ pub trait Tr { | |||
777 | impl Tr for () {} | 777 | impl Tr for () {} |
778 | 778 | ||
779 | //- /main.rs crate:main deps:foo | 779 | //- /main.rs crate:main deps:foo |
780 | use foo::*<|>; | 780 | use foo::*$0; |
781 | 781 | ||
782 | fn main() { | 782 | fn main() { |
783 | ().method(); | 783 | ().method(); |
@@ -807,7 +807,7 @@ pub trait Tr2 { | |||
807 | impl Tr2 for () {} | 807 | impl Tr2 for () {} |
808 | 808 | ||
809 | //- /main.rs crate:main deps:foo | 809 | //- /main.rs crate:main deps:foo |
810 | use foo::*<|>; | 810 | use foo::*$0; |
811 | 811 | ||
812 | fn main() { | 812 | fn main() { |
813 | ().method(); | 813 | ().method(); |
@@ -834,7 +834,7 @@ mod foo { | |||
834 | } | 834 | } |
835 | } | 835 | } |
836 | 836 | ||
837 | use foo::bar::*<|>; | 837 | use foo::bar::*$0; |
838 | 838 | ||
839 | fn baz(bar: Bar) {} | 839 | fn baz(bar: Bar) {} |
840 | ", | 840 | ", |
@@ -851,7 +851,7 @@ mod foo { | |||
851 | } | 851 | } |
852 | } | 852 | } |
853 | 853 | ||
854 | use foo::bar::baz::*<|>; | 854 | use foo::bar::baz::*$0; |
855 | 855 | ||
856 | fn qux(baz: Baz) {} | 856 | fn qux(baz: Baz) {} |
857 | ", | 857 | ", |
@@ -869,7 +869,7 @@ fn qux(baz: Baz) {} | |||
869 | pub struct Qux; | 869 | pub struct Qux; |
870 | } | 870 | } |
871 | 871 | ||
872 | use foo::Bar<|>; | 872 | use foo::Bar$0; |
873 | 873 | ||
874 | fn qux(bar: Bar, baz: Baz) {} | 874 | fn qux(bar: Bar, baz: Baz) {} |
875 | ", | 875 | ", |
@@ -885,7 +885,7 @@ mod foo { | |||
885 | pub struct Bar; | 885 | pub struct Bar; |
886 | } | 886 | } |
887 | 887 | ||
888 | use foo::{*<|>}; | 888 | use foo::{*$0}; |
889 | 889 | ||
890 | struct Baz { | 890 | struct Baz { |
891 | bar: Bar | 891 | bar: Bar |
diff --git a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs index 030b9cd0c..e3ef04932 100644 --- a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs | |||
@@ -2,12 +2,16 @@ use std::iter; | |||
2 | 2 | ||
3 | use either::Either; | 3 | use either::Either; |
4 | use hir::{AsName, Module, ModuleDef, Name, Variant}; | 4 | use hir::{AsName, Module, ModuleDef, Name, Variant}; |
5 | use ide_db::helpers::{ | 5 | use ide_db::{ |
6 | insert_use::{insert_use, ImportScope}, | 6 | defs::Definition, |
7 | mod_path_to_ast, | 7 | helpers::{ |
8 | insert_use::{insert_use, ImportScope}, | ||
9 | mod_path_to_ast, | ||
10 | }, | ||
11 | search::FileReference, | ||
12 | RootDatabase, | ||
8 | }; | 13 | }; |
9 | use ide_db::{defs::Definition, search::Reference, RootDatabase}; | 14 | use rustc_hash::FxHashSet; |
10 | use rustc_hash::{FxHashMap, FxHashSet}; | ||
11 | use syntax::{ | 15 | use syntax::{ |
12 | algo::{find_node_at_offset, SyntaxRewriter}, | 16 | algo::{find_node_at_offset, SyntaxRewriter}, |
13 | ast::{self, edit::IndentLevel, make, AstNode, NameOwner, VisibilityOwner}, | 17 | ast::{self, edit::IndentLevel, make, AstNode, NameOwner, VisibilityOwner}, |
@@ -21,7 +25,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; | |||
21 | // Extracts a struct from enum variant. | 25 | // Extracts a struct from enum variant. |
22 | // | 26 | // |
23 | // ``` | 27 | // ``` |
24 | // enum A { <|>One(u32, u32) } | 28 | // enum A { $0One(u32, u32) } |
25 | // ``` | 29 | // ``` |
26 | // -> | 30 | // -> |
27 | // ``` | 31 | // ``` |
@@ -58,29 +62,29 @@ pub(crate) fn extract_struct_from_enum_variant( | |||
58 | let mut visited_modules_set = FxHashSet::default(); | 62 | let mut visited_modules_set = FxHashSet::default(); |
59 | let current_module = enum_hir.module(ctx.db()); | 63 | let current_module = enum_hir.module(ctx.db()); |
60 | visited_modules_set.insert(current_module); | 64 | visited_modules_set.insert(current_module); |
61 | let mut rewriters = FxHashMap::default(); | 65 | let mut def_rewriter = None; |
62 | for reference in usages { | 66 | for (file_id, references) in usages { |
63 | let rewriter = rewriters | 67 | let mut rewriter = SyntaxRewriter::default(); |
64 | .entry(reference.file_range.file_id) | 68 | let source_file = ctx.sema.parse(file_id); |
65 | .or_insert_with(SyntaxRewriter::default); | 69 | for reference in references { |
66 | let source_file = ctx.sema.parse(reference.file_range.file_id); | 70 | update_reference( |
67 | update_reference( | 71 | ctx, |
68 | ctx, | 72 | &mut rewriter, |
69 | rewriter, | 73 | reference, |
70 | reference, | 74 | &source_file, |
71 | &source_file, | 75 | &enum_module_def, |
72 | &enum_module_def, | 76 | &variant_hir_name, |
73 | &variant_hir_name, | 77 | &mut visited_modules_set, |
74 | &mut visited_modules_set, | 78 | ); |
75 | ); | 79 | } |
76 | } | 80 | if file_id == ctx.frange.file_id { |
77 | let mut rewriter = | 81 | def_rewriter = Some(rewriter); |
78 | rewriters.remove(&ctx.frange.file_id).unwrap_or_else(SyntaxRewriter::default); | 82 | continue; |
79 | for (file_id, rewriter) in rewriters { | 83 | } |
80 | builder.edit_file(file_id); | 84 | builder.edit_file(file_id); |
81 | builder.rewrite(rewriter); | 85 | builder.rewrite(rewriter); |
82 | } | 86 | } |
83 | builder.edit_file(ctx.frange.file_id); | 87 | let mut rewriter = def_rewriter.unwrap_or_default(); |
84 | update_variant(&mut rewriter, &variant); | 88 | update_variant(&mut rewriter, &variant); |
85 | extract_struct_def( | 89 | extract_struct_def( |
86 | &mut rewriter, | 90 | &mut rewriter, |
@@ -90,6 +94,7 @@ pub(crate) fn extract_struct_from_enum_variant( | |||
90 | &variant.parent_enum().syntax().clone().into(), | 94 | &variant.parent_enum().syntax().clone().into(), |
91 | enum_ast.visibility(), | 95 | enum_ast.visibility(), |
92 | ); | 96 | ); |
97 | builder.edit_file(ctx.frange.file_id); | ||
93 | builder.rewrite(rewriter); | 98 | builder.rewrite(rewriter); |
94 | }, | 99 | }, |
95 | ) | 100 | ) |
@@ -117,10 +122,14 @@ fn existing_definition(db: &RootDatabase, variant_name: &ast::Name, variant: &Va | |||
117 | .into_iter() | 122 | .into_iter() |
118 | .filter(|(_, def)| match def { | 123 | .filter(|(_, def)| match def { |
119 | // only check type-namespace | 124 | // only check type-namespace |
120 | hir::ScopeDef::ModuleDef(def) => matches!(def, | 125 | hir::ScopeDef::ModuleDef(def) => matches!( |
121 | ModuleDef::Module(_) | ModuleDef::Adt(_) | | 126 | def, |
122 | ModuleDef::Variant(_) | ModuleDef::Trait(_) | | 127 | ModuleDef::Module(_) |
123 | ModuleDef::TypeAlias(_) | ModuleDef::BuiltinType(_) | 128 | | ModuleDef::Adt(_) |
129 | | ModuleDef::Variant(_) | ||
130 | | ModuleDef::Trait(_) | ||
131 | | ModuleDef::TypeAlias(_) | ||
132 | | ModuleDef::BuiltinType(_) | ||
124 | ), | 133 | ), |
125 | _ => false, | 134 | _ => false, |
126 | }) | 135 | }) |
@@ -201,13 +210,13 @@ fn update_variant(rewriter: &mut SyntaxRewriter, variant: &ast::Variant) -> Opti | |||
201 | fn update_reference( | 210 | fn update_reference( |
202 | ctx: &AssistContext, | 211 | ctx: &AssistContext, |
203 | rewriter: &mut SyntaxRewriter, | 212 | rewriter: &mut SyntaxRewriter, |
204 | reference: Reference, | 213 | reference: FileReference, |
205 | source_file: &SourceFile, | 214 | source_file: &SourceFile, |
206 | enum_module_def: &ModuleDef, | 215 | enum_module_def: &ModuleDef, |
207 | variant_hir_name: &Name, | 216 | variant_hir_name: &Name, |
208 | visited_modules_set: &mut FxHashSet<Module>, | 217 | visited_modules_set: &mut FxHashSet<Module>, |
209 | ) -> Option<()> { | 218 | ) -> Option<()> { |
210 | let offset = reference.file_range.range.start(); | 219 | let offset = reference.range.start(); |
211 | let (segment, expr) = if let Some(path_expr) = | 220 | let (segment, expr) = if let Some(path_expr) = |
212 | find_node_at_offset::<ast::PathExpr>(source_file.syntax(), offset) | 221 | find_node_at_offset::<ast::PathExpr>(source_file.syntax(), offset) |
213 | { | 222 | { |
@@ -247,7 +256,7 @@ mod tests { | |||
247 | fn test_extract_struct_several_fields_tuple() { | 256 | fn test_extract_struct_several_fields_tuple() { |
248 | check_assist( | 257 | check_assist( |
249 | extract_struct_from_enum_variant, | 258 | extract_struct_from_enum_variant, |
250 | "enum A { <|>One(u32, u32) }", | 259 | "enum A { $0One(u32, u32) }", |
251 | r#"struct One(pub u32, pub u32); | 260 | r#"struct One(pub u32, pub u32); |
252 | 261 | ||
253 | enum A { One(One) }"#, | 262 | enum A { One(One) }"#, |
@@ -258,7 +267,7 @@ enum A { One(One) }"#, | |||
258 | fn test_extract_struct_several_fields_named() { | 267 | fn test_extract_struct_several_fields_named() { |
259 | check_assist( | 268 | check_assist( |
260 | extract_struct_from_enum_variant, | 269 | extract_struct_from_enum_variant, |
261 | "enum A { <|>One { foo: u32, bar: u32 } }", | 270 | "enum A { $0One { foo: u32, bar: u32 } }", |
262 | r#"struct One{ pub foo: u32, pub bar: u32 } | 271 | r#"struct One{ pub foo: u32, pub bar: u32 } |
263 | 272 | ||
264 | enum A { One(One) }"#, | 273 | enum A { One(One) }"#, |
@@ -269,7 +278,7 @@ enum A { One(One) }"#, | |||
269 | fn test_extract_struct_one_field_named() { | 278 | fn test_extract_struct_one_field_named() { |
270 | check_assist( | 279 | check_assist( |
271 | extract_struct_from_enum_variant, | 280 | extract_struct_from_enum_variant, |
272 | "enum A { <|>One { foo: u32 } }", | 281 | "enum A { $0One { foo: u32 } }", |
273 | r#"struct One{ pub foo: u32 } | 282 | r#"struct One{ pub foo: u32 } |
274 | 283 | ||
275 | enum A { One(One) }"#, | 284 | enum A { One(One) }"#, |
@@ -281,7 +290,7 @@ enum A { One(One) }"#, | |||
281 | check_assist( | 290 | check_assist( |
282 | extract_struct_from_enum_variant, | 291 | extract_struct_from_enum_variant, |
283 | r#"const One: () = (); | 292 | r#"const One: () = (); |
284 | enum A { <|>One(u32, u32) }"#, | 293 | enum A { $0One(u32, u32) }"#, |
285 | r#"const One: () = (); | 294 | r#"const One: () = (); |
286 | struct One(pub u32, pub u32); | 295 | struct One(pub u32, pub u32); |
287 | 296 | ||
@@ -293,7 +302,7 @@ enum A { One(One) }"#, | |||
293 | fn test_extract_struct_pub_visibility() { | 302 | fn test_extract_struct_pub_visibility() { |
294 | check_assist( | 303 | check_assist( |
295 | extract_struct_from_enum_variant, | 304 | extract_struct_from_enum_variant, |
296 | "pub enum A { <|>One(u32, u32) }", | 305 | "pub enum A { $0One(u32, u32) }", |
297 | r#"pub struct One(pub u32, pub u32); | 306 | r#"pub struct One(pub u32, pub u32); |
298 | 307 | ||
299 | pub enum A { One(One) }"#, | 308 | pub enum A { One(One) }"#, |
@@ -315,7 +324,7 @@ pub enum A { One(One) }"#, | |||
315 | } | 324 | } |
316 | 325 | ||
317 | pub enum MyEnum { | 326 | pub enum MyEnum { |
318 | <|>MyField(u8, u8), | 327 | $0MyField(u8, u8), |
319 | } | 328 | } |
320 | } | 329 | } |
321 | } | 330 | } |
@@ -357,7 +366,7 @@ fn another_fn() { | |||
357 | extract_struct_from_enum_variant, | 366 | extract_struct_from_enum_variant, |
358 | r#" | 367 | r#" |
359 | enum E { | 368 | enum E { |
360 | <|>V { i: i32, j: i32 } | 369 | $0V { i: i32, j: i32 } |
361 | } | 370 | } |
362 | 371 | ||
363 | fn f() { | 372 | fn f() { |
@@ -385,7 +394,7 @@ fn f() { | |||
385 | r#" | 394 | r#" |
386 | //- /main.rs | 395 | //- /main.rs |
387 | enum E { | 396 | enum E { |
388 | <|>V(i32, i32) | 397 | $0V(i32, i32) |
389 | } | 398 | } |
390 | mod foo; | 399 | mod foo; |
391 | 400 | ||
@@ -420,7 +429,7 @@ fn f() { | |||
420 | r#" | 429 | r#" |
421 | //- /main.rs | 430 | //- /main.rs |
422 | enum E { | 431 | enum E { |
423 | <|>V { i: i32, j: i32 } | 432 | $0V { i: i32, j: i32 } |
424 | } | 433 | } |
425 | mod foo; | 434 | mod foo; |
426 | 435 | ||
@@ -453,7 +462,7 @@ fn f() { | |||
453 | check_assist( | 462 | check_assist( |
454 | extract_struct_from_enum_variant, | 463 | extract_struct_from_enum_variant, |
455 | r#" | 464 | r#" |
456 | enum A { <|>One { a: u32, b: u32 } } | 465 | enum A { $0One { a: u32, b: u32 } } |
457 | 466 | ||
458 | struct B(A); | 467 | struct B(A); |
459 | 468 | ||
@@ -483,29 +492,29 @@ fn foo() { | |||
483 | 492 | ||
484 | #[test] | 493 | #[test] |
485 | fn test_extract_enum_not_applicable_for_element_with_no_fields() { | 494 | fn test_extract_enum_not_applicable_for_element_with_no_fields() { |
486 | check_not_applicable("enum A { <|>One }"); | 495 | check_not_applicable("enum A { $0One }"); |
487 | } | 496 | } |
488 | 497 | ||
489 | #[test] | 498 | #[test] |
490 | fn test_extract_enum_not_applicable_if_struct_exists() { | 499 | fn test_extract_enum_not_applicable_if_struct_exists() { |
491 | check_not_applicable( | 500 | check_not_applicable( |
492 | r#"struct One; | 501 | r#"struct One; |
493 | enum A { <|>One(u8, u32) }"#, | 502 | enum A { $0One(u8, u32) }"#, |
494 | ); | 503 | ); |
495 | } | 504 | } |
496 | 505 | ||
497 | #[test] | 506 | #[test] |
498 | fn test_extract_not_applicable_one_field() { | 507 | fn test_extract_not_applicable_one_field() { |
499 | check_not_applicable(r"enum A { <|>One(u32) }"); | 508 | check_not_applicable(r"enum A { $0One(u32) }"); |
500 | } | 509 | } |
501 | 510 | ||
502 | #[test] | 511 | #[test] |
503 | fn test_extract_not_applicable_no_field_tuple() { | 512 | fn test_extract_not_applicable_no_field_tuple() { |
504 | check_not_applicable(r"enum A { <|>None() }"); | 513 | check_not_applicable(r"enum A { $0None() }"); |
505 | } | 514 | } |
506 | 515 | ||
507 | #[test] | 516 | #[test] |
508 | fn test_extract_not_applicable_no_field_named() { | 517 | fn test_extract_not_applicable_no_field_named() { |
509 | check_not_applicable(r"enum A { <|>None {} }"); | 518 | check_not_applicable(r"enum A { $0None {} }"); |
510 | } | 519 | } |
511 | } | 520 | } |
diff --git a/crates/assists/src/handlers/extract_variable.rs b/crates/assists/src/handlers/extract_variable.rs index 9957012fe..98f3dc6ca 100644 --- a/crates/assists/src/handlers/extract_variable.rs +++ b/crates/assists/src/handlers/extract_variable.rs | |||
@@ -16,7 +16,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; | |||
16 | // | 16 | // |
17 | // ``` | 17 | // ``` |
18 | // fn main() { | 18 | // fn main() { |
19 | // <|>(1 + 2)<|> * 4; | 19 | // $0(1 + 2)$0 * 4; |
20 | // } | 20 | // } |
21 | // ``` | 21 | // ``` |
22 | // -> | 22 | // -> |
@@ -139,7 +139,7 @@ impl Anchor { | |||
139 | fn from(to_extract: &ast::Expr) -> Option<Anchor> { | 139 | fn from(to_extract: &ast::Expr) -> Option<Anchor> { |
140 | to_extract.syntax().ancestors().find_map(|node| { | 140 | to_extract.syntax().ancestors().find_map(|node| { |
141 | if let Some(expr) = | 141 | if let Some(expr) = |
142 | node.parent().and_then(ast::BlockExpr::cast).and_then(|it| it.expr()) | 142 | node.parent().and_then(ast::BlockExpr::cast).and_then(|it| it.tail_expr()) |
143 | { | 143 | { |
144 | if expr.syntax() == &node { | 144 | if expr.syntax() == &node { |
145 | mark::hit!(test_extract_var_last_expr); | 145 | mark::hit!(test_extract_var_last_expr); |
@@ -187,7 +187,7 @@ mod tests { | |||
187 | extract_variable, | 187 | extract_variable, |
188 | r#" | 188 | r#" |
189 | fn foo() { | 189 | fn foo() { |
190 | foo(<|>1 + 1<|>); | 190 | foo($01 + 1$0); |
191 | }"#, | 191 | }"#, |
192 | r#" | 192 | r#" |
193 | fn foo() { | 193 | fn foo() { |
@@ -200,7 +200,7 @@ fn foo() { | |||
200 | #[test] | 200 | #[test] |
201 | fn extract_var_in_comment_is_not_applicable() { | 201 | fn extract_var_in_comment_is_not_applicable() { |
202 | mark::check!(extract_var_in_comment_is_not_applicable); | 202 | mark::check!(extract_var_in_comment_is_not_applicable); |
203 | check_assist_not_applicable(extract_variable, "fn main() { 1 + /* <|>comment<|> */ 1; }"); | 203 | check_assist_not_applicable(extract_variable, "fn main() { 1 + /* $0comment$0 */ 1; }"); |
204 | } | 204 | } |
205 | 205 | ||
206 | #[test] | 206 | #[test] |
@@ -210,7 +210,7 @@ fn foo() { | |||
210 | extract_variable, | 210 | extract_variable, |
211 | r#" | 211 | r#" |
212 | fn foo() { | 212 | fn foo() { |
213 | <|>1 + 1<|>; | 213 | $01 + 1$0; |
214 | }"#, | 214 | }"#, |
215 | r#" | 215 | r#" |
216 | fn foo() { | 216 | fn foo() { |
@@ -221,7 +221,7 @@ fn foo() { | |||
221 | extract_variable, | 221 | extract_variable, |
222 | " | 222 | " |
223 | fn foo() { | 223 | fn foo() { |
224 | <|>{ let x = 0; x }<|> | 224 | $0{ let x = 0; x }$0 |
225 | something_else(); | 225 | something_else(); |
226 | }", | 226 | }", |
227 | " | 227 | " |
@@ -238,7 +238,7 @@ fn foo() { | |||
238 | extract_variable, | 238 | extract_variable, |
239 | " | 239 | " |
240 | fn foo() { | 240 | fn foo() { |
241 | <|>1<|> + 1; | 241 | $01$0 + 1; |
242 | }", | 242 | }", |
243 | " | 243 | " |
244 | fn foo() { | 244 | fn foo() { |
@@ -255,7 +255,7 @@ fn foo() { | |||
255 | extract_variable, | 255 | extract_variable, |
256 | r#" | 256 | r#" |
257 | fn foo() { | 257 | fn foo() { |
258 | bar(<|>1 + 1<|>) | 258 | bar($01 + 1$0) |
259 | } | 259 | } |
260 | "#, | 260 | "#, |
261 | r#" | 261 | r#" |
@@ -269,7 +269,7 @@ fn foo() { | |||
269 | extract_variable, | 269 | extract_variable, |
270 | r#" | 270 | r#" |
271 | fn foo() { | 271 | fn foo() { |
272 | <|>bar(1 + 1)<|> | 272 | $0bar(1 + 1)$0 |
273 | } | 273 | } |
274 | "#, | 274 | "#, |
275 | r#" | 275 | r#" |
@@ -289,7 +289,7 @@ fn foo() { | |||
289 | fn main() { | 289 | fn main() { |
290 | let x = true; | 290 | let x = true; |
291 | let tuple = match x { | 291 | let tuple = match x { |
292 | true => (<|>2 + 2<|>, true) | 292 | true => ($02 + 2$0, true) |
293 | _ => (0, false) | 293 | _ => (0, false) |
294 | }; | 294 | }; |
295 | } | 295 | } |
@@ -316,7 +316,7 @@ fn main() { | |||
316 | let tuple = match x { | 316 | let tuple = match x { |
317 | true => { | 317 | true => { |
318 | let y = 1; | 318 | let y = 1; |
319 | (<|>2 + y<|>, true) | 319 | ($02 + y$0, true) |
320 | } | 320 | } |
321 | _ => (0, false) | 321 | _ => (0, false) |
322 | }; | 322 | }; |
@@ -344,7 +344,7 @@ fn main() { | |||
344 | extract_variable, | 344 | extract_variable, |
345 | " | 345 | " |
346 | fn main() { | 346 | fn main() { |
347 | let lambda = |x: u32| <|>x * 2<|>; | 347 | let lambda = |x: u32| $0x * 2$0; |
348 | } | 348 | } |
349 | ", | 349 | ", |
350 | " | 350 | " |
@@ -361,7 +361,7 @@ fn main() { | |||
361 | extract_variable, | 361 | extract_variable, |
362 | " | 362 | " |
363 | fn main() { | 363 | fn main() { |
364 | let lambda = |x: u32| { <|>x * 2<|> }; | 364 | let lambda = |x: u32| { $0x * 2$0 }; |
365 | } | 365 | } |
366 | ", | 366 | ", |
367 | " | 367 | " |
@@ -378,7 +378,7 @@ fn main() { | |||
378 | extract_variable, | 378 | extract_variable, |
379 | " | 379 | " |
380 | fn main() { | 380 | fn main() { |
381 | let o = <|>Some(true)<|>; | 381 | let o = $0Some(true)$0; |
382 | } | 382 | } |
383 | ", | 383 | ", |
384 | " | 384 | " |
@@ -396,7 +396,7 @@ fn main() { | |||
396 | extract_variable, | 396 | extract_variable, |
397 | " | 397 | " |
398 | fn main() { | 398 | fn main() { |
399 | let v = <|>bar.foo()<|>; | 399 | let v = $0bar.foo()$0; |
400 | } | 400 | } |
401 | ", | 401 | ", |
402 | " | 402 | " |
@@ -414,7 +414,7 @@ fn main() { | |||
414 | extract_variable, | 414 | extract_variable, |
415 | " | 415 | " |
416 | fn foo() -> u32 { | 416 | fn foo() -> u32 { |
417 | <|>return 2 + 2<|>; | 417 | $0return 2 + 2$0; |
418 | } | 418 | } |
419 | ", | 419 | ", |
420 | " | 420 | " |
@@ -434,7 +434,7 @@ fn foo() -> u32 { | |||
434 | fn foo() -> u32 { | 434 | fn foo() -> u32 { |
435 | 435 | ||
436 | 436 | ||
437 | <|>return 2 + 2<|>; | 437 | $0return 2 + 2$0; |
438 | } | 438 | } |
439 | ", | 439 | ", |
440 | " | 440 | " |
@@ -452,7 +452,7 @@ fn foo() -> u32 { | |||
452 | " | 452 | " |
453 | fn foo() -> u32 { | 453 | fn foo() -> u32 { |
454 | 454 | ||
455 | <|>return 2 + 2<|>; | 455 | $0return 2 + 2$0; |
456 | } | 456 | } |
457 | ", | 457 | ", |
458 | " | 458 | " |
@@ -473,7 +473,7 @@ fn foo() -> u32 { | |||
473 | // bar | 473 | // bar |
474 | 474 | ||
475 | 475 | ||
476 | <|>return 2 + 2<|>; | 476 | $0return 2 + 2$0; |
477 | } | 477 | } |
478 | ", | 478 | ", |
479 | " | 479 | " |
@@ -497,7 +497,7 @@ fn foo() -> u32 { | |||
497 | " | 497 | " |
498 | fn main() { | 498 | fn main() { |
499 | let result = loop { | 499 | let result = loop { |
500 | <|>break 2 + 2<|>; | 500 | $0break 2 + 2$0; |
501 | }; | 501 | }; |
502 | } | 502 | } |
503 | ", | 503 | ", |
@@ -518,7 +518,7 @@ fn main() { | |||
518 | extract_variable, | 518 | extract_variable, |
519 | " | 519 | " |
520 | fn main() { | 520 | fn main() { |
521 | let v = <|>0f32 as u32<|>; | 521 | let v = $00f32 as u32$0; |
522 | } | 522 | } |
523 | ", | 523 | ", |
524 | " | 524 | " |
@@ -540,7 +540,7 @@ struct S { | |||
540 | } | 540 | } |
541 | 541 | ||
542 | fn main() { | 542 | fn main() { |
543 | S { foo: <|>1 + 1<|> } | 543 | S { foo: $01 + 1$0 } |
544 | } | 544 | } |
545 | "#, | 545 | "#, |
546 | r#" | 546 | r#" |
@@ -558,18 +558,18 @@ fn main() { | |||
558 | 558 | ||
559 | #[test] | 559 | #[test] |
560 | fn test_extract_var_for_return_not_applicable() { | 560 | fn test_extract_var_for_return_not_applicable() { |
561 | check_assist_not_applicable(extract_variable, "fn foo() { <|>return<|>; } "); | 561 | check_assist_not_applicable(extract_variable, "fn foo() { $0return$0; } "); |
562 | } | 562 | } |
563 | 563 | ||
564 | #[test] | 564 | #[test] |
565 | fn test_extract_var_for_break_not_applicable() { | 565 | fn test_extract_var_for_break_not_applicable() { |
566 | check_assist_not_applicable(extract_variable, "fn main() { loop { <|>break<|>; }; }"); | 566 | check_assist_not_applicable(extract_variable, "fn main() { loop { $0break$0; }; }"); |
567 | } | 567 | } |
568 | 568 | ||
569 | // FIXME: This is not quite correct, but good enough(tm) for the sorting heuristic | 569 | // FIXME: This is not quite correct, but good enough(tm) for the sorting heuristic |
570 | #[test] | 570 | #[test] |
571 | fn extract_var_target() { | 571 | fn extract_var_target() { |
572 | check_assist_target(extract_variable, "fn foo() -> u32 { <|>return 2 + 2<|>; }", "2 + 2"); | 572 | check_assist_target(extract_variable, "fn foo() -> u32 { $0return 2 + 2$0; }", "2 + 2"); |
573 | 573 | ||
574 | check_assist_target( | 574 | check_assist_target( |
575 | extract_variable, | 575 | extract_variable, |
@@ -577,7 +577,7 @@ fn main() { | |||
577 | fn main() { | 577 | fn main() { |
578 | let x = true; | 578 | let x = true; |
579 | let tuple = match x { | 579 | let tuple = match x { |
580 | true => (<|>2 + 2<|>, true) | 580 | true => ($02 + 2$0, true) |
581 | _ => (0, false) | 581 | _ => (0, false) |
582 | }; | 582 | }; |
583 | } | 583 | } |
diff --git a/crates/assists/src/handlers/fill_match_arms.rs b/crates/assists/src/handlers/fill_match_arms.rs index cb60a3128..da47187e4 100644 --- a/crates/assists/src/handlers/fill_match_arms.rs +++ b/crates/assists/src/handlers/fill_match_arms.rs | |||
@@ -21,7 +21,7 @@ use crate::{ | |||
21 | // | 21 | // |
22 | // fn handle(action: Action) { | 22 | // fn handle(action: Action) { |
23 | // match action { | 23 | // match action { |
24 | // <|> | 24 | // $0 |
25 | // } | 25 | // } |
26 | // } | 26 | // } |
27 | // ``` | 27 | // ``` |
@@ -196,7 +196,7 @@ fn build_pat(db: &RootDatabase, module: hir::Module, var: hir::Variant) -> Optio | |||
196 | let path = mod_path_to_ast(&module.find_use_path(db, ModuleDef::from(var))?); | 196 | let path = mod_path_to_ast(&module.find_use_path(db, ModuleDef::from(var))?); |
197 | 197 | ||
198 | // FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though | 198 | // FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though |
199 | let pat: ast::Pat = match var.source(db).value.kind() { | 199 | let pat: ast::Pat = match var.source(db)?.value.kind() { |
200 | ast::StructKind::Tuple(field_list) => { | 200 | ast::StructKind::Tuple(field_list) => { |
201 | let pats = iter::repeat(make::wildcard_pat().into()).take(field_list.fields().count()); | 201 | let pats = iter::repeat(make::wildcard_pat().into()).take(field_list.fields().count()); |
202 | make::tuple_struct_pat(path, pats).into() | 202 | make::tuple_struct_pat(path, pats).into() |
@@ -231,7 +231,7 @@ mod tests { | |||
231 | Cs(i32, Option<i32>), | 231 | Cs(i32, Option<i32>), |
232 | } | 232 | } |
233 | fn main() { | 233 | fn main() { |
234 | match A::As<|> { | 234 | match A::As$0 { |
235 | A::As, | 235 | A::As, |
236 | A::Bs{x,y:Some(_)} => {} | 236 | A::Bs{x,y:Some(_)} => {} |
237 | A::Cs(_, Some(_)) => {} | 237 | A::Cs(_, Some(_)) => {} |
@@ -249,7 +249,7 @@ mod tests { | |||
249 | fill_match_arms, | 249 | fill_match_arms, |
250 | r#" | 250 | r#" |
251 | fn main() { | 251 | fn main() { |
252 | match (0, false)<|> { | 252 | match (0, false)$0 { |
253 | } | 253 | } |
254 | } | 254 | } |
255 | "#, | 255 | "#, |
@@ -267,7 +267,7 @@ mod tests { | |||
267 | Cs(i32, Option<i32>), | 267 | Cs(i32, Option<i32>), |
268 | } | 268 | } |
269 | fn main() { | 269 | fn main() { |
270 | match A::As<|> { | 270 | match A::As$0 { |
271 | A::Bs { x, y: Some(_) } => {} | 271 | A::Bs { x, y: Some(_) } => {} |
272 | A::Cs(_, Some(_)) => {} | 272 | A::Cs(_, Some(_)) => {} |
273 | } | 273 | } |
@@ -297,7 +297,7 @@ mod tests { | |||
297 | r#" | 297 | r#" |
298 | enum A { As, Bs, Cs(Option<i32>) } | 298 | enum A { As, Bs, Cs(Option<i32>) } |
299 | fn main() { | 299 | fn main() { |
300 | match A::As<|> { | 300 | match A::As$0 { |
301 | A::Cs(_) | A::Bs => {} | 301 | A::Cs(_) | A::Bs => {} |
302 | } | 302 | } |
303 | } | 303 | } |
@@ -322,7 +322,7 @@ fn main() { | |||
322 | enum A { As, Bs, Cs, Ds(String), Es(B) } | 322 | enum A { As, Bs, Cs, Ds(String), Es(B) } |
323 | enum B { Xs, Ys } | 323 | enum B { Xs, Ys } |
324 | fn main() { | 324 | fn main() { |
325 | match A::As<|> { | 325 | match A::As$0 { |
326 | A::Bs if 0 < 1 => {} | 326 | A::Bs if 0 < 1 => {} |
327 | A::Ds(_value) => { let x = 1; } | 327 | A::Ds(_value) => { let x = 1; } |
328 | A::Es(B::Xs) => (), | 328 | A::Es(B::Xs) => (), |
@@ -352,7 +352,7 @@ fn main() { | |||
352 | r#" | 352 | r#" |
353 | enum A { As, Bs, Cs(Option<i32>) } | 353 | enum A { As, Bs, Cs(Option<i32>) } |
354 | fn main() { | 354 | fn main() { |
355 | match A::As<|> { | 355 | match A::As$0 { |
356 | A::As(_) => {} | 356 | A::As(_) => {} |
357 | a @ A::Bs(_) => {} | 357 | a @ A::Bs(_) => {} |
358 | } | 358 | } |
@@ -380,7 +380,7 @@ enum A { As, Bs, Cs(String), Ds(String, String), Es { x: usize, y: usize } } | |||
380 | 380 | ||
381 | fn main() { | 381 | fn main() { |
382 | let a = A::As; | 382 | let a = A::As; |
383 | match a<|> {} | 383 | match a$0 {} |
384 | } | 384 | } |
385 | "#, | 385 | "#, |
386 | r#" | 386 | r#" |
@@ -411,7 +411,7 @@ fn main() { | |||
411 | fn main() { | 411 | fn main() { |
412 | let a = A::One; | 412 | let a = A::One; |
413 | let b = B::One; | 413 | let b = B::One; |
414 | match (a<|>, b) {} | 414 | match (a$0, b) {} |
415 | } | 415 | } |
416 | "#, | 416 | "#, |
417 | r#" | 417 | r#" |
@@ -443,7 +443,7 @@ fn main() { | |||
443 | fn main() { | 443 | fn main() { |
444 | let a = A::One; | 444 | let a = A::One; |
445 | let b = B::One; | 445 | let b = B::One; |
446 | match (&a<|>, &b) {} | 446 | match (&a$0, &b) {} |
447 | } | 447 | } |
448 | "#, | 448 | "#, |
449 | r#" | 449 | r#" |
@@ -475,7 +475,7 @@ fn main() { | |||
475 | fn main() { | 475 | fn main() { |
476 | let a = A::One; | 476 | let a = A::One; |
477 | let b = B::One; | 477 | let b = B::One; |
478 | match (a<|>, b) { | 478 | match (a$0, b) { |
479 | (A::Two, B::One) => {} | 479 | (A::Two, B::One) => {} |
480 | } | 480 | } |
481 | } | 481 | } |
@@ -494,7 +494,7 @@ fn main() { | |||
494 | fn main() { | 494 | fn main() { |
495 | let a = A::One; | 495 | let a = A::One; |
496 | let b = B::One; | 496 | let b = B::One; |
497 | match (a<|>, b) { | 497 | match (a$0, b) { |
498 | (A::Two, B::One) => {} | 498 | (A::Two, B::One) => {} |
499 | (A::One, B::One) => {} | 499 | (A::One, B::One) => {} |
500 | (A::One, B::Two) => {} | 500 | (A::One, B::Two) => {} |
@@ -517,7 +517,7 @@ fn main() { | |||
517 | 517 | ||
518 | fn main() { | 518 | fn main() { |
519 | let a = A::One; | 519 | let a = A::One; |
520 | match (a<|>, ) { | 520 | match (a$0, ) { |
521 | } | 521 | } |
522 | } | 522 | } |
523 | "#, | 523 | "#, |
@@ -532,7 +532,7 @@ fn main() { | |||
532 | enum A { As } | 532 | enum A { As } |
533 | 533 | ||
534 | fn foo(a: &A) { | 534 | fn foo(a: &A) { |
535 | match a<|> { | 535 | match a$0 { |
536 | } | 536 | } |
537 | } | 537 | } |
538 | "#, | 538 | "#, |
@@ -555,7 +555,7 @@ fn main() { | |||
555 | } | 555 | } |
556 | 556 | ||
557 | fn foo(a: &mut A) { | 557 | fn foo(a: &mut A) { |
558 | match a<|> { | 558 | match a$0 { |
559 | } | 559 | } |
560 | } | 560 | } |
561 | "#, | 561 | "#, |
@@ -581,7 +581,7 @@ fn main() { | |||
581 | enum E { X, Y } | 581 | enum E { X, Y } |
582 | 582 | ||
583 | fn main() { | 583 | fn main() { |
584 | match E::X<|> {} | 584 | match E::X$0 {} |
585 | } | 585 | } |
586 | "#, | 586 | "#, |
587 | "match E::X {}", | 587 | "match E::X {}", |
@@ -597,7 +597,7 @@ fn main() { | |||
597 | 597 | ||
598 | fn main() { | 598 | fn main() { |
599 | match E::X { | 599 | match E::X { |
600 | <|>_ => {} | 600 | $0_ => {} |
601 | } | 601 | } |
602 | } | 602 | } |
603 | "#, | 603 | "#, |
@@ -624,7 +624,7 @@ fn main() { | |||
624 | 624 | ||
625 | fn main() { | 625 | fn main() { |
626 | match X { | 626 | match X { |
627 | <|> | 627 | $0 |
628 | } | 628 | } |
629 | } | 629 | } |
630 | "#, | 630 | "#, |
@@ -650,7 +650,7 @@ fn main() { | |||
650 | enum A { One, Two } | 650 | enum A { One, Two } |
651 | fn foo(a: A) { | 651 | fn foo(a: A) { |
652 | match a { | 652 | match a { |
653 | // foo bar baz<|> | 653 | // foo bar baz$0 |
654 | A::One => {} | 654 | A::One => {} |
655 | // This is where the rest should be | 655 | // This is where the rest should be |
656 | } | 656 | } |
@@ -678,7 +678,7 @@ fn main() { | |||
678 | enum A { One, Two } | 678 | enum A { One, Two } |
679 | fn foo(a: A) { | 679 | fn foo(a: A) { |
680 | match a { | 680 | match a { |
681 | // foo bar baz<|> | 681 | // foo bar baz$0 |
682 | } | 682 | } |
683 | } | 683 | } |
684 | "#, | 684 | "#, |
@@ -702,7 +702,7 @@ fn main() { | |||
702 | r#" | 702 | r#" |
703 | enum A { One, Two, } | 703 | enum A { One, Two, } |
704 | fn foo(a: A) { | 704 | fn foo(a: A) { |
705 | match a<|> { | 705 | match a$0 { |
706 | _ => (), | 706 | _ => (), |
707 | } | 707 | } |
708 | } | 708 | } |
@@ -724,7 +724,7 @@ fn main() { | |||
724 | mark::check!(option_order); | 724 | mark::check!(option_order); |
725 | let before = r#" | 725 | let before = r#" |
726 | fn foo(opt: Option<i32>) { | 726 | fn foo(opt: Option<i32>) { |
727 | match opt<|> { | 727 | match opt$0 { |
728 | } | 728 | } |
729 | } | 729 | } |
730 | "#; | 730 | "#; |
diff --git a/crates/assists/src/handlers/fix_visibility.rs b/crates/assists/src/handlers/fix_visibility.rs index 8558a8ff0..6c7824e55 100644 --- a/crates/assists/src/handlers/fix_visibility.rs +++ b/crates/assists/src/handlers/fix_visibility.rs | |||
@@ -18,7 +18,7 @@ use crate::{utils::vis_offset, AssistContext, AssistId, AssistKind, Assists}; | |||
18 | // fn frobnicate() {} | 18 | // fn frobnicate() {} |
19 | // } | 19 | // } |
20 | // fn main() { | 20 | // fn main() { |
21 | // m::frobnicate<|>() {} | 21 | // m::frobnicate$0() {} |
22 | // } | 22 | // } |
23 | // ``` | 23 | // ``` |
24 | // -> | 24 | // -> |
@@ -97,7 +97,7 @@ fn add_vis_to_referenced_record_field(acc: &mut Assists, ctx: &AssistContext) -> | |||
97 | let parent_name = parent.name(ctx.db()); | 97 | let parent_name = parent.name(ctx.db()); |
98 | let target_module = parent.module(ctx.db()); | 98 | let target_module = parent.module(ctx.db()); |
99 | 99 | ||
100 | let in_file_source = record_field_def.source(ctx.db()); | 100 | let in_file_source = record_field_def.source(ctx.db())?; |
101 | let (offset, current_visibility, target) = match in_file_source.value { | 101 | let (offset, current_visibility, target) = match in_file_source.value { |
102 | hir::FieldSource::Named(it) => { | 102 | hir::FieldSource::Named(it) => { |
103 | let s = it.syntax(); | 103 | let s = it.syntax(); |
@@ -145,53 +145,53 @@ fn target_data_for_def( | |||
145 | fn offset_target_and_file_id<S, Ast>( | 145 | fn offset_target_and_file_id<S, Ast>( |
146 | db: &dyn HirDatabase, | 146 | db: &dyn HirDatabase, |
147 | x: S, | 147 | x: S, |
148 | ) -> (TextSize, Option<ast::Visibility>, TextRange, FileId) | 148 | ) -> Option<(TextSize, Option<ast::Visibility>, TextRange, FileId)> |
149 | where | 149 | where |
150 | S: HasSource<Ast = Ast>, | 150 | S: HasSource<Ast = Ast>, |
151 | Ast: AstNode + ast::VisibilityOwner, | 151 | Ast: AstNode + ast::VisibilityOwner, |
152 | { | 152 | { |
153 | let source = x.source(db); | 153 | let source = x.source(db)?; |
154 | let in_file_syntax = source.syntax(); | 154 | let in_file_syntax = source.syntax(); |
155 | let file_id = in_file_syntax.file_id; | 155 | let file_id = in_file_syntax.file_id; |
156 | let syntax = in_file_syntax.value; | 156 | let syntax = in_file_syntax.value; |
157 | let current_visibility = source.value.visibility(); | 157 | let current_visibility = source.value.visibility(); |
158 | ( | 158 | Some(( |
159 | vis_offset(syntax), | 159 | vis_offset(syntax), |
160 | current_visibility, | 160 | current_visibility, |
161 | syntax.text_range(), | 161 | syntax.text_range(), |
162 | file_id.original_file(db.upcast()), | 162 | file_id.original_file(db.upcast()), |
163 | ) | 163 | )) |
164 | } | 164 | } |
165 | 165 | ||
166 | let target_name; | 166 | let target_name; |
167 | let (offset, current_visibility, target, target_file) = match def { | 167 | let (offset, current_visibility, target, target_file) = match def { |
168 | hir::ModuleDef::Function(f) => { | 168 | hir::ModuleDef::Function(f) => { |
169 | target_name = Some(f.name(db)); | 169 | target_name = Some(f.name(db)); |
170 | offset_target_and_file_id(db, f) | 170 | offset_target_and_file_id(db, f)? |
171 | } | 171 | } |
172 | hir::ModuleDef::Adt(adt) => { | 172 | hir::ModuleDef::Adt(adt) => { |
173 | target_name = Some(adt.name(db)); | 173 | target_name = Some(adt.name(db)); |
174 | match adt { | 174 | match adt { |
175 | hir::Adt::Struct(s) => offset_target_and_file_id(db, s), | 175 | hir::Adt::Struct(s) => offset_target_and_file_id(db, s)?, |
176 | hir::Adt::Union(u) => offset_target_and_file_id(db, u), | 176 | hir::Adt::Union(u) => offset_target_and_file_id(db, u)?, |
177 | hir::Adt::Enum(e) => offset_target_and_file_id(db, e), | 177 | hir::Adt::Enum(e) => offset_target_and_file_id(db, e)?, |
178 | } | 178 | } |
179 | } | 179 | } |
180 | hir::ModuleDef::Const(c) => { | 180 | hir::ModuleDef::Const(c) => { |
181 | target_name = c.name(db); | 181 | target_name = c.name(db); |
182 | offset_target_and_file_id(db, c) | 182 | offset_target_and_file_id(db, c)? |
183 | } | 183 | } |
184 | hir::ModuleDef::Static(s) => { | 184 | hir::ModuleDef::Static(s) => { |
185 | target_name = s.name(db); | 185 | target_name = s.name(db); |
186 | offset_target_and_file_id(db, s) | 186 | offset_target_and_file_id(db, s)? |
187 | } | 187 | } |
188 | hir::ModuleDef::Trait(t) => { | 188 | hir::ModuleDef::Trait(t) => { |
189 | target_name = Some(t.name(db)); | 189 | target_name = Some(t.name(db)); |
190 | offset_target_and_file_id(db, t) | 190 | offset_target_and_file_id(db, t)? |
191 | } | 191 | } |
192 | hir::ModuleDef::TypeAlias(t) => { | 192 | hir::ModuleDef::TypeAlias(t) => { |
193 | target_name = Some(t.name(db)); | 193 | target_name = Some(t.name(db)); |
194 | offset_target_and_file_id(db, t) | 194 | offset_target_and_file_id(db, t)? |
195 | } | 195 | } |
196 | hir::ModuleDef::Module(m) => { | 196 | hir::ModuleDef::Module(m) => { |
197 | target_name = m.name(db); | 197 | target_name = m.name(db); |
@@ -218,14 +218,14 @@ mod tests { | |||
218 | check_assist( | 218 | check_assist( |
219 | fix_visibility, | 219 | fix_visibility, |
220 | r"mod foo { fn foo() {} } | 220 | r"mod foo { fn foo() {} } |
221 | fn main() { foo::foo<|>() } ", | 221 | fn main() { foo::foo$0() } ", |
222 | r"mod foo { $0pub(crate) fn foo() {} } | 222 | r"mod foo { $0pub(crate) fn foo() {} } |
223 | fn main() { foo::foo() } ", | 223 | fn main() { foo::foo() } ", |
224 | ); | 224 | ); |
225 | check_assist_not_applicable( | 225 | check_assist_not_applicable( |
226 | fix_visibility, | 226 | fix_visibility, |
227 | r"mod foo { pub fn foo() {} } | 227 | r"mod foo { pub fn foo() {} } |
228 | fn main() { foo::foo<|>() } ", | 228 | fn main() { foo::foo$0() } ", |
229 | ) | 229 | ) |
230 | } | 230 | } |
231 | 231 | ||
@@ -234,38 +234,38 @@ mod tests { | |||
234 | check_assist( | 234 | check_assist( |
235 | fix_visibility, | 235 | fix_visibility, |
236 | r"mod foo { struct Foo; } | 236 | r"mod foo { struct Foo; } |
237 | fn main() { foo::Foo<|> } ", | 237 | fn main() { foo::Foo$0 } ", |
238 | r"mod foo { $0pub(crate) struct Foo; } | 238 | r"mod foo { $0pub(crate) struct Foo; } |
239 | fn main() { foo::Foo } ", | 239 | fn main() { foo::Foo } ", |
240 | ); | 240 | ); |
241 | check_assist_not_applicable( | 241 | check_assist_not_applicable( |
242 | fix_visibility, | 242 | fix_visibility, |
243 | r"mod foo { pub struct Foo; } | 243 | r"mod foo { pub struct Foo; } |
244 | fn main() { foo::Foo<|> } ", | 244 | fn main() { foo::Foo$0 } ", |
245 | ); | 245 | ); |
246 | check_assist( | 246 | check_assist( |
247 | fix_visibility, | 247 | fix_visibility, |
248 | r"mod foo { enum Foo; } | 248 | r"mod foo { enum Foo; } |
249 | fn main() { foo::Foo<|> } ", | 249 | fn main() { foo::Foo$0 } ", |
250 | r"mod foo { $0pub(crate) enum Foo; } | 250 | r"mod foo { $0pub(crate) enum Foo; } |
251 | fn main() { foo::Foo } ", | 251 | fn main() { foo::Foo } ", |
252 | ); | 252 | ); |
253 | check_assist_not_applicable( | 253 | check_assist_not_applicable( |
254 | fix_visibility, | 254 | fix_visibility, |
255 | r"mod foo { pub enum Foo; } | 255 | r"mod foo { pub enum Foo; } |
256 | fn main() { foo::Foo<|> } ", | 256 | fn main() { foo::Foo$0 } ", |
257 | ); | 257 | ); |
258 | check_assist( | 258 | check_assist( |
259 | fix_visibility, | 259 | fix_visibility, |
260 | r"mod foo { union Foo; } | 260 | r"mod foo { union Foo; } |
261 | fn main() { foo::Foo<|> } ", | 261 | fn main() { foo::Foo$0 } ", |
262 | r"mod foo { $0pub(crate) union Foo; } | 262 | r"mod foo { $0pub(crate) union Foo; } |
263 | fn main() { foo::Foo } ", | 263 | fn main() { foo::Foo } ", |
264 | ); | 264 | ); |
265 | check_assist_not_applicable( | 265 | check_assist_not_applicable( |
266 | fix_visibility, | 266 | fix_visibility, |
267 | r"mod foo { pub union Foo; } | 267 | r"mod foo { pub union Foo; } |
268 | fn main() { foo::Foo<|> } ", | 268 | fn main() { foo::Foo$0 } ", |
269 | ); | 269 | ); |
270 | } | 270 | } |
271 | 271 | ||
@@ -276,7 +276,7 @@ mod tests { | |||
276 | r" | 276 | r" |
277 | //- /main.rs | 277 | //- /main.rs |
278 | mod foo; | 278 | mod foo; |
279 | fn main() { foo::Foo<|> } | 279 | fn main() { foo::Foo$0 } |
280 | 280 | ||
281 | //- /foo.rs | 281 | //- /foo.rs |
282 | struct Foo; | 282 | struct Foo; |
@@ -291,7 +291,7 @@ struct Foo; | |||
291 | check_assist( | 291 | check_assist( |
292 | fix_visibility, | 292 | fix_visibility, |
293 | r"mod foo { pub struct Foo { bar: (), } } | 293 | r"mod foo { pub struct Foo { bar: (), } } |
294 | fn main() { foo::Foo { <|>bar: () }; } ", | 294 | fn main() { foo::Foo { $0bar: () }; } ", |
295 | r"mod foo { pub struct Foo { $0pub(crate) bar: (), } } | 295 | r"mod foo { pub struct Foo { $0pub(crate) bar: (), } } |
296 | fn main() { foo::Foo { bar: () }; } ", | 296 | fn main() { foo::Foo { bar: () }; } ", |
297 | ); | 297 | ); |
@@ -300,7 +300,7 @@ struct Foo; | |||
300 | r" | 300 | r" |
301 | //- /lib.rs | 301 | //- /lib.rs |
302 | mod foo; | 302 | mod foo; |
303 | fn main() { foo::Foo { <|>bar: () }; } | 303 | fn main() { foo::Foo { $0bar: () }; } |
304 | //- /foo.rs | 304 | //- /foo.rs |
305 | pub struct Foo { bar: () } | 305 | pub struct Foo { bar: () } |
306 | ", | 306 | ", |
@@ -310,14 +310,14 @@ pub struct Foo { bar: () } | |||
310 | check_assist_not_applicable( | 310 | check_assist_not_applicable( |
311 | fix_visibility, | 311 | fix_visibility, |
312 | r"mod foo { pub struct Foo { pub bar: (), } } | 312 | r"mod foo { pub struct Foo { pub bar: (), } } |
313 | fn main() { foo::Foo { <|>bar: () }; } ", | 313 | fn main() { foo::Foo { $0bar: () }; } ", |
314 | ); | 314 | ); |
315 | check_assist_not_applicable( | 315 | check_assist_not_applicable( |
316 | fix_visibility, | 316 | fix_visibility, |
317 | r" | 317 | r" |
318 | //- /lib.rs | 318 | //- /lib.rs |
319 | mod foo; | 319 | mod foo; |
320 | fn main() { foo::Foo { <|>bar: () }; } | 320 | fn main() { foo::Foo { $0bar: () }; } |
321 | //- /foo.rs | 321 | //- /foo.rs |
322 | pub struct Foo { pub bar: () } | 322 | pub struct Foo { pub bar: () } |
323 | ", | 323 | ", |
@@ -331,14 +331,14 @@ pub struct Foo { pub bar: () } | |||
331 | check_assist_not_applicable( | 331 | check_assist_not_applicable( |
332 | fix_visibility, | 332 | fix_visibility, |
333 | r"mod foo { pub enum Foo { Bar { bar: () } } } | 333 | r"mod foo { pub enum Foo { Bar { bar: () } } } |
334 | fn main() { foo::Foo::Bar { <|>bar: () }; } ", | 334 | fn main() { foo::Foo::Bar { $0bar: () }; } ", |
335 | ); | 335 | ); |
336 | check_assist_not_applicable( | 336 | check_assist_not_applicable( |
337 | fix_visibility, | 337 | fix_visibility, |
338 | r" | 338 | r" |
339 | //- /lib.rs | 339 | //- /lib.rs |
340 | mod foo; | 340 | mod foo; |
341 | fn main() { foo::Foo::Bar { <|>bar: () }; } | 341 | fn main() { foo::Foo::Bar { $0bar: () }; } |
342 | //- /foo.rs | 342 | //- /foo.rs |
343 | pub enum Foo { Bar { bar: () } } | 343 | pub enum Foo { Bar { bar: () } } |
344 | ", | 344 | ", |
@@ -346,14 +346,14 @@ pub enum Foo { Bar { bar: () } } | |||
346 | check_assist_not_applicable( | 346 | check_assist_not_applicable( |
347 | fix_visibility, | 347 | fix_visibility, |
348 | r"mod foo { pub struct Foo { pub bar: (), } } | 348 | r"mod foo { pub struct Foo { pub bar: (), } } |
349 | fn main() { foo::Foo { <|>bar: () }; } ", | 349 | fn main() { foo::Foo { $0bar: () }; } ", |
350 | ); | 350 | ); |
351 | check_assist_not_applicable( | 351 | check_assist_not_applicable( |
352 | fix_visibility, | 352 | fix_visibility, |
353 | r" | 353 | r" |
354 | //- /lib.rs | 354 | //- /lib.rs |
355 | mod foo; | 355 | mod foo; |
356 | fn main() { foo::Foo { <|>bar: () }; } | 356 | fn main() { foo::Foo { $0bar: () }; } |
357 | //- /foo.rs | 357 | //- /foo.rs |
358 | pub struct Foo { pub bar: () } | 358 | pub struct Foo { pub bar: () } |
359 | ", | 359 | ", |
@@ -367,7 +367,7 @@ pub struct Foo { pub bar: () } | |||
367 | check_assist( | 367 | check_assist( |
368 | fix_visibility, | 368 | fix_visibility, |
369 | r"mod foo { pub union Foo { bar: (), } } | 369 | r"mod foo { pub union Foo { bar: (), } } |
370 | fn main() { foo::Foo { <|>bar: () }; } ", | 370 | fn main() { foo::Foo { $0bar: () }; } ", |
371 | r"mod foo { pub union Foo { $0pub(crate) bar: (), } } | 371 | r"mod foo { pub union Foo { $0pub(crate) bar: (), } } |
372 | fn main() { foo::Foo { bar: () }; } ", | 372 | fn main() { foo::Foo { bar: () }; } ", |
373 | ); | 373 | ); |
@@ -376,7 +376,7 @@ pub struct Foo { pub bar: () } | |||
376 | r" | 376 | r" |
377 | //- /lib.rs | 377 | //- /lib.rs |
378 | mod foo; | 378 | mod foo; |
379 | fn main() { foo::Foo { <|>bar: () }; } | 379 | fn main() { foo::Foo { $0bar: () }; } |
380 | //- /foo.rs | 380 | //- /foo.rs |
381 | pub union Foo { bar: () } | 381 | pub union Foo { bar: () } |
382 | ", | 382 | ", |
@@ -386,14 +386,14 @@ pub union Foo { bar: () } | |||
386 | check_assist_not_applicable( | 386 | check_assist_not_applicable( |
387 | fix_visibility, | 387 | fix_visibility, |
388 | r"mod foo { pub union Foo { pub bar: (), } } | 388 | r"mod foo { pub union Foo { pub bar: (), } } |
389 | fn main() { foo::Foo { <|>bar: () }; } ", | 389 | fn main() { foo::Foo { $0bar: () }; } ", |
390 | ); | 390 | ); |
391 | check_assist_not_applicable( | 391 | check_assist_not_applicable( |
392 | fix_visibility, | 392 | fix_visibility, |
393 | r" | 393 | r" |
394 | //- /lib.rs | 394 | //- /lib.rs |
395 | mod foo; | 395 | mod foo; |
396 | fn main() { foo::Foo { <|>bar: () }; } | 396 | fn main() { foo::Foo { $0bar: () }; } |
397 | //- /foo.rs | 397 | //- /foo.rs |
398 | pub union Foo { pub bar: () } | 398 | pub union Foo { pub bar: () } |
399 | ", | 399 | ", |
@@ -405,14 +405,14 @@ pub union Foo { pub bar: () } | |||
405 | check_assist( | 405 | check_assist( |
406 | fix_visibility, | 406 | fix_visibility, |
407 | r"mod foo { const FOO: () = (); } | 407 | r"mod foo { const FOO: () = (); } |
408 | fn main() { foo::FOO<|> } ", | 408 | fn main() { foo::FOO$0 } ", |
409 | r"mod foo { $0pub(crate) const FOO: () = (); } | 409 | r"mod foo { $0pub(crate) const FOO: () = (); } |
410 | fn main() { foo::FOO } ", | 410 | fn main() { foo::FOO } ", |
411 | ); | 411 | ); |
412 | check_assist_not_applicable( | 412 | check_assist_not_applicable( |
413 | fix_visibility, | 413 | fix_visibility, |
414 | r"mod foo { pub const FOO: () = (); } | 414 | r"mod foo { pub const FOO: () = (); } |
415 | fn main() { foo::FOO<|> } ", | 415 | fn main() { foo::FOO$0 } ", |
416 | ); | 416 | ); |
417 | } | 417 | } |
418 | 418 | ||
@@ -421,14 +421,14 @@ pub union Foo { pub bar: () } | |||
421 | check_assist( | 421 | check_assist( |
422 | fix_visibility, | 422 | fix_visibility, |
423 | r"mod foo { static FOO: () = (); } | 423 | r"mod foo { static FOO: () = (); } |
424 | fn main() { foo::FOO<|> } ", | 424 | fn main() { foo::FOO$0 } ", |
425 | r"mod foo { $0pub(crate) static FOO: () = (); } | 425 | r"mod foo { $0pub(crate) static FOO: () = (); } |
426 | fn main() { foo::FOO } ", | 426 | fn main() { foo::FOO } ", |
427 | ); | 427 | ); |
428 | check_assist_not_applicable( | 428 | check_assist_not_applicable( |
429 | fix_visibility, | 429 | fix_visibility, |
430 | r"mod foo { pub static FOO: () = (); } | 430 | r"mod foo { pub static FOO: () = (); } |
431 | fn main() { foo::FOO<|> } ", | 431 | fn main() { foo::FOO$0 } ", |
432 | ); | 432 | ); |
433 | } | 433 | } |
434 | 434 | ||
@@ -437,14 +437,14 @@ pub union Foo { pub bar: () } | |||
437 | check_assist( | 437 | check_assist( |
438 | fix_visibility, | 438 | fix_visibility, |
439 | r"mod foo { trait Foo { fn foo(&self) {} } } | 439 | r"mod foo { trait Foo { fn foo(&self) {} } } |
440 | fn main() { let x: &dyn foo::<|>Foo; } ", | 440 | fn main() { let x: &dyn foo::$0Foo; } ", |
441 | r"mod foo { $0pub(crate) trait Foo { fn foo(&self) {} } } | 441 | r"mod foo { $0pub(crate) trait Foo { fn foo(&self) {} } } |
442 | fn main() { let x: &dyn foo::Foo; } ", | 442 | fn main() { let x: &dyn foo::Foo; } ", |
443 | ); | 443 | ); |
444 | check_assist_not_applicable( | 444 | check_assist_not_applicable( |
445 | fix_visibility, | 445 | fix_visibility, |
446 | r"mod foo { pub trait Foo { fn foo(&self) {} } } | 446 | r"mod foo { pub trait Foo { fn foo(&self) {} } } |
447 | fn main() { let x: &dyn foo::Foo<|>; } ", | 447 | fn main() { let x: &dyn foo::Foo$0; } ", |
448 | ); | 448 | ); |
449 | } | 449 | } |
450 | 450 | ||
@@ -453,14 +453,14 @@ pub union Foo { pub bar: () } | |||
453 | check_assist( | 453 | check_assist( |
454 | fix_visibility, | 454 | fix_visibility, |
455 | r"mod foo { type Foo = (); } | 455 | r"mod foo { type Foo = (); } |
456 | fn main() { let x: foo::Foo<|>; } ", | 456 | fn main() { let x: foo::Foo$0; } ", |
457 | r"mod foo { $0pub(crate) type Foo = (); } | 457 | r"mod foo { $0pub(crate) type Foo = (); } |
458 | fn main() { let x: foo::Foo; } ", | 458 | fn main() { let x: foo::Foo; } ", |
459 | ); | 459 | ); |
460 | check_assist_not_applicable( | 460 | check_assist_not_applicable( |
461 | fix_visibility, | 461 | fix_visibility, |
462 | r"mod foo { pub type Foo = (); } | 462 | r"mod foo { pub type Foo = (); } |
463 | fn main() { let x: foo::Foo<|>; } ", | 463 | fn main() { let x: foo::Foo$0; } ", |
464 | ); | 464 | ); |
465 | } | 465 | } |
466 | 466 | ||
@@ -469,7 +469,7 @@ pub union Foo { pub bar: () } | |||
469 | check_assist( | 469 | check_assist( |
470 | fix_visibility, | 470 | fix_visibility, |
471 | r"mod foo { mod bar { fn bar() {} } } | 471 | r"mod foo { mod bar { fn bar() {} } } |
472 | fn main() { foo::bar<|>::bar(); } ", | 472 | fn main() { foo::bar$0::bar(); } ", |
473 | r"mod foo { $0pub(crate) mod bar { fn bar() {} } } | 473 | r"mod foo { $0pub(crate) mod bar { fn bar() {} } } |
474 | fn main() { foo::bar::bar(); } ", | 474 | fn main() { foo::bar::bar(); } ", |
475 | ); | 475 | ); |
@@ -479,7 +479,7 @@ pub union Foo { pub bar: () } | |||
479 | r" | 479 | r" |
480 | //- /main.rs | 480 | //- /main.rs |
481 | mod foo; | 481 | mod foo; |
482 | fn main() { foo::bar<|>::baz(); } | 482 | fn main() { foo::bar$0::baz(); } |
483 | 483 | ||
484 | //- /foo.rs | 484 | //- /foo.rs |
485 | mod bar { | 485 | mod bar { |
@@ -495,7 +495,7 @@ mod bar { | |||
495 | check_assist_not_applicable( | 495 | check_assist_not_applicable( |
496 | fix_visibility, | 496 | fix_visibility, |
497 | r"mod foo { pub mod bar { pub fn bar() {} } } | 497 | r"mod foo { pub mod bar { pub fn bar() {} } } |
498 | fn main() { foo::bar<|>::bar(); } ", | 498 | fn main() { foo::bar$0::bar(); } ", |
499 | ); | 499 | ); |
500 | } | 500 | } |
501 | 501 | ||
@@ -506,7 +506,7 @@ mod bar { | |||
506 | r" | 506 | r" |
507 | //- /main.rs | 507 | //- /main.rs |
508 | mod foo; | 508 | mod foo; |
509 | fn main() { foo::bar<|>::baz(); } | 509 | fn main() { foo::bar$0::baz(); } |
510 | 510 | ||
511 | //- /foo.rs | 511 | //- /foo.rs |
512 | mod bar; | 512 | mod bar; |
@@ -525,7 +525,7 @@ pub fn baz() {} | |||
525 | r" | 525 | r" |
526 | //- /main.rs | 526 | //- /main.rs |
527 | mod foo; | 527 | mod foo; |
528 | fn main() { foo::bar<|>>::baz(); } | 528 | fn main() { foo::bar$0>::baz(); } |
529 | 529 | ||
530 | //- /foo.rs | 530 | //- /foo.rs |
531 | mod bar { | 531 | mod bar { |
@@ -545,7 +545,7 @@ mod bar { | |||
545 | fix_visibility, | 545 | fix_visibility, |
546 | r" | 546 | r" |
547 | //- /main.rs crate:a deps:foo | 547 | //- /main.rs crate:a deps:foo |
548 | foo::Bar<|> | 548 | foo::Bar$0 |
549 | //- /lib.rs crate:foo | 549 | //- /lib.rs crate:foo |
550 | struct Bar; | 550 | struct Bar; |
551 | ", | 551 | ", |
@@ -560,7 +560,7 @@ struct Bar; | |||
560 | fix_visibility, | 560 | fix_visibility, |
561 | r" | 561 | r" |
562 | //- /main.rs crate:a deps:foo | 562 | //- /main.rs crate:a deps:foo |
563 | foo::Bar<|> | 563 | foo::Bar$0 |
564 | //- /lib.rs crate:foo | 564 | //- /lib.rs crate:foo |
565 | pub(crate) struct Bar; | 565 | pub(crate) struct Bar; |
566 | ", | 566 | ", |
@@ -572,7 +572,7 @@ pub(crate) struct Bar; | |||
572 | r" | 572 | r" |
573 | //- /main.rs crate:a deps:foo | 573 | //- /main.rs crate:a deps:foo |
574 | fn main() { | 574 | fn main() { |
575 | foo::Foo { <|>bar: () }; | 575 | foo::Foo { $0bar: () }; |
576 | } | 576 | } |
577 | //- /lib.rs crate:foo | 577 | //- /lib.rs crate:foo |
578 | pub struct Foo { pub(crate) bar: () } | 578 | pub struct Foo { pub(crate) bar: () } |
@@ -593,7 +593,7 @@ pub struct Foo { pub(crate) bar: () } | |||
593 | use bar::Baz; | 593 | use bar::Baz; |
594 | mod bar { pub(super) struct Baz; } | 594 | mod bar { pub(super) struct Baz; } |
595 | } | 595 | } |
596 | foo::Baz<|> | 596 | foo::Baz$0 |
597 | ", | 597 | ", |
598 | r" | 598 | r" |
599 | mod foo { | 599 | mod foo { |
diff --git a/crates/assists/src/handlers/flip_binexpr.rs b/crates/assists/src/handlers/flip_binexpr.rs index 404f06133..209e5d43c 100644 --- a/crates/assists/src/handlers/flip_binexpr.rs +++ b/crates/assists/src/handlers/flip_binexpr.rs | |||
@@ -8,7 +8,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; | |||
8 | // | 8 | // |
9 | // ``` | 9 | // ``` |
10 | // fn main() { | 10 | // fn main() { |
11 | // let _ = 90 +<|> 2; | 11 | // let _ = 90 +$0 2; |
12 | // } | 12 | // } |
13 | // ``` | 13 | // ``` |
14 | // -> | 14 | // -> |
@@ -77,42 +77,34 @@ mod tests { | |||
77 | 77 | ||
78 | #[test] | 78 | #[test] |
79 | fn flip_binexpr_target_is_the_op() { | 79 | fn flip_binexpr_target_is_the_op() { |
80 | check_assist_target(flip_binexpr, "fn f() { let res = 1 ==<|> 2; }", "==") | 80 | check_assist_target(flip_binexpr, "fn f() { let res = 1 ==$0 2; }", "==") |
81 | } | 81 | } |
82 | 82 | ||
83 | #[test] | 83 | #[test] |
84 | fn flip_binexpr_not_applicable_for_assignment() { | 84 | fn flip_binexpr_not_applicable_for_assignment() { |
85 | check_assist_not_applicable(flip_binexpr, "fn f() { let mut _x = 1; _x +=<|> 2 }") | 85 | check_assist_not_applicable(flip_binexpr, "fn f() { let mut _x = 1; _x +=$0 2 }") |
86 | } | 86 | } |
87 | 87 | ||
88 | #[test] | 88 | #[test] |
89 | fn flip_binexpr_works_for_eq() { | 89 | fn flip_binexpr_works_for_eq() { |
90 | check_assist( | 90 | check_assist(flip_binexpr, "fn f() { let res = 1 ==$0 2; }", "fn f() { let res = 2 == 1; }") |
91 | flip_binexpr, | ||
92 | "fn f() { let res = 1 ==<|> 2; }", | ||
93 | "fn f() { let res = 2 == 1; }", | ||
94 | ) | ||
95 | } | 91 | } |
96 | 92 | ||
97 | #[test] | 93 | #[test] |
98 | fn flip_binexpr_works_for_gt() { | 94 | fn flip_binexpr_works_for_gt() { |
99 | check_assist(flip_binexpr, "fn f() { let res = 1 ><|> 2; }", "fn f() { let res = 2 < 1; }") | 95 | check_assist(flip_binexpr, "fn f() { let res = 1 >$0 2; }", "fn f() { let res = 2 < 1; }") |
100 | } | 96 | } |
101 | 97 | ||
102 | #[test] | 98 | #[test] |
103 | fn flip_binexpr_works_for_lteq() { | 99 | fn flip_binexpr_works_for_lteq() { |
104 | check_assist( | 100 | check_assist(flip_binexpr, "fn f() { let res = 1 <=$0 2; }", "fn f() { let res = 2 >= 1; }") |
105 | flip_binexpr, | ||
106 | "fn f() { let res = 1 <=<|> 2; }", | ||
107 | "fn f() { let res = 2 >= 1; }", | ||
108 | ) | ||
109 | } | 101 | } |
110 | 102 | ||
111 | #[test] | 103 | #[test] |
112 | fn flip_binexpr_works_for_complex_expr() { | 104 | fn flip_binexpr_works_for_complex_expr() { |
113 | check_assist( | 105 | check_assist( |
114 | flip_binexpr, | 106 | flip_binexpr, |
115 | "fn f() { let res = (1 + 1) ==<|> (2 + 2); }", | 107 | "fn f() { let res = (1 + 1) ==$0 (2 + 2); }", |
116 | "fn f() { let res = (2 + 2) == (1 + 1); }", | 108 | "fn f() { let res = (2 + 2) == (1 + 1); }", |
117 | ) | 109 | ) |
118 | } | 110 | } |
@@ -125,7 +117,7 @@ mod tests { | |||
125 | fn dyn_eq(&self, other: &dyn Diagnostic) -> bool { | 117 | fn dyn_eq(&self, other: &dyn Diagnostic) -> bool { |
126 | match other.downcast_ref::<Self>() { | 118 | match other.downcast_ref::<Self>() { |
127 | None => false, | 119 | None => false, |
128 | Some(it) => it ==<|> self, | 120 | Some(it) => it ==$0 self, |
129 | } | 121 | } |
130 | } | 122 | } |
131 | "#, | 123 | "#, |
diff --git a/crates/assists/src/handlers/flip_comma.rs b/crates/assists/src/handlers/flip_comma.rs index 64b4b1a76..18cf64a34 100644 --- a/crates/assists/src/handlers/flip_comma.rs +++ b/crates/assists/src/handlers/flip_comma.rs | |||
@@ -8,7 +8,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; | |||
8 | // | 8 | // |
9 | // ``` | 9 | // ``` |
10 | // fn main() { | 10 | // fn main() { |
11 | // ((1, 2),<|> (3, 4)); | 11 | // ((1, 2),$0 (3, 4)); |
12 | // } | 12 | // } |
13 | // ``` | 13 | // ``` |
14 | // -> | 14 | // -> |
@@ -49,14 +49,14 @@ mod tests { | |||
49 | fn flip_comma_works_for_function_parameters() { | 49 | fn flip_comma_works_for_function_parameters() { |
50 | check_assist( | 50 | check_assist( |
51 | flip_comma, | 51 | flip_comma, |
52 | "fn foo(x: i32,<|> y: Result<(), ()>) {}", | 52 | r#"fn foo(x: i32,$0 y: Result<(), ()>) {}"#, |
53 | "fn foo(y: Result<(), ()>, x: i32) {}", | 53 | r#"fn foo(y: Result<(), ()>, x: i32) {}"#, |
54 | ) | 54 | ) |
55 | } | 55 | } |
56 | 56 | ||
57 | #[test] | 57 | #[test] |
58 | fn flip_comma_target() { | 58 | fn flip_comma_target() { |
59 | check_assist_target(flip_comma, "fn foo(x: i32,<|> y: Result<(), ()>) {}", ",") | 59 | check_assist_target(flip_comma, r#"fn foo(x: i32,$0 y: Result<(), ()>) {}"#, ",") |
60 | } | 60 | } |
61 | 61 | ||
62 | #[test] | 62 | #[test] |
@@ -68,7 +68,7 @@ mod tests { | |||
68 | check_assist_target( | 68 | check_assist_target( |
69 | flip_comma, | 69 | flip_comma, |
70 | "pub enum Test { \ | 70 | "pub enum Test { \ |
71 | A,<|> \ | 71 | A,$0 \ |
72 | }", | 72 | }", |
73 | ",", | 73 | ",", |
74 | ); | 74 | ); |
@@ -76,7 +76,7 @@ mod tests { | |||
76 | check_assist_target( | 76 | check_assist_target( |
77 | flip_comma, | 77 | flip_comma, |
78 | "pub struct Test { \ | 78 | "pub struct Test { \ |
79 | foo: usize,<|> \ | 79 | foo: usize,$0 \ |
80 | }", | 80 | }", |
81 | ",", | 81 | ",", |
82 | ); | 82 | ); |
diff --git a/crates/assists/src/handlers/flip_trait_bound.rs b/crates/assists/src/handlers/flip_trait_bound.rs index 92ee42181..d419d263e 100644 --- a/crates/assists/src/handlers/flip_trait_bound.rs +++ b/crates/assists/src/handlers/flip_trait_bound.rs | |||
@@ -11,7 +11,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; | |||
11 | // Flips two trait bounds. | 11 | // Flips two trait bounds. |
12 | // | 12 | // |
13 | // ``` | 13 | // ``` |
14 | // fn foo<T: Clone +<|> Copy>() { } | 14 | // fn foo<T: Clone +$0 Copy>() { } |
15 | // ``` | 15 | // ``` |
16 | // -> | 16 | // -> |
17 | // ``` | 17 | // ``` |
@@ -52,19 +52,19 @@ mod tests { | |||
52 | 52 | ||
53 | #[test] | 53 | #[test] |
54 | fn flip_trait_bound_assist_available() { | 54 | fn flip_trait_bound_assist_available() { |
55 | check_assist_target(flip_trait_bound, "struct S<T> where T: A <|>+ B + C { }", "+") | 55 | check_assist_target(flip_trait_bound, "struct S<T> where T: A $0+ B + C { }", "+") |
56 | } | 56 | } |
57 | 57 | ||
58 | #[test] | 58 | #[test] |
59 | fn flip_trait_bound_not_applicable_for_single_trait_bound() { | 59 | fn flip_trait_bound_not_applicable_for_single_trait_bound() { |
60 | check_assist_not_applicable(flip_trait_bound, "struct S<T> where T: <|>A { }") | 60 | check_assist_not_applicable(flip_trait_bound, "struct S<T> where T: $0A { }") |
61 | } | 61 | } |
62 | 62 | ||
63 | #[test] | 63 | #[test] |
64 | fn flip_trait_bound_works_for_struct() { | 64 | fn flip_trait_bound_works_for_struct() { |
65 | check_assist( | 65 | check_assist( |
66 | flip_trait_bound, | 66 | flip_trait_bound, |
67 | "struct S<T> where T: A <|>+ B { }", | 67 | "struct S<T> where T: A $0+ B { }", |
68 | "struct S<T> where T: B + A { }", | 68 | "struct S<T> where T: B + A { }", |
69 | ) | 69 | ) |
70 | } | 70 | } |
@@ -73,21 +73,21 @@ mod tests { | |||
73 | fn flip_trait_bound_works_for_trait_impl() { | 73 | fn flip_trait_bound_works_for_trait_impl() { |
74 | check_assist( | 74 | check_assist( |
75 | flip_trait_bound, | 75 | flip_trait_bound, |
76 | "impl X for S<T> where T: A +<|> B { }", | 76 | "impl X for S<T> where T: A +$0 B { }", |
77 | "impl X for S<T> where T: B + A { }", | 77 | "impl X for S<T> where T: B + A { }", |
78 | ) | 78 | ) |
79 | } | 79 | } |
80 | 80 | ||
81 | #[test] | 81 | #[test] |
82 | fn flip_trait_bound_works_for_fn() { | 82 | fn flip_trait_bound_works_for_fn() { |
83 | check_assist(flip_trait_bound, "fn f<T: A <|>+ B>(t: T) { }", "fn f<T: B + A>(t: T) { }") | 83 | check_assist(flip_trait_bound, "fn f<T: A $0+ B>(t: T) { }", "fn f<T: B + A>(t: T) { }") |
84 | } | 84 | } |
85 | 85 | ||
86 | #[test] | 86 | #[test] |
87 | fn flip_trait_bound_works_for_fn_where_clause() { | 87 | fn flip_trait_bound_works_for_fn_where_clause() { |
88 | check_assist( | 88 | check_assist( |
89 | flip_trait_bound, | 89 | flip_trait_bound, |
90 | "fn f<T>(t: T) where T: A +<|> B { }", | 90 | "fn f<T>(t: T) where T: A +$0 B { }", |
91 | "fn f<T>(t: T) where T: B + A { }", | 91 | "fn f<T>(t: T) where T: B + A { }", |
92 | ) | 92 | ) |
93 | } | 93 | } |
@@ -96,7 +96,7 @@ mod tests { | |||
96 | fn flip_trait_bound_works_for_lifetime() { | 96 | fn flip_trait_bound_works_for_lifetime() { |
97 | check_assist( | 97 | check_assist( |
98 | flip_trait_bound, | 98 | flip_trait_bound, |
99 | "fn f<T>(t: T) where T: A <|>+ 'static { }", | 99 | "fn f<T>(t: T) where T: A $0+ 'static { }", |
100 | "fn f<T>(t: T) where T: 'static + A { }", | 100 | "fn f<T>(t: T) where T: 'static + A { }", |
101 | ) | 101 | ) |
102 | } | 102 | } |
@@ -105,7 +105,7 @@ mod tests { | |||
105 | fn flip_trait_bound_works_for_complex_bounds() { | 105 | fn flip_trait_bound_works_for_complex_bounds() { |
106 | check_assist( | 106 | check_assist( |
107 | flip_trait_bound, | 107 | flip_trait_bound, |
108 | "struct S<T> where T: A<T> <|>+ b_mod::B<T> + C<T> { }", | 108 | "struct S<T> where T: A<T> $0+ b_mod::B<T> + C<T> { }", |
109 | "struct S<T> where T: b_mod::B<T> + A<T> + C<T> { }", | 109 | "struct S<T> where T: b_mod::B<T> + A<T> + C<T> { }", |
110 | ) | 110 | ) |
111 | } | 111 | } |
@@ -114,7 +114,7 @@ mod tests { | |||
114 | fn flip_trait_bound_works_for_long_bounds() { | 114 | fn flip_trait_bound_works_for_long_bounds() { |
115 | check_assist( | 115 | check_assist( |
116 | flip_trait_bound, | 116 | flip_trait_bound, |
117 | "struct S<T> where T: A + B + C + D + E + F +<|> G + H + I + J { }", | 117 | "struct S<T> where T: A + B + C + D + E + F +$0 G + H + I + J { }", |
118 | "struct S<T> where T: A + B + C + D + E + G + F + H + I + J { }", | 118 | "struct S<T> where T: A + B + C + D + E + G + F + H + I + J { }", |
119 | ) | 119 | ) |
120 | } | 120 | } |
diff --git a/crates/assists/src/handlers/generate_default_from_enum_variant.rs b/crates/assists/src/handlers/generate_default_from_enum_variant.rs index bcea46735..6a2ab9596 100644 --- a/crates/assists/src/handlers/generate_default_from_enum_variant.rs +++ b/crates/assists/src/handlers/generate_default_from_enum_variant.rs | |||
@@ -12,7 +12,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; | |||
12 | // ``` | 12 | // ``` |
13 | // enum Version { | 13 | // enum Version { |
14 | // Undefined, | 14 | // Undefined, |
15 | // Minor<|>, | 15 | // Minor$0, |
16 | // Major, | 16 | // Major, |
17 | // } | 17 | // } |
18 | // ``` | 18 | // ``` |
@@ -108,7 +108,7 @@ mod tests { | |||
108 | r#" | 108 | r#" |
109 | enum Variant { | 109 | enum Variant { |
110 | Undefined, | 110 | Undefined, |
111 | Minor<|>, | 111 | Minor$0, |
112 | Major, | 112 | Major, |
113 | }"#, | 113 | }"#, |
114 | r#"enum Variant { | 114 | r#"enum Variant { |
@@ -132,7 +132,7 @@ impl Default for Variant { | |||
132 | r#" | 132 | r#" |
133 | enum Variant { | 133 | enum Variant { |
134 | Undefined, | 134 | Undefined, |
135 | Minor<|>, | 135 | Minor$0, |
136 | Major, | 136 | Major, |
137 | } | 137 | } |
138 | 138 | ||
@@ -151,7 +151,7 @@ impl Default for Variant { | |||
151 | r#" | 151 | r#" |
152 | enum Variant { | 152 | enum Variant { |
153 | Undefined, | 153 | Undefined, |
154 | Minor(u32)<|>, | 154 | Minor(u32)$0, |
155 | Major, | 155 | Major, |
156 | }"#, | 156 | }"#, |
157 | ); | 157 | ); |
@@ -161,7 +161,7 @@ enum Variant { | |||
161 | fn test_generate_default_from_variant_with_one_variant() { | 161 | fn test_generate_default_from_variant_with_one_variant() { |
162 | check_assist( | 162 | check_assist( |
163 | generate_default_from_enum_variant, | 163 | generate_default_from_enum_variant, |
164 | r#"enum Variant { Undefi<|>ned }"#, | 164 | r#"enum Variant { Undefi$0ned }"#, |
165 | r#" | 165 | r#" |
166 | enum Variant { Undefined } | 166 | enum Variant { Undefined } |
167 | 167 | ||
diff --git a/crates/assists/src/handlers/generate_derive.rs b/crates/assists/src/handlers/generate_derive.rs index 314504e15..f876b7684 100644 --- a/crates/assists/src/handlers/generate_derive.rs +++ b/crates/assists/src/handlers/generate_derive.rs | |||
@@ -13,7 +13,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; | |||
13 | // ``` | 13 | // ``` |
14 | // struct Point { | 14 | // struct Point { |
15 | // x: u32, | 15 | // x: u32, |
16 | // y: u32,<|> | 16 | // y: u32,$0 |
17 | // } | 17 | // } |
18 | // ``` | 18 | // ``` |
19 | // -> | 19 | // -> |
@@ -76,12 +76,12 @@ mod tests { | |||
76 | fn add_derive_new() { | 76 | fn add_derive_new() { |
77 | check_assist( | 77 | check_assist( |
78 | generate_derive, | 78 | generate_derive, |
79 | "struct Foo { a: i32, <|>}", | 79 | "struct Foo { a: i32, $0}", |
80 | "#[derive($0)]\nstruct Foo { a: i32, }", | 80 | "#[derive($0)]\nstruct Foo { a: i32, }", |
81 | ); | 81 | ); |
82 | check_assist( | 82 | check_assist( |
83 | generate_derive, | 83 | generate_derive, |
84 | "struct Foo { <|> a: i32, }", | 84 | "struct Foo { $0 a: i32, }", |
85 | "#[derive($0)]\nstruct Foo { a: i32, }", | 85 | "#[derive($0)]\nstruct Foo { a: i32, }", |
86 | ); | 86 | ); |
87 | } | 87 | } |
@@ -90,7 +90,7 @@ mod tests { | |||
90 | fn add_derive_existing() { | 90 | fn add_derive_existing() { |
91 | check_assist( | 91 | check_assist( |
92 | generate_derive, | 92 | generate_derive, |
93 | "#[derive(Clone)]\nstruct Foo { a: i32<|>, }", | 93 | "#[derive(Clone)]\nstruct Foo { a: i32$0, }", |
94 | "#[derive(Clone$0)]\nstruct Foo { a: i32, }", | 94 | "#[derive(Clone$0)]\nstruct Foo { a: i32, }", |
95 | ); | 95 | ); |
96 | } | 96 | } |
@@ -102,7 +102,7 @@ mod tests { | |||
102 | " | 102 | " |
103 | /// `Foo` is a pretty important struct. | 103 | /// `Foo` is a pretty important struct. |
104 | /// It does stuff. | 104 | /// It does stuff. |
105 | struct Foo { a: i32<|>, } | 105 | struct Foo { a: i32$0, } |
106 | ", | 106 | ", |
107 | " | 107 | " |
108 | /// `Foo` is a pretty important struct. | 108 | /// `Foo` is a pretty important struct. |
@@ -121,7 +121,7 @@ struct Foo { a: i32, } | |||
121 | struct SomeThingIrrelevant; | 121 | struct SomeThingIrrelevant; |
122 | /// `Foo` is a pretty important struct. | 122 | /// `Foo` is a pretty important struct. |
123 | /// It does stuff. | 123 | /// It does stuff. |
124 | struct Foo { a: i32<|>, } | 124 | struct Foo { a: i32$0, } |
125 | struct EvenMoreIrrelevant; | 125 | struct EvenMoreIrrelevant; |
126 | ", | 126 | ", |
127 | "/// `Foo` is a pretty important struct. | 127 | "/// `Foo` is a pretty important struct. |
diff --git a/crates/assists/src/handlers/generate_from_impl_for_enum.rs b/crates/assists/src/handlers/generate_from_impl_for_enum.rs index 3c374e5d9..d9af6ab11 100644 --- a/crates/assists/src/handlers/generate_from_impl_for_enum.rs +++ b/crates/assists/src/handlers/generate_from_impl_for_enum.rs | |||
@@ -10,7 +10,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; | |||
10 | // Adds a From impl for an enum variant with one tuple field. | 10 | // Adds a From impl for an enum variant with one tuple field. |
11 | // | 11 | // |
12 | // ``` | 12 | // ``` |
13 | // enum A { <|>One(u32) } | 13 | // enum A { $0One(u32) } |
14 | // ``` | 14 | // ``` |
15 | // -> | 15 | // -> |
16 | // ``` | 16 | // ``` |
@@ -101,7 +101,7 @@ mod tests { | |||
101 | fn test_generate_from_impl_for_enum() { | 101 | fn test_generate_from_impl_for_enum() { |
102 | check_assist( | 102 | check_assist( |
103 | generate_from_impl_for_enum, | 103 | generate_from_impl_for_enum, |
104 | "enum A { <|>One(u32) }", | 104 | "enum A { $0One(u32) }", |
105 | r#"enum A { One(u32) } | 105 | r#"enum A { One(u32) } |
106 | 106 | ||
107 | impl From<u32> for A { | 107 | impl From<u32> for A { |
@@ -116,7 +116,7 @@ impl From<u32> for A { | |||
116 | fn test_generate_from_impl_for_enum_complicated_path() { | 116 | fn test_generate_from_impl_for_enum_complicated_path() { |
117 | check_assist( | 117 | check_assist( |
118 | generate_from_impl_for_enum, | 118 | generate_from_impl_for_enum, |
119 | r#"enum A { <|>One(foo::bar::baz::Boo) }"#, | 119 | r#"enum A { $0One(foo::bar::baz::Boo) }"#, |
120 | r#"enum A { One(foo::bar::baz::Boo) } | 120 | r#"enum A { One(foo::bar::baz::Boo) } |
121 | 121 | ||
122 | impl From<foo::bar::baz::Boo> for A { | 122 | impl From<foo::bar::baz::Boo> for A { |
@@ -135,17 +135,17 @@ impl From<foo::bar::baz::Boo> for A { | |||
135 | 135 | ||
136 | #[test] | 136 | #[test] |
137 | fn test_add_from_impl_no_element() { | 137 | fn test_add_from_impl_no_element() { |
138 | check_not_applicable("enum A { <|>One }"); | 138 | check_not_applicable("enum A { $0One }"); |
139 | } | 139 | } |
140 | 140 | ||
141 | #[test] | 141 | #[test] |
142 | fn test_add_from_impl_more_than_one_element_in_tuple() { | 142 | fn test_add_from_impl_more_than_one_element_in_tuple() { |
143 | check_not_applicable("enum A { <|>One(u32, String) }"); | 143 | check_not_applicable("enum A { $0One(u32, String) }"); |
144 | } | 144 | } |
145 | 145 | ||
146 | #[test] | 146 | #[test] |
147 | fn test_add_from_impl_struct_variant() { | 147 | fn test_add_from_impl_struct_variant() { |
148 | check_not_applicable("enum A { <|>One { x: u32 } }"); | 148 | check_not_applicable("enum A { $0One { x: u32 } }"); |
149 | } | 149 | } |
150 | 150 | ||
151 | #[test] | 151 | #[test] |
@@ -153,7 +153,7 @@ impl From<foo::bar::baz::Boo> for A { | |||
153 | mark::check!(test_add_from_impl_already_exists); | 153 | mark::check!(test_add_from_impl_already_exists); |
154 | check_not_applicable( | 154 | check_not_applicable( |
155 | r#" | 155 | r#" |
156 | enum A { <|>One(u32), } | 156 | enum A { $0One(u32), } |
157 | 157 | ||
158 | impl From<u32> for A { | 158 | impl From<u32> for A { |
159 | fn from(v: u32) -> Self { | 159 | fn from(v: u32) -> Self { |
@@ -168,7 +168,7 @@ impl From<u32> for A { | |||
168 | fn test_add_from_impl_different_variant_impl_exists() { | 168 | fn test_add_from_impl_different_variant_impl_exists() { |
169 | check_assist( | 169 | check_assist( |
170 | generate_from_impl_for_enum, | 170 | generate_from_impl_for_enum, |
171 | r#"enum A { <|>One(u32), Two(String), } | 171 | r#"enum A { $0One(u32), Two(String), } |
172 | 172 | ||
173 | impl From<String> for A { | 173 | impl From<String> for A { |
174 | fn from(v: String) -> Self { | 174 | fn from(v: String) -> Self { |
diff --git a/crates/assists/src/handlers/generate_function.rs b/crates/assists/src/handlers/generate_function.rs index f4cf155b6..06ac85f67 100644 --- a/crates/assists/src/handlers/generate_function.rs +++ b/crates/assists/src/handlers/generate_function.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use hir::HirDisplay; | 1 | use hir::HirDisplay; |
2 | use ide_db::base_db::FileId; | 2 | use ide_db::{base_db::FileId, helpers::SnippetCap}; |
3 | use rustc_hash::{FxHashMap, FxHashSet}; | 3 | use rustc_hash::{FxHashMap, FxHashSet}; |
4 | use syntax::{ | 4 | use syntax::{ |
5 | ast::{ | 5 | ast::{ |
@@ -11,7 +11,6 @@ use syntax::{ | |||
11 | }; | 11 | }; |
12 | 12 | ||
13 | use crate::{ | 13 | use crate::{ |
14 | assist_config::SnippetCap, | ||
15 | utils::{render_snippet, Cursor}, | 14 | utils::{render_snippet, Cursor}, |
16 | AssistContext, AssistId, AssistKind, Assists, | 15 | AssistContext, AssistId, AssistKind, Assists, |
17 | }; | 16 | }; |
@@ -24,7 +23,7 @@ use crate::{ | |||
24 | // struct Baz; | 23 | // struct Baz; |
25 | // fn baz() -> Baz { Baz } | 24 | // fn baz() -> Baz { Baz } |
26 | // fn foo() { | 25 | // fn foo() { |
27 | // bar<|>("", baz()); | 26 | // bar$0("", baz()); |
28 | // } | 27 | // } |
29 | // | 28 | // |
30 | // ``` | 29 | // ``` |
@@ -343,7 +342,7 @@ mod tests { | |||
343 | generate_function, | 342 | generate_function, |
344 | r" | 343 | r" |
345 | fn foo() { | 344 | fn foo() { |
346 | bar<|>(); | 345 | bar$0(); |
347 | } | 346 | } |
348 | ", | 347 | ", |
349 | r" | 348 | r" |
@@ -367,7 +366,7 @@ fn bar() ${0:-> ()} { | |||
367 | r" | 366 | r" |
368 | impl Foo { | 367 | impl Foo { |
369 | fn foo() { | 368 | fn foo() { |
370 | bar<|>(); | 369 | bar$0(); |
371 | } | 370 | } |
372 | } | 371 | } |
373 | ", | 372 | ", |
@@ -392,7 +391,7 @@ fn bar() ${0:-> ()} { | |||
392 | generate_function, | 391 | generate_function, |
393 | r" | 392 | r" |
394 | fn foo1() { | 393 | fn foo1() { |
395 | bar<|>(); | 394 | bar$0(); |
396 | } | 395 | } |
397 | 396 | ||
398 | fn foo2() {} | 397 | fn foo2() {} |
@@ -418,7 +417,7 @@ fn foo2() {} | |||
418 | r" | 417 | r" |
419 | mod baz { | 418 | mod baz { |
420 | fn foo() { | 419 | fn foo() { |
421 | bar<|>(); | 420 | bar$0(); |
422 | } | 421 | } |
423 | } | 422 | } |
424 | ", | 423 | ", |
@@ -444,7 +443,7 @@ mod baz { | |||
444 | struct Baz; | 443 | struct Baz; |
445 | fn baz() -> Baz { todo!() } | 444 | fn baz() -> Baz { todo!() } |
446 | fn foo() { | 445 | fn foo() { |
447 | bar<|>(baz()); | 446 | bar$0(baz()); |
448 | } | 447 | } |
449 | ", | 448 | ", |
450 | r" | 449 | r" |
@@ -469,7 +468,7 @@ fn bar(baz: Baz) ${0:-> ()} { | |||
469 | struct Baz; | 468 | struct Baz; |
470 | impl Baz { | 469 | impl Baz { |
471 | fn foo(&self) -> Baz { | 470 | fn foo(&self) -> Baz { |
472 | ba<|>r(self.baz()) | 471 | ba$0r(self.baz()) |
473 | } | 472 | } |
474 | fn baz(&self) -> Baz { | 473 | fn baz(&self) -> Baz { |
475 | Baz | 474 | Baz |
@@ -500,7 +499,7 @@ fn bar(baz: Baz) ${0:-> ()} { | |||
500 | generate_function, | 499 | generate_function, |
501 | r#" | 500 | r#" |
502 | fn foo() { | 501 | fn foo() { |
503 | <|>bar("bar") | 502 | $0bar("bar") |
504 | } | 503 | } |
505 | "#, | 504 | "#, |
506 | r#" | 505 | r#" |
@@ -521,7 +520,7 @@ fn bar(arg: &str) ${0:-> ()} { | |||
521 | generate_function, | 520 | generate_function, |
522 | r#" | 521 | r#" |
523 | fn foo() { | 522 | fn foo() { |
524 | <|>bar('x') | 523 | $0bar('x') |
525 | } | 524 | } |
526 | "#, | 525 | "#, |
527 | r#" | 526 | r#" |
@@ -542,7 +541,7 @@ fn bar(arg: char) ${0:-> ()} { | |||
542 | generate_function, | 541 | generate_function, |
543 | r" | 542 | r" |
544 | fn foo() { | 543 | fn foo() { |
545 | <|>bar(42) | 544 | $0bar(42) |
546 | } | 545 | } |
547 | ", | 546 | ", |
548 | r" | 547 | r" |
@@ -563,7 +562,7 @@ fn bar(arg: i32) ${0:-> ()} { | |||
563 | generate_function, | 562 | generate_function, |
564 | r" | 563 | r" |
565 | fn foo() { | 564 | fn foo() { |
566 | <|>bar(42 as u8) | 565 | $0bar(42 as u8) |
567 | } | 566 | } |
568 | ", | 567 | ", |
569 | r" | 568 | r" |
@@ -587,7 +586,7 @@ fn bar(arg: u8) ${0:-> ()} { | |||
587 | r" | 586 | r" |
588 | fn foo() { | 587 | fn foo() { |
589 | let x = 42; | 588 | let x = 42; |
590 | bar<|>(x as u8) | 589 | bar$0(x as u8) |
591 | } | 590 | } |
592 | ", | 591 | ", |
593 | r" | 592 | r" |
@@ -610,7 +609,7 @@ fn bar(x: u8) ${0:-> ()} { | |||
610 | r" | 609 | r" |
611 | fn foo() { | 610 | fn foo() { |
612 | let worble = (); | 611 | let worble = (); |
613 | <|>bar(worble) | 612 | $0bar(worble) |
614 | } | 613 | } |
615 | ", | 614 | ", |
616 | r" | 615 | r" |
@@ -636,7 +635,7 @@ fn foo() -> impl Foo { | |||
636 | todo!() | 635 | todo!() |
637 | } | 636 | } |
638 | fn baz() { | 637 | fn baz() { |
639 | <|>bar(foo()) | 638 | $0bar(foo()) |
640 | } | 639 | } |
641 | ", | 640 | ", |
642 | r" | 641 | r" |
@@ -664,7 +663,7 @@ struct Baz; | |||
664 | fn baz() -> Baz { todo!() } | 663 | fn baz() -> Baz { todo!() } |
665 | 664 | ||
666 | fn foo() { | 665 | fn foo() { |
667 | bar<|>(&baz()) | 666 | bar$0(&baz()) |
668 | } | 667 | } |
669 | ", | 668 | ", |
670 | r" | 669 | r" |
@@ -692,7 +691,7 @@ mod Baz { | |||
692 | pub fn baz() -> Bof { Bof } | 691 | pub fn baz() -> Bof { Bof } |
693 | } | 692 | } |
694 | fn foo() { | 693 | fn foo() { |
695 | <|>bar(Baz::baz()) | 694 | $0bar(Baz::baz()) |
696 | } | 695 | } |
697 | ", | 696 | ", |
698 | r" | 697 | r" |
@@ -719,7 +718,7 @@ fn bar(baz: Baz::Bof) ${0:-> ()} { | |||
719 | generate_function, | 718 | generate_function, |
720 | r" | 719 | r" |
721 | fn foo<T>(t: T) { | 720 | fn foo<T>(t: T) { |
722 | <|>bar(t) | 721 | $0bar(t) |
723 | } | 722 | } |
724 | ", | 723 | ", |
725 | r" | 724 | r" |
@@ -746,7 +745,7 @@ impl Baz { | |||
746 | fn new() -> Self { Baz } | 745 | fn new() -> Self { Baz } |
747 | } | 746 | } |
748 | fn foo() { | 747 | fn foo() { |
749 | <|>bar(Baz::new); | 748 | $0bar(Baz::new); |
750 | } | 749 | } |
751 | ", | 750 | ", |
752 | r" | 751 | r" |
@@ -774,7 +773,7 @@ fn bar(arg: fn() -> Baz) ${0:-> ()} { | |||
774 | r" | 773 | r" |
775 | fn foo() { | 774 | fn foo() { |
776 | let closure = |x: i64| x - 1; | 775 | let closure = |x: i64| x - 1; |
777 | <|>bar(closure) | 776 | $0bar(closure) |
778 | } | 777 | } |
779 | ", | 778 | ", |
780 | r" | 779 | r" |
@@ -796,7 +795,7 @@ fn bar(closure: impl Fn(i64) -> i64) ${0:-> ()} { | |||
796 | generate_function, | 795 | generate_function, |
797 | r" | 796 | r" |
798 | fn foo() { | 797 | fn foo() { |
799 | <|>bar(baz) | 798 | $0bar(baz) |
800 | } | 799 | } |
801 | ", | 800 | ", |
802 | r" | 801 | r" |
@@ -819,7 +818,7 @@ fn bar(baz: ()) ${0:-> ()} { | |||
819 | struct Baz; | 818 | struct Baz; |
820 | fn baz() -> Baz { Baz } | 819 | fn baz() -> Baz { Baz } |
821 | fn foo() { | 820 | fn foo() { |
822 | <|>bar(baz(), baz()) | 821 | $0bar(baz(), baz()) |
823 | } | 822 | } |
824 | ", | 823 | ", |
825 | r" | 824 | r" |
@@ -844,7 +843,7 @@ fn bar(baz_1: Baz, baz_2: Baz) ${0:-> ()} { | |||
844 | struct Baz; | 843 | struct Baz; |
845 | fn baz() -> Baz { Baz } | 844 | fn baz() -> Baz { Baz } |
846 | fn foo() { | 845 | fn foo() { |
847 | <|>bar(baz(), baz(), "foo", "bar") | 846 | $0bar(baz(), baz(), "foo", "bar") |
848 | } | 847 | } |
849 | "#, | 848 | "#, |
850 | r#" | 849 | r#" |
@@ -869,7 +868,7 @@ fn bar(baz_1: Baz, baz_2: Baz, arg_1: &str, arg_2: &str) ${0:-> ()} { | |||
869 | mod bar {} | 868 | mod bar {} |
870 | 869 | ||
871 | fn foo() { | 870 | fn foo() { |
872 | bar::my_fn<|>() | 871 | bar::my_fn$0() |
873 | } | 872 | } |
874 | ", | 873 | ", |
875 | r" | 874 | r" |
@@ -900,7 +899,7 @@ mod foo { | |||
900 | fn bar() { | 899 | fn bar() { |
901 | use foo::Foo; | 900 | use foo::Foo; |
902 | let foo = Foo; | 901 | let foo = Foo; |
903 | baz<|>(foo) | 902 | baz$0(foo) |
904 | } | 903 | } |
905 | ", | 904 | ", |
906 | " | 905 | " |
@@ -930,7 +929,7 @@ mod bar { | |||
930 | } | 929 | } |
931 | 930 | ||
932 | fn foo() { | 931 | fn foo() { |
933 | bar::my_fn<|>() | 932 | bar::my_fn$0() |
934 | } | 933 | } |
935 | ", | 934 | ", |
936 | r" | 935 | r" |
@@ -959,7 +958,7 @@ mod bar { | |||
959 | } | 958 | } |
960 | 959 | ||
961 | fn foo() { | 960 | fn foo() { |
962 | bar::baz::my_fn<|>() | 961 | bar::baz::my_fn$0() |
963 | } | 962 | } |
964 | ", | 963 | ", |
965 | r" | 964 | r" |
@@ -987,7 +986,7 @@ fn foo() { | |||
987 | mod foo; | 986 | mod foo; |
988 | 987 | ||
989 | fn main() { | 988 | fn main() { |
990 | foo::bar<|>() | 989 | foo::bar$0() |
991 | } | 990 | } |
992 | //- /foo.rs | 991 | //- /foo.rs |
993 | ", | 992 | ", |
@@ -1006,7 +1005,7 @@ pub(crate) fn bar() ${0:-> ()} { | |||
1006 | generate_function, | 1005 | generate_function, |
1007 | r" | 1006 | r" |
1008 | fn foo() { | 1007 | fn foo() { |
1009 | bar<|>(); | 1008 | bar$0(); |
1010 | } | 1009 | } |
1011 | 1010 | ||
1012 | fn bar() {} | 1011 | fn bar() {} |
@@ -1023,7 +1022,7 @@ fn bar() {} | |||
1023 | generate_function, | 1022 | generate_function, |
1024 | r" | 1023 | r" |
1025 | fn foo() { | 1024 | fn foo() { |
1026 | bar(b<|>az); | 1025 | bar(b$0az); |
1027 | } | 1026 | } |
1028 | 1027 | ||
1029 | fn bar(baz: ()) {} | 1028 | fn bar(baz: ()) {} |
@@ -1040,7 +1039,7 @@ fn bar(baz: ()) {} | |||
1040 | struct Foo; | 1039 | struct Foo; |
1041 | impl Foo { | 1040 | impl Foo { |
1042 | fn foo(&self) { | 1041 | fn foo(&self) { |
1043 | self.bar()<|>; | 1042 | self.bar()$0; |
1044 | } | 1043 | } |
1045 | } | 1044 | } |
1046 | ", | 1045 | ", |
diff --git a/crates/assists/src/handlers/generate_impl.rs b/crates/assists/src/handlers/generate_impl.rs index 960af5ab3..9af45192b 100644 --- a/crates/assists/src/handlers/generate_impl.rs +++ b/crates/assists/src/handlers/generate_impl.rs | |||
@@ -10,7 +10,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; | |||
10 | // | 10 | // |
11 | // ``` | 11 | // ``` |
12 | // struct Ctx<T: Clone> { | 12 | // struct Ctx<T: Clone> { |
13 | // data: T,<|> | 13 | // data: T,$0 |
14 | // } | 14 | // } |
15 | // ``` | 15 | // ``` |
16 | // -> | 16 | // -> |
@@ -87,24 +87,24 @@ mod tests { | |||
87 | fn test_add_impl() { | 87 | fn test_add_impl() { |
88 | check_assist( | 88 | check_assist( |
89 | generate_impl, | 89 | generate_impl, |
90 | "struct Foo {<|>}\n", | 90 | "struct Foo {$0}\n", |
91 | "struct Foo {}\n\nimpl Foo {\n $0\n}\n", | 91 | "struct Foo {}\n\nimpl Foo {\n $0\n}\n", |
92 | ); | 92 | ); |
93 | check_assist( | 93 | check_assist( |
94 | generate_impl, | 94 | generate_impl, |
95 | "struct Foo<T: Clone> {<|>}", | 95 | "struct Foo<T: Clone> {$0}", |
96 | "struct Foo<T: Clone> {}\n\nimpl<T: Clone> Foo<T> {\n $0\n}", | 96 | "struct Foo<T: Clone> {}\n\nimpl<T: Clone> Foo<T> {\n $0\n}", |
97 | ); | 97 | ); |
98 | check_assist( | 98 | check_assist( |
99 | generate_impl, | 99 | generate_impl, |
100 | "struct Foo<'a, T: Foo<'a>> {<|>}", | 100 | "struct Foo<'a, T: Foo<'a>> {$0}", |
101 | "struct Foo<'a, T: Foo<'a>> {}\n\nimpl<'a, T: Foo<'a>> Foo<'a, T> {\n $0\n}", | 101 | "struct Foo<'a, T: Foo<'a>> {}\n\nimpl<'a, T: Foo<'a>> Foo<'a, T> {\n $0\n}", |
102 | ); | 102 | ); |
103 | check_assist( | 103 | check_assist( |
104 | generate_impl, | 104 | generate_impl, |
105 | r#" | 105 | r#" |
106 | #[cfg(feature = "foo")] | 106 | #[cfg(feature = "foo")] |
107 | struct Foo<'a, T: Foo<'a>> {<|>}"#, | 107 | struct Foo<'a, T: Foo<'a>> {$0}"#, |
108 | r#" | 108 | r#" |
109 | #[cfg(feature = "foo")] | 109 | #[cfg(feature = "foo")] |
110 | struct Foo<'a, T: Foo<'a>> {} | 110 | struct Foo<'a, T: Foo<'a>> {} |
@@ -119,7 +119,7 @@ mod tests { | |||
119 | generate_impl, | 119 | generate_impl, |
120 | r#" | 120 | r#" |
121 | #[cfg(not(feature = "foo"))] | 121 | #[cfg(not(feature = "foo"))] |
122 | struct Foo<'a, T: Foo<'a>> {<|>}"#, | 122 | struct Foo<'a, T: Foo<'a>> {$0}"#, |
123 | r#" | 123 | r#" |
124 | #[cfg(not(feature = "foo"))] | 124 | #[cfg(not(feature = "foo"))] |
125 | struct Foo<'a, T: Foo<'a>> {} | 125 | struct Foo<'a, T: Foo<'a>> {} |
@@ -138,7 +138,7 @@ mod tests { | |||
138 | " | 138 | " |
139 | struct SomeThingIrrelevant; | 139 | struct SomeThingIrrelevant; |
140 | /// Has a lifetime parameter | 140 | /// Has a lifetime parameter |
141 | struct Foo<'a, T: Foo<'a>> {<|>} | 141 | struct Foo<'a, T: Foo<'a>> {$0} |
142 | struct EvenMoreIrrelevant; | 142 | struct EvenMoreIrrelevant; |
143 | ", | 143 | ", |
144 | "/// Has a lifetime parameter | 144 | "/// Has a lifetime parameter |
diff --git a/crates/assists/src/handlers/generate_new.rs b/crates/assists/src/handlers/generate_new.rs index c5fec4e0a..5c52b2bc8 100644 --- a/crates/assists/src/handlers/generate_new.rs +++ b/crates/assists/src/handlers/generate_new.rs | |||
@@ -14,7 +14,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; | |||
14 | // | 14 | // |
15 | // ``` | 15 | // ``` |
16 | // struct Ctx<T: Clone> { | 16 | // struct Ctx<T: Clone> { |
17 | // data: T,<|> | 17 | // data: T,$0 |
18 | // } | 18 | // } |
19 | // ``` | 19 | // ``` |
20 | // -> | 20 | // -> |
@@ -182,7 +182,7 @@ mod tests { | |||
182 | // Check output of generation | 182 | // Check output of generation |
183 | check_assist( | 183 | check_assist( |
184 | generate_new, | 184 | generate_new, |
185 | "struct Foo {<|>}", | 185 | "struct Foo {$0}", |
186 | "struct Foo {} | 186 | "struct Foo {} |
187 | 187 | ||
188 | impl Foo { | 188 | impl Foo { |
@@ -192,7 +192,7 @@ impl Foo { | |||
192 | ); | 192 | ); |
193 | check_assist( | 193 | check_assist( |
194 | generate_new, | 194 | generate_new, |
195 | "struct Foo<T: Clone> {<|>}", | 195 | "struct Foo<T: Clone> {$0}", |
196 | "struct Foo<T: Clone> {} | 196 | "struct Foo<T: Clone> {} |
197 | 197 | ||
198 | impl<T: Clone> Foo<T> { | 198 | impl<T: Clone> Foo<T> { |
@@ -202,7 +202,7 @@ impl<T: Clone> Foo<T> { | |||
202 | ); | 202 | ); |
203 | check_assist( | 203 | check_assist( |
204 | generate_new, | 204 | generate_new, |
205 | "struct Foo<'a, T: Foo<'a>> {<|>}", | 205 | "struct Foo<'a, T: Foo<'a>> {$0}", |
206 | "struct Foo<'a, T: Foo<'a>> {} | 206 | "struct Foo<'a, T: Foo<'a>> {} |
207 | 207 | ||
208 | impl<'a, T: Foo<'a>> Foo<'a, T> { | 208 | impl<'a, T: Foo<'a>> Foo<'a, T> { |
@@ -212,7 +212,7 @@ impl<'a, T: Foo<'a>> Foo<'a, T> { | |||
212 | ); | 212 | ); |
213 | check_assist( | 213 | check_assist( |
214 | generate_new, | 214 | generate_new, |
215 | "struct Foo { baz: String <|>}", | 215 | "struct Foo { baz: String $0}", |
216 | "struct Foo { baz: String } | 216 | "struct Foo { baz: String } |
217 | 217 | ||
218 | impl Foo { | 218 | impl Foo { |
@@ -222,7 +222,7 @@ impl Foo { | |||
222 | ); | 222 | ); |
223 | check_assist( | 223 | check_assist( |
224 | generate_new, | 224 | generate_new, |
225 | "struct Foo { baz: String, qux: Vec<i32> <|>}", | 225 | "struct Foo { baz: String, qux: Vec<i32> $0}", |
226 | "struct Foo { baz: String, qux: Vec<i32> } | 226 | "struct Foo { baz: String, qux: Vec<i32> } |
227 | 227 | ||
228 | impl Foo { | 228 | impl Foo { |
@@ -234,7 +234,7 @@ impl Foo { | |||
234 | // Check that visibility modifiers don't get brought in for fields | 234 | // Check that visibility modifiers don't get brought in for fields |
235 | check_assist( | 235 | check_assist( |
236 | generate_new, | 236 | generate_new, |
237 | "struct Foo { pub baz: String, pub qux: Vec<i32> <|>}", | 237 | "struct Foo { pub baz: String, pub qux: Vec<i32> $0}", |
238 | "struct Foo { pub baz: String, pub qux: Vec<i32> } | 238 | "struct Foo { pub baz: String, pub qux: Vec<i32> } |
239 | 239 | ||
240 | impl Foo { | 240 | impl Foo { |
@@ -246,7 +246,7 @@ impl Foo { | |||
246 | // Check that it reuses existing impls | 246 | // Check that it reuses existing impls |
247 | check_assist( | 247 | check_assist( |
248 | generate_new, | 248 | generate_new, |
249 | "struct Foo {<|>} | 249 | "struct Foo {$0} |
250 | 250 | ||
251 | impl Foo {} | 251 | impl Foo {} |
252 | ", | 252 | ", |
@@ -259,7 +259,7 @@ impl Foo { | |||
259 | ); | 259 | ); |
260 | check_assist( | 260 | check_assist( |
261 | generate_new, | 261 | generate_new, |
262 | "struct Foo {<|>} | 262 | "struct Foo {$0} |
263 | 263 | ||
264 | impl Foo { | 264 | impl Foo { |
265 | fn qux(&self) {} | 265 | fn qux(&self) {} |
@@ -277,7 +277,7 @@ impl Foo { | |||
277 | 277 | ||
278 | check_assist( | 278 | check_assist( |
279 | generate_new, | 279 | generate_new, |
280 | "struct Foo {<|>} | 280 | "struct Foo {$0} |
281 | 281 | ||
282 | impl Foo { | 282 | impl Foo { |
283 | fn qux(&self) {} | 283 | fn qux(&self) {} |
@@ -302,7 +302,7 @@ impl Foo { | |||
302 | // Check visibility of new fn based on struct | 302 | // Check visibility of new fn based on struct |
303 | check_assist( | 303 | check_assist( |
304 | generate_new, | 304 | generate_new, |
305 | "pub struct Foo {<|>}", | 305 | "pub struct Foo {$0}", |
306 | "pub struct Foo {} | 306 | "pub struct Foo {} |
307 | 307 | ||
308 | impl Foo { | 308 | impl Foo { |
@@ -312,7 +312,7 @@ impl Foo { | |||
312 | ); | 312 | ); |
313 | check_assist( | 313 | check_assist( |
314 | generate_new, | 314 | generate_new, |
315 | "pub(crate) struct Foo {<|>}", | 315 | "pub(crate) struct Foo {$0}", |
316 | "pub(crate) struct Foo {} | 316 | "pub(crate) struct Foo {} |
317 | 317 | ||
318 | impl Foo { | 318 | impl Foo { |
@@ -327,7 +327,7 @@ impl Foo { | |||
327 | check_assist_not_applicable( | 327 | check_assist_not_applicable( |
328 | generate_new, | 328 | generate_new, |
329 | " | 329 | " |
330 | struct Foo {<|>} | 330 | struct Foo {$0} |
331 | 331 | ||
332 | impl Foo { | 332 | impl Foo { |
333 | fn new() -> Self { | 333 | fn new() -> Self { |
@@ -339,7 +339,7 @@ impl Foo { | |||
339 | check_assist_not_applicable( | 339 | check_assist_not_applicable( |
340 | generate_new, | 340 | generate_new, |
341 | " | 341 | " |
342 | struct Foo {<|>} | 342 | struct Foo {$0} |
343 | 343 | ||
344 | impl Foo { | 344 | impl Foo { |
345 | fn New() -> Self { | 345 | fn New() -> Self { |
@@ -356,7 +356,7 @@ impl Foo { | |||
356 | " | 356 | " |
357 | struct SomeThingIrrelevant; | 357 | struct SomeThingIrrelevant; |
358 | /// Has a lifetime parameter | 358 | /// Has a lifetime parameter |
359 | struct Foo<'a, T: Foo<'a>> {<|>} | 359 | struct Foo<'a, T: Foo<'a>> {$0} |
360 | struct EvenMoreIrrelevant; | 360 | struct EvenMoreIrrelevant; |
361 | ", | 361 | ", |
362 | "/// Has a lifetime parameter | 362 | "/// Has a lifetime parameter |
@@ -381,7 +381,7 @@ impl<N: AstNode> AstId<N> { | |||
381 | } | 381 | } |
382 | 382 | ||
383 | pub struct Source<T> { | 383 | pub struct Source<T> { |
384 | pub file_id: HirFileId,<|> | 384 | pub file_id: HirFileId,$0 |
385 | pub ast: T, | 385 | pub ast: T, |
386 | } | 386 | } |
387 | 387 | ||
diff --git a/crates/assists/src/handlers/infer_function_return_type.rs b/crates/assists/src/handlers/infer_function_return_type.rs index aa584eb03..5279af1f3 100644 --- a/crates/assists/src/handlers/infer_function_return_type.rs +++ b/crates/assists/src/handlers/infer_function_return_type.rs | |||
@@ -10,7 +10,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; | |||
10 | // type specified. This assists is useable in a functions or closures tail expression or return type position. | 10 | // type specified. This assists is useable in a functions or closures tail expression or return type position. |
11 | // | 11 | // |
12 | // ``` | 12 | // ``` |
13 | // fn foo() { 4<|>2i32 } | 13 | // fn foo() { 4$02i32 } |
14 | // ``` | 14 | // ``` |
15 | // -> | 15 | // -> |
16 | // ``` | 16 | // ``` |
@@ -89,7 +89,7 @@ fn extract_tail(ctx: &AssistContext) -> Option<(FnType, ast::Expr, InsertOrRepla | |||
89 | let body = closure.body()?; | 89 | let body = closure.body()?; |
90 | let body_start = body.syntax().first_token()?.text_range().start(); | 90 | let body_start = body.syntax().first_token()?.text_range().start(); |
91 | let (tail_expr, wrap_expr) = match body { | 91 | let (tail_expr, wrap_expr) = match body { |
92 | ast::Expr::BlockExpr(block) => (block.expr()?, false), | 92 | ast::Expr::BlockExpr(block) => (block.tail_expr()?, false), |
93 | body => (body, true), | 93 | body => (body, true), |
94 | }; | 94 | }; |
95 | 95 | ||
@@ -101,7 +101,7 @@ fn extract_tail(ctx: &AssistContext) -> Option<(FnType, ast::Expr, InsertOrRepla | |||
101 | let action = ret_ty_to_action(func.ret_type(), rparen_pos)?; | 101 | let action = ret_ty_to_action(func.ret_type(), rparen_pos)?; |
102 | 102 | ||
103 | let body = func.body()?; | 103 | let body = func.body()?; |
104 | let tail_expr = body.expr()?; | 104 | let tail_expr = body.tail_expr()?; |
105 | 105 | ||
106 | let ret_range_end = body.l_curly_token()?.text_range().start(); | 106 | let ret_range_end = body.l_curly_token()?.text_range().start(); |
107 | let ret_range = TextRange::new(rparen_pos, ret_range_end); | 107 | let ret_range = TextRange::new(rparen_pos, ret_range_end); |
@@ -131,7 +131,7 @@ mod tests { | |||
131 | mark::check!(existing_infer_ret_type); | 131 | mark::check!(existing_infer_ret_type); |
132 | check_assist( | 132 | check_assist( |
133 | infer_function_return_type, | 133 | infer_function_return_type, |
134 | r#"fn foo() -> <|>_ { | 134 | r#"fn foo() -> $0_ { |
135 | 45 | 135 | 45 |
136 | }"#, | 136 | }"#, |
137 | r#"fn foo() -> i32 { | 137 | r#"fn foo() -> i32 { |
@@ -146,7 +146,7 @@ mod tests { | |||
146 | check_assist( | 146 | check_assist( |
147 | infer_function_return_type, | 147 | infer_function_return_type, |
148 | r#"fn foo() { | 148 | r#"fn foo() { |
149 | || -> _ {<|>45}; | 149 | || -> _ {$045}; |
150 | }"#, | 150 | }"#, |
151 | r#"fn foo() { | 151 | r#"fn foo() { |
152 | || -> i32 {45}; | 152 | || -> i32 {45}; |
@@ -159,7 +159,7 @@ mod tests { | |||
159 | mark::check!(cursor_in_ret_position); | 159 | mark::check!(cursor_in_ret_position); |
160 | check_assist( | 160 | check_assist( |
161 | infer_function_return_type, | 161 | infer_function_return_type, |
162 | r#"fn foo() <|>{ | 162 | r#"fn foo() $0{ |
163 | 45 | 163 | 45 |
164 | }"#, | 164 | }"#, |
165 | r#"fn foo() -> i32 { | 165 | r#"fn foo() -> i32 { |
@@ -174,7 +174,7 @@ mod tests { | |||
174 | check_assist( | 174 | check_assist( |
175 | infer_function_return_type, | 175 | infer_function_return_type, |
176 | r#"fn foo() { | 176 | r#"fn foo() { |
177 | || <|>45 | 177 | || $045 |
178 | }"#, | 178 | }"#, |
179 | r#"fn foo() { | 179 | r#"fn foo() { |
180 | || -> i32 {45} | 180 | || -> i32 {45} |
@@ -188,7 +188,7 @@ mod tests { | |||
188 | check_assist( | 188 | check_assist( |
189 | infer_function_return_type, | 189 | infer_function_return_type, |
190 | r#"fn foo() { | 190 | r#"fn foo() { |
191 | 45<|> | 191 | 45$0 |
192 | }"#, | 192 | }"#, |
193 | r#"fn foo() -> i32 { | 193 | r#"fn foo() -> i32 { |
194 | 45 | 194 | 45 |
@@ -202,7 +202,7 @@ mod tests { | |||
202 | infer_function_return_type, | 202 | infer_function_return_type, |
203 | r#"fn foo() { | 203 | r#"fn foo() { |
204 | if true { | 204 | if true { |
205 | 3<|> | 205 | 3$0 |
206 | } else { | 206 | } else { |
207 | 5 | 207 | 5 |
208 | } | 208 | } |
@@ -223,7 +223,7 @@ mod tests { | |||
223 | check_assist_not_applicable( | 223 | check_assist_not_applicable( |
224 | infer_function_return_type, | 224 | infer_function_return_type, |
225 | r#"fn foo() -> i32 { | 225 | r#"fn foo() -> i32 { |
226 | ( 45<|> + 32 ) * 123 | 226 | ( 45$0 + 32 ) * 123 |
227 | }"#, | 227 | }"#, |
228 | ); | 228 | ); |
229 | } | 229 | } |
@@ -233,7 +233,7 @@ mod tests { | |||
233 | check_assist_not_applicable( | 233 | check_assist_not_applicable( |
234 | infer_function_return_type, | 234 | infer_function_return_type, |
235 | r#"fn foo() { | 235 | r#"fn foo() { |
236 | let x = <|>3; | 236 | let x = $03; |
237 | ( 45 + 32 ) * 123 | 237 | ( 45 + 32 ) * 123 |
238 | }"#, | 238 | }"#, |
239 | ); | 239 | ); |
@@ -244,7 +244,7 @@ mod tests { | |||
244 | check_assist_not_applicable( | 244 | check_assist_not_applicable( |
245 | infer_function_return_type, | 245 | infer_function_return_type, |
246 | r#"fn foo() { | 246 | r#"fn foo() { |
247 | (<|>) | 247 | ($0) |
248 | }"#, | 248 | }"#, |
249 | ); | 249 | ); |
250 | } | 250 | } |
@@ -256,7 +256,7 @@ mod tests { | |||
256 | infer_function_return_type, | 256 | infer_function_return_type, |
257 | r#"fn foo() { | 257 | r#"fn foo() { |
258 | |x: i32| { | 258 | |x: i32| { |
259 | x<|> | 259 | x$0 |
260 | }; | 260 | }; |
261 | }"#, | 261 | }"#, |
262 | r#"fn foo() { | 262 | r#"fn foo() { |
@@ -272,7 +272,7 @@ mod tests { | |||
272 | check_assist( | 272 | check_assist( |
273 | infer_function_return_type, | 273 | infer_function_return_type, |
274 | r#"fn foo() { | 274 | r#"fn foo() { |
275 | |x: i32| { x<|> }; | 275 | |x: i32| { x$0 }; |
276 | }"#, | 276 | }"#, |
277 | r#"fn foo() { | 277 | r#"fn foo() { |
278 | |x: i32| -> i32 { x }; | 278 | |x: i32| -> i32 { x }; |
@@ -286,7 +286,7 @@ mod tests { | |||
286 | check_assist( | 286 | check_assist( |
287 | infer_function_return_type, | 287 | infer_function_return_type, |
288 | r#"fn foo() { | 288 | r#"fn foo() { |
289 | |x: i32| x<|>; | 289 | |x: i32| x$0; |
290 | }"#, | 290 | }"#, |
291 | r#"fn foo() { | 291 | r#"fn foo() { |
292 | |x: i32| -> i32 {x}; | 292 | |x: i32| -> i32 {x}; |
@@ -301,7 +301,7 @@ mod tests { | |||
301 | r#"fn foo() { | 301 | r#"fn foo() { |
302 | || { | 302 | || { |
303 | if true { | 303 | if true { |
304 | 3<|> | 304 | 3$0 |
305 | } else { | 305 | } else { |
306 | 5 | 306 | 5 |
307 | } | 307 | } |
@@ -325,7 +325,7 @@ mod tests { | |||
325 | check_assist_not_applicable( | 325 | check_assist_not_applicable( |
326 | infer_function_return_type, | 326 | infer_function_return_type, |
327 | r#"fn foo() { | 327 | r#"fn foo() { |
328 | || -> i32 { 3<|> } | 328 | || -> i32 { 3$0 } |
329 | }"#, | 329 | }"#, |
330 | ); | 330 | ); |
331 | } | 331 | } |
@@ -336,7 +336,7 @@ mod tests { | |||
336 | infer_function_return_type, | 336 | infer_function_return_type, |
337 | r#"fn foo() { | 337 | r#"fn foo() { |
338 | || -> i32 { | 338 | || -> i32 { |
339 | let x = 3<|>; | 339 | let x = 3$0; |
340 | 6 | 340 | 6 |
341 | } | 341 | } |
342 | }"#, | 342 | }"#, |
diff --git a/crates/assists/src/handlers/inline_function.rs b/crates/assists/src/handlers/inline_function.rs new file mode 100644 index 000000000..6ec99b09b --- /dev/null +++ b/crates/assists/src/handlers/inline_function.rs | |||
@@ -0,0 +1,202 @@ | |||
1 | use ast::make; | ||
2 | use hir::{HasSource, PathResolution}; | ||
3 | use syntax::{ | ||
4 | ast::{self, edit::AstNodeEdit, ArgListOwner}, | ||
5 | AstNode, | ||
6 | }; | ||
7 | use test_utils::mark; | ||
8 | |||
9 | use crate::{ | ||
10 | assist_context::{AssistContext, Assists}, | ||
11 | AssistId, AssistKind, | ||
12 | }; | ||
13 | |||
14 | // Assist: inline_function | ||
15 | // | ||
16 | // Inlines a function body. | ||
17 | // | ||
18 | // ``` | ||
19 | // fn add(a: u32, b: u32) -> u32 { a + b } | ||
20 | // fn main() { | ||
21 | // let x = add$0(1, 2); | ||