aboutsummaryrefslogtreecommitdiff
path: root/crates/assists/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/assists/src')
-rw-r--r--crates/assists/src/assist_config.rs32
-rw-r--r--crates/assists/src/assist_context.rs10
-rw-r--r--crates/assists/src/ast_transform.rs3
-rw-r--r--crates/assists/src/handlers/add_explicit_type.rs32
-rw-r--r--crates/assists/src/handlers/add_missing_impl_members.rs56
-rw-r--r--crates/assists/src/handlers/add_turbo_fish.rs12
-rw-r--r--crates/assists/src/handlers/apply_demorgan.rs12
-rw-r--r--crates/assists/src/handlers/auto_import.rs64
-rw-r--r--crates/assists/src/handlers/change_visibility.rs42
-rw-r--r--crates/assists/src/handlers/convert_integer_literal.rs32
-rw-r--r--crates/assists/src/handlers/early_return.rs32
-rw-r--r--crates/assists/src/handlers/expand_glob_import.rs34
-rw-r--r--crates/assists/src/handlers/extract_struct_from_enum_variant.rs103
-rw-r--r--crates/assists/src/handlers/extract_variable.rs52
-rw-r--r--crates/assists/src/handlers/fill_match_arms.rs46
-rw-r--r--crates/assists/src/handlers/fix_visibility.rs104
-rw-r--r--crates/assists/src/handlers/flip_binexpr.rs24
-rw-r--r--crates/assists/src/handlers/flip_comma.rs12
-rw-r--r--crates/assists/src/handlers/flip_trait_bound.rs20
-rw-r--r--crates/assists/src/handlers/generate_default_from_enum_variant.rs10
-rw-r--r--crates/assists/src/handlers/generate_derive.rs12
-rw-r--r--crates/assists/src/handlers/generate_from_impl_for_enum.rs16
-rw-r--r--crates/assists/src/handlers/generate_function.rs63
-rw-r--r--crates/assists/src/handlers/generate_impl.rs14
-rw-r--r--crates/assists/src/handlers/generate_new.rs32
-rw-r--r--crates/assists/src/handlers/infer_function_return_type.rs36
-rw-r--r--crates/assists/src/handlers/inline_function.rs202
-rw-r--r--crates/assists/src/handlers/inline_local_variable.rs155
-rw-r--r--crates/assists/src/handlers/introduce_named_lifetime.rs42
-rw-r--r--crates/assists/src/handlers/invert_if.rs20
-rw-r--r--crates/assists/src/handlers/merge_imports.rs42
-rw-r--r--crates/assists/src/handlers/merge_match_arms.rs12
-rw-r--r--crates/assists/src/handlers/move_bounds.rs10
-rw-r--r--crates/assists/src/handlers/move_guard.rs26
-rw-r--r--crates/assists/src/handlers/move_module_to_file.rs (renamed from crates/assists/src/handlers/extract_module_to_file.rs)50
-rw-r--r--crates/assists/src/handlers/pull_assignment_up.rs400
-rw-r--r--crates/assists/src/handlers/qualify_path.rs76
-rw-r--r--crates/assists/src/handlers/raw_string.rs54
-rw-r--r--crates/assists/src/handlers/remove_dbg.rs80
-rw-r--r--crates/assists/src/handlers/remove_mut.rs2
-rw-r--r--crates/assists/src/handlers/remove_unused_param.rs61
-rw-r--r--crates/assists/src/handlers/reorder_fields.rs12
-rw-r--r--crates/assists/src/handlers/reorder_impl.rs201
-rw-r--r--crates/assists/src/handlers/replace_derive_with_manual_impl.rs20
-rw-r--r--crates/assists/src/handlers/replace_if_let_with_match.rs32
-rw-r--r--crates/assists/src/handlers/replace_impl_trait_with_generic.rs18
-rw-r--r--crates/assists/src/handlers/replace_let_with_if_let.rs4
-rw-r--r--crates/assists/src/handlers/replace_qualified_name_with_use.rs58
-rw-r--r--crates/assists/src/handlers/replace_string_with_char.rs14
-rw-r--r--crates/assists/src/handlers/replace_unwrap_with_match.rs10
-rw-r--r--crates/assists/src/handlers/split_import.rs12
-rw-r--r--crates/assists/src/handlers/toggle_ignore.rs6
-rw-r--r--crates/assists/src/handlers/unwrap_block.rs34
-rw-r--r--crates/assists/src/handlers/wrap_return_type_in_result.rs78
-rw-r--r--crates/assists/src/lib.rs16
-rw-r--r--crates/assists/src/tests.rs44
-rw-r--r--crates/assists/src/tests/generated.rs223
-rw-r--r--crates/assists/src/utils.rs23
58 files changed, 1922 insertions, 1020 deletions
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
7use hir::PrefixKind; 7use ide_db::helpers::{insert_use::MergeBehavior, SnippetCap};
8use ide_db::helpers::insert_use::MergeBehavior;
9 8
10use crate::AssistKind; 9use 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
19impl 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)]
26pub struct SnippetCap {
27 _private: (),
28}
29
30impl 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)]
41pub struct InsertUseConfig { 19pub 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
46impl 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
5use algo::find_covering_element; 5use algo::find_covering_element;
6use hir::Semantics; 6use hir::Semantics;
7use ide_db::base_db::{AnchoredPathBuf, FileId, FileRange}; 7use ide_db::{
8 base_db::{AnchoredPathBuf, FileId, FileRange},
9 helpers::SnippetCap,
10};
8use ide_db::{ 11use 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};
18use text_edit::{TextEdit, TextEditBuilder}; 21use text_edit::{TextEdit, TextEditBuilder};
19 22
20use crate::{ 23use 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#"
180fn main() { 176fn 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
197fn main() { 193fn main() {
198 let test<|> = Test { t: 23u8, k: 33 }; 194 let test$0 = Test { t: 23u8, k: 33 };
199}"#, 195}"#,
200 r#" 196 r#"
201struct Test<K, T = u8> { 197struct 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
167impl Foo for S { 167impl Foo for S {
168 fn bar(&self) {} 168 fn bar(&self) {}
169<|> 169$0
170}"#, 170}"#,
171 r#" 171 r#"
172trait Foo { 172trait Foo {
@@ -214,7 +214,7 @@ struct S;
214 214
215impl Foo for S { 215impl Foo for S {
216 fn bar(&self) {} 216 fn bar(&self) {}
217<|> 217$0
218}"#, 218}"#,
219 r#" 219 r#"
220trait Foo { 220trait Foo {
@@ -242,7 +242,7 @@ impl Foo for S {
242 r#" 242 r#"
243trait Foo { fn foo(&self); } 243trait Foo { fn foo(&self); }
244struct S; 244struct S;
245impl Foo for S { <|> }"#, 245impl Foo for S { $0 }"#,
246 r#" 246 r#"
247trait Foo { fn foo(&self); } 247trait Foo { fn foo(&self); }
248struct S; 248struct S;
@@ -261,7 +261,7 @@ impl Foo for S {
261 r#" 261 r#"
262trait Foo { fn foo(&self); } 262trait Foo { fn foo(&self); }
263struct S; 263struct S;
264impl Foo for S<|>"#, 264impl Foo for S$0"#,
265 r#" 265 r#"
266trait Foo { fn foo(&self); } 266trait Foo { fn foo(&self); }
267struct S; 267struct S;
@@ -280,7 +280,7 @@ impl Foo for S {
280 r#" 280 r#"
281trait Foo<T> { fn foo(&self, t: T) -> &T; } 281trait Foo<T> { fn foo(&self, t: T) -> &T; }
282struct S; 282struct S;
283impl Foo<u32> for S { <|> }"#, 283impl Foo<u32> for S { $0 }"#,
284 r#" 284 r#"
285trait Foo<T> { fn foo(&self, t: T) -> &T; } 285trait Foo<T> { fn foo(&self, t: T) -> &T; }
286struct S; 286struct S;
@@ -299,7 +299,7 @@ impl Foo<u32> for S {
299 r#" 299 r#"
300trait Foo<T> { fn foo(&self, t: T) -> &T; } 300trait Foo<T> { fn foo(&self, t: T) -> &T; }
301struct S; 301struct S;
302impl<U> Foo<U> for S { <|> }"#, 302impl<U> Foo<U> for S { $0 }"#,
303 r#" 303 r#"
304trait Foo<T> { fn foo(&self, t: T) -> &T; } 304trait Foo<T> { fn foo(&self, t: T) -> &T; }
305struct S; 305struct S;
@@ -318,7 +318,7 @@ impl<U> Foo<U> for S {
318 r#" 318 r#"
319trait Foo { fn foo(&self); } 319trait Foo { fn foo(&self); }
320struct S; 320struct S;
321impl Foo for S {}<|>"#, 321impl Foo for S {}$0"#,
322 r#" 322 r#"
323trait Foo { fn foo(&self); } 323trait Foo { fn foo(&self); }
324struct S; 324struct 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}
342struct S; 342struct S;
343impl foo::Foo for S { <|> }"#, 343impl foo::Foo for S { $0 }"#,
344 r#" 344 r#"
345mod foo { 345mod foo {
346 pub struct Bar; 346 pub struct Bar;
@@ -370,7 +370,7 @@ mod foo {
370use foo::bar; 370use foo::bar;
371 371
372struct S; 372struct S;
373impl bar::Foo for S { <|> }"#, 373impl bar::Foo for S { $0 }"#,
374 r#" 374 r#"
375mod foo { 375mod 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}
402struct S; 402struct S;
403impl foo::Foo for S { <|> }"#, 403impl foo::Foo for S { $0 }"#,
404 r#" 404 r#"
405mod foo { 405mod 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}
427struct S; 427struct S;
428impl foo::Foo<u32> for S { <|> }"#, 428impl foo::Foo<u32> for S { $0 }"#,
429 r#" 429 r#"
430mod foo { 430mod foo {
431 pub struct Bar<T>; 431 pub struct Bar<T>;
@@ -452,7 +452,7 @@ mod foo {
452} 452}
453struct Param; 453struct Param;
454struct S; 454struct S;
455impl foo::Foo<Param> for S { <|> }"#, 455impl foo::Foo<Param> for S { $0 }"#,
456 r#" 456 r#"
457mod foo { 457mod 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}
481struct S; 481struct S;
482impl foo::Foo for S { <|> }"#, 482impl foo::Foo for S { $0 }"#,
483 r#" 483 r#"
484mod foo { 484mod 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}
508struct S; 508struct S;
509impl foo::Foo for S { <|> }"#, 509impl foo::Foo for S { $0 }"#,
510 r#" 510 r#"
511mod foo { 511mod 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}
534struct S; 534struct S;
535impl foo::Foo for S { <|> }"#, 535impl foo::Foo for S { $0 }"#,
536 r#" 536 r#"
537mod foo { 537mod 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#"
555trait Foo; 555trait Foo;
556struct S; 556struct S;
557impl Foo for S { <|> }"#, 557impl 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}
570struct S; 570struct S;
571impl Foo for S { <|> }"#, 571impl 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}
588struct S; 588struct S;
589impl Foo for S {}<|>"#, 589impl Foo for S {}$0"#,
590 r#" 590 r#"
591#[doc(alias = "test alias")] 591#[doc(alias = "test alias")]
592trait Foo { 592trait Foo {
@@ -621,7 +621,7 @@ trait Foo {
621 fn foo(some: u32) -> bool; 621 fn foo(some: u32) -> bool;
622} 622}
623struct S; 623struct S;
624impl Foo for S { <|> }"#, 624impl Foo for S { $0 }"#,
625 r#" 625 r#"
626trait Foo { 626trait Foo {
627 type Output; 627 type Output;
@@ -648,7 +648,7 @@ trait Foo<T = Self> {
648} 648}
649 649
650struct S; 650struct S;
651impl Foo for S { <|> }"#, 651impl Foo for S { $0 }"#,
652 r#" 652 r#"
653trait Foo<T = Self> { 653trait 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
675struct S<T>; 675struct S<T>;
676impl Foo<T> for S<T> { <|> }"#, 676impl Foo<T> for S<T> { $0 }"#,
677 r#" 677 r#"
678trait Foo<T1, T2 = Self> { 678trait 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
700impl Tr for ()<|> { 700impl Tr for ()$0 {
701}"#, 701}"#,
702 r#" 702 r#"
703trait Tr { 703trait Tr {
@@ -719,7 +719,7 @@ trait Tr {
719 fn foo(); 719 fn foo();
720} 720}
721 721
722impl Tr for ()<|> { 722impl 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
748impl Tr for ()<|> { 748impl 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}
773impl Test for () { 773impl 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}
798impl Foo for () { 798impl 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#"
78fn make<T>() -> T {} 78fn make<T>() -> T {}
79fn main() { 79fn main() {
80 make<|>(); 80 make$0();
81} 81}
82"#, 82"#,
83 r#" 83 r#"
@@ -97,7 +97,7 @@ fn main() {
97 r#" 97 r#"
98fn make<T>() -> T {} 98fn make<T>() -> T {}
99fn main() { 99fn 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}
121fn main() { 121fn 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#"
143fn make<T>() -> T {} 143fn make<T>() -> T {}
144fn main() { 144fn main() {
145 make<|>::<()>(); 145 make$0::<()>();
146} 146}
147"#, 147"#,
148 ); 148 );
@@ -156,7 +156,7 @@ fn main() {
156 r#" 156 r#"
157fn make() -> () {} 157fn make() -> () {}
158fn main() { 158fn 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
379fn main() { 379fn 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
876fn main() { 876fn 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
903struct S; 903struct S;
904 904
905impl f<|>mt::Display for S {} 905impl 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
932fn main() { 932fn 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
956fn main() { 956fn 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// ↑ ---------------
207fn find_imported_defs(ctx: &AssistContext, star: SyntaxToken) -> Option<Vec<Def>> { 207fn 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
306use foo::*<|>; 306use foo::*$0;
307 307
308fn qux(bar: Bar, baz: Baz) { 308fn 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
343use foo::{*<|>, f}; 343use foo::{*$0, f};
344 344
345fn qux(bar: Bar, baz: Baz) { 345fn qux(bar: Bar, baz: Baz) {
346 f(); 346 f();
@@ -378,7 +378,7 @@ mod foo {
378} 378}
379 379
380use foo::Bar; 380use foo::Bar;
381use foo::{*<|>, f}; 381use foo::{*$0, f};
382 382
383fn qux(bar: Bar, baz: Baz) { 383fn qux(bar: Bar, baz: Baz) {
384 f(); 384 f();
@@ -422,7 +422,7 @@ mod foo {
422 } 422 }
423} 423}
424 424
425use foo::{bar::{*<|>, f}, baz::*}; 425use foo::{bar::{*$0, f}, baz::*};
426 426
427fn qux(bar: Bar, baz: Baz) { 427fn qux(bar: Bar, baz: Baz) {
428 f(); 428 f();
@@ -470,7 +470,7 @@ mod foo {
470 } 470 }
471} 471}
472 472
473use foo::{bar::{Bar, Baz, f}, baz::*<|>}; 473use foo::{bar::{Bar, Baz, f}, baz::*$0};
474 474
475fn qux(bar: Bar, baz: Baz) { 475fn qux(bar: Bar, baz: Baz) {
476 f(); 476 f();
@@ -529,7 +529,7 @@ mod foo {
529 529
530use foo::{ 530use foo::{
531 bar::{*, f}, 531 bar::{*, f},
532 baz::{g, qux::*<|>} 532 baz::{g, qux::*$0}
533}; 533};
534 534
535fn qux(bar: Bar, baz: Baz) { 535fn qux(bar: Bar, baz: Baz) {
@@ -605,7 +605,7 @@ mod foo {
605 605
606use foo::{ 606use foo::{
607 bar::{*, f}, 607 bar::{*, f},
608 baz::{g, qux::{h, q::*<|>}} 608 baz::{g, qux::{h, q::*$0}}
609}; 609};
610 610
611fn qux(bar: Bar, baz: Baz) { 611fn qux(bar: Bar, baz: Baz) {
@@ -681,7 +681,7 @@ mod foo {
681 681
682use foo::{ 682use foo::{
683 bar::{*, f}, 683 bar::{*, f},
684 baz::{g, qux::{q::j, *<|>}} 684 baz::{g, qux::{q::j, *$0}}
685}; 685};
686 686
687fn qux(bar: Bar, baz: Baz) { 687fn 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 {
777impl Tr for () {} 777impl Tr for () {}
778 778
779//- /main.rs crate:main deps:foo 779//- /main.rs crate:main deps:foo
780use foo::*<|>; 780use foo::*$0;
781 781
782fn main() { 782fn main() {
783 ().method(); 783 ().method();
@@ -807,7 +807,7 @@ pub trait Tr2 {
807impl Tr2 for () {} 807impl Tr2 for () {}
808 808
809//- /main.rs crate:main deps:foo 809//- /main.rs crate:main deps:foo
810use foo::*<|>; 810use foo::*$0;
811 811
812fn main() { 812fn main() {
813 ().method(); 813 ().method();
@@ -834,7 +834,7 @@ mod foo {
834 } 834 }
835} 835}
836 836
837use foo::bar::*<|>; 837use foo::bar::*$0;
838 838
839fn baz(bar: Bar) {} 839fn baz(bar: Bar) {}
840", 840",
@@ -851,7 +851,7 @@ mod foo {
851 } 851 }
852} 852}
853 853
854use foo::bar::baz::*<|>; 854use foo::bar::baz::*$0;
855 855
856fn qux(baz: Baz) {} 856fn 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
888use foo::{*<|>}; 888use foo::{*$0};
889 889
890struct Baz { 890struct 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
3use either::Either; 3use either::Either;
4use hir::{AsName, Module, ModuleDef, Name, Variant}; 4use hir::{AsName, Module, ModuleDef, Name, Variant};
5use ide_db::helpers::{ 5use 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};
9use ide_db::{defs::Definition, search::Reference, RootDatabase}; 14use rustc_hash::FxHashSet;
10use rustc_hash::{FxHashMap, FxHashSet};
11use syntax::{ 15use 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
201fn update_reference( 210fn 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
253enum A { One(One) }"#, 262enum 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
264enum A { One(One) }"#, 273enum 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
275enum A { One(One) }"#, 284enum 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: () = ();
284enum A { <|>One(u32, u32) }"#, 293enum A { $0One(u32, u32) }"#,
285 r#"const One: () = (); 294 r#"const One: () = ();
286struct One(pub u32, pub u32); 295struct 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
299pub enum A { One(One) }"#, 308pub 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#"
359enum E { 368enum E {
360 <|>V { i: i32, j: i32 } 369 $0V { i: i32, j: i32 }
361} 370}
362 371
363fn f() { 372fn f() {
@@ -385,7 +394,7 @@ fn f() {
385 r#" 394 r#"
386//- /main.rs 395//- /main.rs
387enum E { 396enum E {
388 <|>V(i32, i32) 397 $0V(i32, i32)
389} 398}
390mod foo; 399mod foo;
391 400
@@ -420,7 +429,7 @@ fn f() {
420 r#" 429 r#"
421//- /main.rs 430//- /main.rs
422enum E { 431enum E {
423 <|>V { i: i32, j: i32 } 432 $0V { i: i32, j: i32 }
424} 433}
425mod foo; 434mod 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#"
456enum A { <|>One { a: u32, b: u32 } } 465enum A { $0One { a: u32, b: u32 } }
457 466
458struct B(A); 467struct 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#"
189fn foo() { 189fn foo() {
190 foo(<|>1 + 1<|>); 190 foo($01 + 1$0);
191}"#, 191}"#,
192 r#" 192 r#"
193fn foo() { 193fn 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#"
212fn foo() { 212fn foo() {
213 <|>1 + 1<|>; 213 $01 + 1$0;
214}"#, 214}"#,
215 r#" 215 r#"
216fn foo() { 216fn foo() {
@@ -221,7 +221,7 @@ fn foo() {
221 extract_variable, 221 extract_variable,
222 " 222 "
223fn foo() { 223fn 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 "
240fn foo() { 240fn foo() {
241 <|>1<|> + 1; 241 $01$0 + 1;
242}", 242}",
243 " 243 "
244fn foo() { 244fn foo() {
@@ -255,7 +255,7 @@ fn foo() {
255 extract_variable, 255 extract_variable,
256 r#" 256 r#"
257fn foo() { 257fn 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#"
271fn foo() { 271fn foo() {
272 <|>bar(1 + 1)<|> 272 $0bar(1 + 1)$0
273} 273}
274"#, 274"#,
275 r#" 275 r#"
@@ -289,7 +289,7 @@ fn foo() {
289fn main() { 289fn 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 "
346fn main() { 346fn 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 "
363fn main() { 363fn 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 "
380fn main() { 380fn 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 "
398fn main() { 398fn 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 "
416fn foo() -> u32 { 416fn foo() -> u32 {
417 <|>return 2 + 2<|>; 417 $0return 2 + 2$0;
418} 418}
419", 419",
420 " 420 "
@@ -434,7 +434,7 @@ fn foo() -> u32 {
434fn foo() -> u32 { 434fn 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 "
453fn foo() -> u32 { 453fn 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 "
498fn main() { 498fn 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 "
520fn main() { 520fn 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
542fn main() { 542fn 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() {
577fn main() { 577fn 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#"
298enum A { As, Bs, Cs(Option<i32>) } 298enum A { As, Bs, Cs(Option<i32>) }
299fn main() { 299fn 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() {
322enum A { As, Bs, Cs, Ds(String), Es(B) } 322enum A { As, Bs, Cs, Ds(String), Es(B) }
323enum B { Xs, Ys } 323enum B { Xs, Ys }
324fn main() { 324fn 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#"
353enum A { As, Bs, Cs(Option<i32>) } 353enum A { As, Bs, Cs(Option<i32>) }
354fn main() { 354fn 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
381fn main() { 381fn 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#"
726fn foo(opt: Option<i32>) { 726fn 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
278mod foo; 278mod foo;
279fn main() { foo::Foo<|> } 279fn main() { foo::Foo$0 }
280 280
281//- /foo.rs 281//- /foo.rs
282struct Foo; 282struct 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
302mod foo; 302mod foo;
303fn main() { foo::Foo { <|>bar: () }; } 303fn main() { foo::Foo { $0bar: () }; }
304//- /foo.rs 304//- /foo.rs
305pub struct Foo { bar: () } 305pub 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
319mod foo; 319mod foo;
320fn main() { foo::Foo { <|>bar: () }; } 320fn main() { foo::Foo { $0bar: () }; }
321//- /foo.rs 321//- /foo.rs
322pub struct Foo { pub bar: () } 322pub 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
340mod foo; 340mod foo;
341fn main() { foo::Foo::Bar { <|>bar: () }; } 341fn main() { foo::Foo::Bar { $0bar: () }; }
342//- /foo.rs 342//- /foo.rs
343pub enum Foo { Bar { bar: () } } 343pub 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
355mod foo; 355mod foo;
356fn main() { foo::Foo { <|>bar: () }; } 356fn main() { foo::Foo { $0bar: () }; }
357//- /foo.rs 357//- /foo.rs
358pub struct Foo { pub bar: () } 358pub 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
378mod foo; 378mod foo;
379fn main() { foo::Foo { <|>bar: () }; } 379fn main() { foo::Foo { $0bar: () }; }
380//- /foo.rs 380//- /foo.rs
381pub union Foo { bar: () } 381pub 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
395mod foo; 395mod foo;
396fn main() { foo::Foo { <|>bar: () }; } 396fn main() { foo::Foo { $0bar: () }; }
397//- /foo.rs 397//- /foo.rs
398pub union Foo { pub bar: () } 398pub 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
481mod foo; 481mod foo;
482fn main() { foo::bar<|>::baz(); } 482fn main() { foo::bar$0::baz(); }
483 483
484//- /foo.rs 484//- /foo.rs
485mod bar { 485mod 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
508mod foo; 508mod foo;
509fn main() { foo::bar<|>::baz(); } 509fn main() { foo::bar$0::baz(); }
510 510
511//- /foo.rs 511//- /foo.rs
512mod bar; 512mod bar;
@@ -525,7 +525,7 @@ pub fn baz() {}
525 r" 525 r"
526//- /main.rs 526//- /main.rs
527mod foo; 527mod foo;
528fn main() { foo::bar<|>>::baz(); } 528fn main() { foo::bar$0>::baz(); }
529 529
530//- /foo.rs 530//- /foo.rs
531mod bar { 531mod 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
548foo::Bar<|> 548foo::Bar$0
549//- /lib.rs crate:foo 549//- /lib.rs crate:foo
550struct Bar; 550struct 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
563foo::Bar<|> 563foo::Bar$0
564//- /lib.rs crate:foo 564//- /lib.rs crate:foo
565pub(crate) struct Bar; 565pub(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
574fn main() { 574fn main() {
575 foo::Foo { <|>bar: () }; 575 foo::Foo { $0bar: () };
576} 576}
577//- /lib.rs crate:foo 577//- /lib.rs crate:foo
578pub struct Foo { pub(crate) bar: () } 578pub 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#"
109enum Variant { 109enum 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#"
133enum Variant { 133enum 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#"
152enum Variant { 152enum 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#"
166enum Variant { Undefined } 166enum 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.
105struct Foo { a: i32<|>, } 105struct 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, }
121struct SomeThingIrrelevant; 121struct SomeThingIrrelevant;
122/// `Foo` is a pretty important struct. 122/// `Foo` is a pretty important struct.
123/// It does stuff. 123/// It does stuff.
124struct Foo { a: i32<|>, } 124struct Foo { a: i32$0, }
125struct EvenMoreIrrelevant; 125struct 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
107impl From<u32> for A { 107impl 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
122impl From<foo::bar::baz::Boo> for A { 122impl 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#"
156enum A { <|>One(u32), } 156enum A { $0One(u32), }
157 157
158impl From<u32> for A { 158impl 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
173impl From<String> for A { 173impl 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 @@
1use hir::HirDisplay; 1use hir::HirDisplay;
2use ide_db::base_db::FileId; 2use ide_db::{base_db::FileId, helpers::SnippetCap};
3use rustc_hash::{FxHashMap, FxHashSet}; 3use rustc_hash::{FxHashMap, FxHashSet};
4use syntax::{ 4use syntax::{
5 ast::{ 5 ast::{
@@ -11,7 +11,6 @@ use syntax::{
11}; 11};
12 12
13use crate::{ 13use 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"
345fn foo() { 344fn 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"
368impl Foo { 367impl 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"
394fn foo1() { 393fn foo1() {
395 bar<|>(); 394 bar$0();
396} 395}
397 396
398fn foo2() {} 397fn foo2() {}
@@ -418,7 +417,7 @@ fn foo2() {}
418 r" 417 r"
419mod baz { 418mod baz {
420 fn foo() { 419 fn foo() {
421 bar<|>(); 420 bar$0();
422 } 421 }
423} 422}
424", 423",
@@ -444,7 +443,7 @@ mod baz {
444struct Baz; 443struct Baz;
445fn baz() -> Baz { todo!() } 444fn baz() -> Baz { todo!() }
446fn foo() { 445fn 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:-> ()} {
469struct Baz; 468struct Baz;
470impl Baz { 469impl 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#"
502fn foo() { 501fn 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#"
523fn foo() { 522fn 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"
544fn foo() { 543fn 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"
565fn foo() { 564fn 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"
588fn foo() { 587fn 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"
611fn foo() { 610fn 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}
638fn baz() { 637fn baz() {
639 <|>bar(foo()) 638 $0bar(foo())
640} 639}
641", 640",
642 r" 641 r"
@@ -664,7 +663,7 @@ struct Baz;
664fn baz() -> Baz { todo!() } 663fn baz() -> Baz { todo!() }
665 664
666fn foo() { 665fn 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}
694fn foo() { 693fn 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"
721fn foo<T>(t: T) { 720fn 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}
748fn foo() { 747fn 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"
775fn foo() { 774fn 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"
798fn foo() { 797fn foo() {
799 <|>bar(baz) 798 $0bar(baz)
800} 799}
801", 800",
802 r" 801 r"
@@ -819,7 +818,7 @@ fn bar(baz: ()) ${0:-> ()} {
819struct Baz; 818struct Baz;
820fn baz() -> Baz { Baz } 819fn baz() -> Baz { Baz }
821fn foo() { 820fn 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:-> ()} {
844struct Baz; 843struct Baz;
845fn baz() -> Baz { Baz } 844fn baz() -> Baz { Baz }
846fn foo() { 845fn 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:-> ()} {
869mod bar {} 868mod bar {}
870 869
871fn foo() { 870fn foo() {
872 bar::my_fn<|>() 871 bar::my_fn$0()
873} 872}
874", 873",
875 r" 874 r"
@@ -900,7 +899,7 @@ mod foo {
900fn bar() { 899fn 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
932fn foo() { 931fn 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
961fn foo() { 960fn 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() {
987mod foo; 986mod foo;
988 987
989fn main() { 988fn 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"
1008fn foo() { 1007fn foo() {
1009 bar<|>(); 1008 bar$0();
1010} 1009}
1011 1010
1012fn bar() {} 1011fn bar() {}
@@ -1023,7 +1022,7 @@ fn bar() {}
1023 generate_function, 1022 generate_function,
1024 r" 1023 r"
1025fn foo() { 1024fn foo() {
1026 bar(b<|>az); 1025 bar(b$0az);
1027} 1026}
1028 1027
1029fn bar(baz: ()) {} 1028fn bar(baz: ()) {}
@@ -1040,7 +1039,7 @@ fn bar(baz: ()) {}
1040struct Foo; 1039struct Foo;
1041impl Foo { 1040impl 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 "
139struct SomeThingIrrelevant; 139struct SomeThingIrrelevant;
140/// Has a lifetime parameter 140/// Has a lifetime parameter
141struct Foo<'a, T: Foo<'a>> {<|>} 141struct Foo<'a, T: Foo<'a>> {$0}
142struct EvenMoreIrrelevant; 142struct 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
188impl Foo { 188impl 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
198impl<T: Clone> Foo<T> { 198impl<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
208impl<'a, T: Foo<'a>> Foo<'a, T> { 208impl<'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
218impl Foo { 218impl 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
228impl Foo { 228impl 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
240impl Foo { 240impl 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
251impl Foo {} 251impl 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
264impl Foo { 264impl 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
282impl Foo { 282impl 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
308impl Foo { 308impl 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
318impl Foo { 318impl 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 "
330struct Foo {<|>} 330struct Foo {$0}
331 331
332impl Foo { 332impl 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 "
342struct Foo {<|>} 342struct Foo {$0}
343 343
344impl Foo { 344impl Foo {
345 fn New() -> Self { 345 fn New() -> Self {
@@ -356,7 +356,7 @@ impl Foo {
356 " 356 "
357struct SomeThingIrrelevant; 357struct SomeThingIrrelevant;
358/// Has a lifetime parameter 358/// Has a lifetime parameter
359struct Foo<'a, T: Foo<'a>> {<|>} 359struct Foo<'a, T: Foo<'a>> {$0}
360struct EvenMoreIrrelevant; 360struct 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
383pub struct Source<T> { 383pub 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 @@
1use ast::make;
2use hir::{HasSource, PathResolution};
3use syntax::{
4 ast::{self, edit::AstNodeEdit, ArgListOwner},
5 AstNode,
6};
7use test_utils::mark;
8
9use 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);
22// }
23// ```
24// ->
25// ```
26// fn add(a: u32, b: u32) -> u32 { a + b }
27// fn main() {
28// let x = {
29// let a = 1;
30// let b = 2;
31// a + b
32// };
33// }
34// ```
35pub(crate) fn inline_function(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
36 let path_expr: ast::PathExpr = ctx.find_node_at_offset()?;
37 let call = path_expr.syntax().parent().and_then(ast::CallExpr::cast)?;
38 let path = path_expr.path()?;
39
40 let function = match ctx.sema.resolve_path(&path)? {
41 PathResolution::Def(hir::ModuleDef::Function(f)) => f,
42 _ => return None,
43 };
44
45 let function_source = function.source(ctx.db())?;
46 let arguments: Vec<_> = call.arg_list()?.args().collect();
47 let parameters = function_parameter_patterns(&function_source.value)?;
48
49 if arguments.len() != parameters.len() {
50 // Can't inline the function because they've passed the wrong number of
51 // arguments to this function
52 mark::hit!(inline_function_incorrect_number_of_arguments);
53 return None;
54 }
55
56 let new_bindings = parameters.into_iter().zip(arguments);
57
58 let body = function_source.value.body()?;
59
60 acc.add(
61 AssistId("inline_function", AssistKind::RefactorInline),
62 format!("Inline `{}`", path),
63 call.syntax().text_range(),
64 |builder| {
65 let mut statements: Vec<ast::Stmt> = Vec::new();
66
67 for (pattern, value) in new_bindings {
68 statements.push(make::let_stmt(pattern, Some(value)).into());
69 }
70
71 statements.extend(body.statements());
72
73 let original_indentation = call.indent_level();
74 let replacement = make::block_expr(statements, body.tail_expr())
75 .reset_indent()
76 .indent(original_indentation);
77
78 builder.replace_ast(ast::Expr::CallExpr(call), ast::Expr::BlockExpr(replacement));
79 },
80 )
81}
82
83fn function_parameter_patterns(value: &ast::Fn) -> Option<Vec<ast::Pat>> {
84 let mut patterns = Vec::new();
85
86 for param in value.param_list()?.params() {
87 let pattern = param.pat()?;
88 patterns.push(pattern);
89 }
90
91 Some(patterns)
92}
93
94#[cfg(test)]
95mod tests {
96 use crate::tests::{check_assist, check_assist_not_applicable};
97
98 use super::*;
99
100 #[test]
101 fn no_args_or_return_value_gets_inlined_without_block() {
102 check_assist(
103 inline_function,
104 r#"
105fn foo() { println!("Hello, World!"); }
106fn main() {
107 fo$0o();
108}
109"#,
110 r#"
111fn foo() { println!("Hello, World!"); }
112fn main() {
113 {
114 println!("Hello, World!");
115 };
116}
117"#,
118 );
119 }
120
121 #[test]
122 fn args_with_side_effects() {
123 check_assist(
124 inline_function,
125 r#"
126fn foo(name: String) { println!("Hello, {}!", name); }
127fn main() {
128 foo$0(String::from("Michael"));
129}
130"#,
131 r#"
132fn foo(name: String) { println!("Hello, {}!", name); }
133fn main() {
134 {
135 let name = String::from("Michael");
136 println!("Hello, {}!", name);
137 };
138}
139"#,
140 );
141 }
142
143 #[test]
144 fn method_inlining_isnt_supported() {
145 check_assist_not_applicable(
146 inline_function,
147 r"
148struct Foo;
149impl Foo { fn bar(&self) {} }
150
151fn main() { Foo.bar$0(); }
152",
153 );
154 }
155
156 #[test]
157 fn not_applicable_when_incorrect_number_of_parameters_are_provided() {
158 mark::check!(inline_function_incorrect_number_of_arguments);
159 check_assist_not_applicable(
160 inline_function,
161 r#"
162fn add(a: u32, b: u32) -> u32 { a + b }
163fn main() { let x = add$0(42); }
164"#,
165 );
166 }
167
168 #[test]
169 fn function_with_multiple_statements() {
170 check_assist(
171 inline_function,
172 r#"
173fn foo(a: u32, b: u32) -> u32 {
174 let x = a + b;
175 let y = x - b;
176 x * y
177}
178
179fn main() {
180 let x = foo$0(1, 2);
181}
182"#,
183 r#"
184fn foo(a: u32, b: u32) -> u32 {
185 let x = a + b;
186 let y = x - b;
187 x * y
188}
189
190fn main() {
191 let x = {
192 let a = 1;
193 let b = 2;
194 let x = a + b;
195 let y = x - b;
196 x * y
197 };
198}
199"#,
200 );
201 }
202}
diff --git a/crates/assists/src/handlers/inline_local_variable.rs b/crates/assists/src/handlers/inline_local_variable.rs
index 587eb5feb..dc798daaa 100644
--- a/crates/assists/src/handlers/inline_local_variable.rs
+++ b/crates/assists/src/handlers/inline_local_variable.rs
@@ -1,4 +1,7 @@
1use ide_db::{defs::Definition, search::ReferenceKind}; 1use ide_db::{
2 defs::Definition,
3 search::{FileReference, ReferenceKind},
4};
2use syntax::{ 5use syntax::{
3 ast::{self, AstNode, AstToken}, 6 ast::{self, AstNode, AstToken},
4 TextRange, 7 TextRange,
@@ -16,7 +19,7 @@ use crate::{
16// 19//
17// ``` 20// ```
18// fn main() { 21// fn main() {
19// let x<|> = 1 + 2; 22// let x$0 = 1 + 2;
20// x * 4; 23// x * 4;
21// } 24// }
22// ``` 25// ```
@@ -44,8 +47,8 @@ pub(crate) fn inline_local_variable(acc: &mut Assists, ctx: &AssistContext) -> O
44 47
45 let def = ctx.sema.to_def(&bind_pat)?; 48 let def = ctx.sema.to_def(&bind_pat)?;
46 let def = Definition::Local(def); 49 let def = Definition::Local(def);
47 let refs = def.usages(&ctx.sema).all(); 50 let usages = def.usages(&ctx.sema).all();
48 if refs.is_empty() { 51 if usages.is_empty() {
49 mark::hit!(test_not_applicable_if_variable_unused); 52 mark::hit!(test_not_applicable_if_variable_unused);
50 return None; 53 return None;
51 }; 54 };
@@ -63,48 +66,45 @@ pub(crate) fn inline_local_variable(acc: &mut Assists, ctx: &AssistContext) -> O
63 let_stmt.syntax().text_range() 66 let_stmt.syntax().text_range()
64 }; 67 };
65 68
66 let mut wrap_in_parens = vec![true; refs.len()]; 69 let wrap_in_parens = usages
67 70 .references
68 for (i, desc) in refs.iter().enumerate() { 71 .values()
69 let usage_node = ctx 72 .flatten()
70 .covering_node_for_range(desc.file_range.range) 73 .map(|&FileReference { range, .. }| {
71 .ancestors() 74 let usage_node =
72 .find_map(ast::PathExpr::cast)?; 75 ctx.covering_node_for_range(range).ancestors().find_map(ast::PathExpr::cast)?;
73 let usage_parent_option = usage_node.syntax().parent().and_then(ast::Expr::cast); 76 let usage_parent_option = usage_node.syntax().parent().and_then(ast::Expr::cast);
74 let usage_parent = match usage_parent_option { 77 let usage_parent = match usage_parent_option {
75 Some(u) => u, 78 Some(u) => u,
76 None => { 79 None => return Ok(false),
77 wrap_in_parens[i] = false; 80 };
78 continue; 81
79 } 82 Ok(!matches!((&initializer_expr, usage_parent),
80 }; 83 (ast::Expr::CallExpr(_), _)
81 84 | (ast::Expr::IndexExpr(_), _)
82 wrap_in_parens[i] = match (&initializer_expr, usage_parent) { 85 | (ast::Expr::MethodCallExpr(_), _)
83 (ast::Expr::CallExpr(_), _) 86 | (ast::Expr::FieldExpr(_), _)
84 | (ast::Expr::IndexExpr(_), _) 87 | (ast::Expr::TryExpr(_), _)
85 | (ast::Expr::MethodCallExpr(_), _) 88 | (ast::Expr::RefExpr(_), _)
86 | (ast::Expr::FieldExpr(_), _) 89 | (ast::Expr::Literal(_), _)
87 | (ast::Expr::TryExpr(_), _) 90 | (ast::Expr::TupleExpr(_), _)
88 | (ast::Expr::RefExpr(_), _) 91 | (ast::Expr::ArrayExpr(_), _)
89 | (ast::Expr::Literal(_), _) 92 | (ast::Expr::ParenExpr(_), _)
90 | (ast::Expr::TupleExpr(_), _) 93 | (ast::Expr::PathExpr(_), _)
91 | (ast::Expr::ArrayExpr(_), _) 94 | (ast::Expr::BlockExpr(_), _)
92 | (ast::Expr::ParenExpr(_), _) 95 | (ast::Expr::EffectExpr(_), _)
93 | (ast::Expr::PathExpr(_), _) 96 | (_, ast::Expr::CallExpr(_))
94 | (ast::Expr::BlockExpr(_), _) 97 | (_, ast::Expr::TupleExpr(_))
95 | (ast::Expr::EffectExpr(_), _) 98 | (_, ast::Expr::ArrayExpr(_))
96 | (_, ast::Expr::CallExpr(_)) 99 | (_, ast::Expr::ParenExpr(_))
97 | (_, ast::Expr::TupleExpr(_)) 100 | (_, ast::Expr::ForExpr(_))
98 | (_, ast::Expr::ArrayExpr(_)) 101 | (_, ast::Expr::WhileExpr(_))
99 | (_, ast::Expr::ParenExpr(_)) 102 | (_, ast::Expr::BreakExpr(_))
100 | (_, ast::Expr::ForExpr(_)) 103 | (_, ast::Expr::ReturnExpr(_))
101 | (_, ast::Expr::WhileExpr(_)) 104 | (_, ast::Expr::MatchExpr(_))
102 | (_, ast::Expr::BreakExpr(_)) 105 ))
103 | (_, ast::Expr::ReturnExpr(_)) 106 })
104 | (_, ast::Expr::MatchExpr(_)) => false, 107 .collect::<Result<Vec<_>, _>>()?;
105 _ => true,
106 };
107 }
108 108
109 let init_str = initializer_expr.syntax().text().to_string(); 109 let init_str = initializer_expr.syntax().text().to_string();
110 let init_in_paren = format!("({})", &init_str); 110 let init_in_paren = format!("({})", &init_str);
@@ -116,15 +116,16 @@ pub(crate) fn inline_local_variable(acc: &mut Assists, ctx: &AssistContext) -> O
116 target, 116 target,
117 move |builder| { 117 move |builder| {
118 builder.delete(delete_range); 118 builder.delete(delete_range);
119 for (desc, should_wrap) in refs.iter().zip(wrap_in_parens) { 119 for (reference, should_wrap) in usages.references.values().flatten().zip(wrap_in_parens)
120 {
120 let replacement = 121 let replacement =
121 if should_wrap { init_in_paren.clone() } else { init_str.clone() }; 122 if should_wrap { init_in_paren.clone() } else { init_str.clone() };
122 match desc.kind { 123 match reference.kind {
123 ReferenceKind::FieldShorthandForLocal => { 124 ReferenceKind::FieldShorthandForLocal => {
124 mark::hit!(inline_field_shorthand); 125 mark::hit!(inline_field_shorthand);
125 builder.insert(desc.file_range.range.end(), format!(": {}", replacement)) 126 builder.insert(reference.range.end(), format!(": {}", replacement))
126 } 127 }
127 _ => builder.replace(desc.file_range.range, replacement), 128 _ => builder.replace(reference.range, replacement),
128 } 129 }
129 } 130 }
130 }, 131 },
@@ -146,7 +147,7 @@ mod tests {
146 r" 147 r"
147fn bar(a: usize) {} 148fn bar(a: usize) {}
148fn foo() { 149fn foo() {
149 let a<|> = 1; 150 let a$0 = 1;
150 a + 1; 151 a + 1;
151 if a > 10 { 152 if a > 10 {
152 } 153 }
@@ -180,7 +181,7 @@ fn foo() {
180 r" 181 r"
181fn bar(a: usize) {} 182fn bar(a: usize) {}
182fn foo() { 183fn foo() {
183 let a<|> = 1 + 1; 184 let a$0 = 1 + 1;
184 a + 1; 185 a + 1;
185 if a > 10 { 186 if a > 10 {
186 } 187 }
@@ -214,7 +215,7 @@ fn foo() {
214 r" 215 r"
215fn bar(a: usize) {} 216fn bar(a: usize) {}
216fn foo() { 217fn foo() {
217 let a<|> = bar(1); 218 let a$0 = bar(1);
218 a + 1; 219 a + 1;
219 if a > 10 { 220 if a > 10 {
220 } 221 }
@@ -248,7 +249,7 @@ fn foo() {
248 r" 249 r"
249fn bar(a: usize): usize { a } 250fn bar(a: usize): usize { a }
250fn foo() { 251fn foo() {
251 let a<|> = bar(1) as u64; 252 let a$0 = bar(1) as u64;
252 a + 1; 253 a + 1;
253 if a > 10 { 254 if a > 10 {
254 } 255 }
@@ -281,7 +282,7 @@ fn foo() {
281 inline_local_variable, 282 inline_local_variable,
282 r" 283 r"
283fn foo() { 284fn foo() {
284 let a<|> = { 10 + 1 }; 285 let a$0 = { 10 + 1 };
285 a + 1; 286 a + 1;
286 if a > 10 { 287 if a > 10 {
287 } 288 }
@@ -313,7 +314,7 @@ fn foo() {
313 inline_local_variable, 314 inline_local_variable,
314 r" 315 r"
315fn foo() { 316fn foo() {
316 let a<|> = ( 10 + 1 ); 317 let a$0 = ( 10 + 1 );
317 a + 1; 318 a + 1;
318 if a > 10 { 319 if a > 10 {
319 } 320 }
@@ -346,7 +347,7 @@ fn foo() {
346 inline_local_variable, 347 inline_local_variable,
347 r" 348 r"
348fn foo() { 349fn foo() {
349 let mut a<|> = 1 + 1; 350 let mut a$0 = 1 + 1;
350 a + 1; 351 a + 1;
351}", 352}",
352 ); 353 );
@@ -358,7 +359,7 @@ fn foo() {
358 inline_local_variable, 359 inline_local_variable,
359 r" 360 r"
360fn foo() { 361fn foo() {
361 let a<|> = bar(10 + 1); 362 let a$0 = bar(10 + 1);
362 let b = a * 10; 363 let b = a * 10;
363 let c = a as usize; 364 let c = a as usize;
364}", 365}",
@@ -377,7 +378,7 @@ fn foo() {
377 r" 378 r"
378fn foo() { 379fn foo() {
379 let x = vec![1, 2, 3]; 380 let x = vec![1, 2, 3];
380 let a<|> = x[0]; 381 let a$0 = x[0];
381 let b = a * 10; 382 let b = a * 10;
382 let c = a as usize; 383 let c = a as usize;
383}", 384}",
@@ -397,7 +398,7 @@ fn foo() {
397 r" 398 r"
398fn foo() { 399fn foo() {
399 let bar = vec![1]; 400 let bar = vec![1];
400 let a<|> = bar.len(); 401 let a$0 = bar.len();
401 let b = a * 10; 402 let b = a * 10;
402 let c = a as usize; 403 let c = a as usize;
403}", 404}",
@@ -421,7 +422,7 @@ struct Bar {
421 422
422fn foo() { 423fn foo() {
423 let bar = Bar { foo: 1 }; 424 let bar = Bar { foo: 1 };
424 let a<|> = bar.foo; 425 let a$0 = bar.foo;
425 let b = a * 10; 426 let b = a * 10;
426 let c = a as usize; 427 let c = a as usize;
427}", 428}",
@@ -445,7 +446,7 @@ fn foo() {
445 r" 446 r"
446fn foo() -> Option<usize> { 447fn foo() -> Option<usize> {
447 let bar = Some(1); 448 let bar = Some(1);
448 let a<|> = bar?; 449 let a$0 = bar?;
449 let b = a * 10; 450 let b = a * 10;
450 let c = a as usize; 451 let c = a as usize;
451 None 452 None
@@ -467,7 +468,7 @@ fn foo() -> Option<usize> {
467 r" 468 r"
468fn foo() { 469fn foo() {
469 let bar = 10; 470 let bar = 10;
470 let a<|> = &bar; 471 let a$0 = &bar;
471 let b = a * 10; 472 let b = a * 10;
472}", 473}",
473 r" 474 r"
@@ -484,7 +485,7 @@ fn foo() {
484 inline_local_variable, 485 inline_local_variable,
485 r" 486 r"
486fn foo() { 487fn foo() {
487 let a<|> = (10, 20); 488 let a$0 = (10, 20);
488 let b = a[0]; 489 let b = a[0];
489}", 490}",
490 r" 491 r"
@@ -500,7 +501,7 @@ fn foo() {
500 inline_local_variable, 501 inline_local_variable,
501 r" 502 r"
502fn foo() { 503fn foo() {
503 let a<|> = [1, 2, 3]; 504 let a$0 = [1, 2, 3];
504 let b = a.len(); 505 let b = a.len();
505}", 506}",
506 r" 507 r"
@@ -516,7 +517,7 @@ fn foo() {
516 inline_local_variable, 517 inline_local_variable,
517 r" 518 r"
518fn foo() { 519fn foo() {
519 let a<|> = (10 + 20); 520 let a$0 = (10 + 20);
520 let b = a * 10; 521 let b = a * 10;
521 let c = a as usize; 522 let c = a as usize;
522}", 523}",
@@ -535,7 +536,7 @@ fn foo() {
535 r" 536 r"
536fn foo() { 537fn foo() {
537 let d = 10; 538 let d = 10;
538 let a<|> = d; 539 let a$0 = d;
539 let b = a * 10; 540 let b = a * 10;
540 let c = a as usize; 541 let c = a as usize;
541}", 542}",
@@ -554,7 +555,7 @@ fn foo() {
554 inline_local_variable, 555 inline_local_variable,
555 r" 556 r"
556fn foo() { 557fn foo() {
557 let a<|> = { 10 }; 558 let a$0 = { 10 };
558 let b = a * 10; 559 let b = a * 10;
559 let c = a as usize; 560 let c = a as usize;
560}", 561}",
@@ -572,7 +573,7 @@ fn foo() {
572 inline_local_variable, 573 inline_local_variable,
573 r" 574 r"
574fn foo() { 575fn foo() {
575 let a<|> = 10 + 20; 576 let a$0 = 10 + 20;
576 let b = a * 10; 577 let b = a * 10;
577 let c = (a, 20); 578 let c = (a, 20);
578 let d = [a, 10]; 579 let d = [a, 10];
@@ -594,7 +595,7 @@ fn foo() {
594 inline_local_variable, 595 inline_local_variable,
595 r" 596 r"
596fn foo() { 597fn foo() {
597 let a<|> = vec![10, 20]; 598 let a$0 = vec![10, 20];
598 for i in a {} 599 for i in a {}
599}", 600}",
600 r" 601 r"
@@ -610,7 +611,7 @@ fn foo() {
610 inline_local_variable, 611 inline_local_variable,
611 r" 612 r"
612fn foo() { 613fn foo() {
613 let a<|> = 1 > 0; 614 let a$0 = 1 > 0;
614 while a {} 615 while a {}
615}", 616}",
616 r" 617 r"
@@ -626,7 +627,7 @@ fn foo() {
626 inline_local_variable, 627 inline_local_variable,
627 r" 628 r"
628fn foo() { 629fn foo() {
629 let a<|> = 1 + 1; 630 let a$0 = 1 + 1;
630 loop { 631 loop {
631 break a; 632 break a;
632 } 633 }
@@ -646,7 +647,7 @@ fn foo() {
646 inline_local_variable, 647 inline_local_variable,
647 r" 648 r"
648fn foo() { 649fn foo() {
649 let a<|> = 1 > 0; 650 let a$0 = 1 > 0;
650 return a; 651 return a;
651}", 652}",
652 r" 653 r"
@@ -662,7 +663,7 @@ fn foo() {
662 inline_local_variable, 663 inline_local_variable,
663 r" 664 r"
664fn foo() { 665fn foo() {
665 let a<|> = 1 > 0; 666 let a$0 = 1 > 0;
666 match a {} 667 match a {}
667}", 668}",
668 r" 669 r"
@@ -680,7 +681,7 @@ fn foo() {
680 r" 681 r"
681struct S { foo: i32} 682struct S { foo: i32}
682fn main() { 683fn main() {
683 let <|>foo = 92; 684 let $0foo = 92;
684 S { foo } 685 S { foo }
685} 686}
686", 687",
@@ -700,7 +701,7 @@ fn main() {
700 inline_local_variable, 701 inline_local_variable,
701 r" 702 r"
702fn foo() { 703fn foo() {
703 let <|>a = 0; 704 let $0a = 0;
704} 705}
705 ", 706 ",
706 ) 707 )
@@ -713,7 +714,7 @@ fn foo() {
713 inline_local_variable, 714 inline_local_variable,
714 r" 715 r"
715fn main() { 716fn main() {
716 let x = <|>1 + 2; 717 let x = $01 + 2;
717 x * 4; 718 x * 4;
718} 719}
719", 720",
diff --git a/crates/assists/src/handlers/introduce_named_lifetime.rs b/crates/assists/src/handlers/introduce_named_lifetime.rs
index ab8fe3ea9..3f5f44d69 100644
--- a/crates/assists/src/handlers/introduce_named_lifetime.rs
+++ b/crates/assists/src/handlers/introduce_named_lifetime.rs
@@ -14,7 +14,7 @@ static ASSIST_LABEL: &str = "Introduce named lifetime";
14// Change an anonymous lifetime to a named lifetime. 14// Change an anonymous lifetime to a named lifetime.
15// 15//
16// ``` 16// ```
17// impl Cursor<'_<|>> { 17// impl Cursor<'_$0> {
18// fn node(self) -> &SyntaxNode { 18// fn node(self) -> &SyntaxNode {
19// match self { 19// match self {
20// Cursor::Replace(node) | Cursor::Before(node) => node, 20// Cursor::Replace(node) | Cursor::Before(node) => node,
@@ -33,7 +33,7 @@ static ASSIST_LABEL: &str = "Introduce named lifetime";
33// } 33// }
34// ``` 34// ```
35// FIXME: How can we handle renaming any one of multiple anonymous lifetimes? 35// FIXME: How can we handle renaming any one of multiple anonymous lifetimes?
36// FIXME: should also add support for the case fun(f: &Foo) -> &<|>Foo 36// FIXME: should also add support for the case fun(f: &Foo) -> &$0Foo
37pub(crate) fn introduce_named_lifetime(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 37pub(crate) fn introduce_named_lifetime(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
38 let lifetime = 38 let lifetime =
39 ctx.find_node_at_offset::<ast::Lifetime>().filter(|lifetime| lifetime.text() == "'_")?; 39 ctx.find_node_at_offset::<ast::Lifetime>().filter(|lifetime| lifetime.text() == "'_")?;
@@ -150,7 +150,7 @@ mod tests {
150 fn test_example_case() { 150 fn test_example_case() {
151 check_assist( 151 check_assist(
152 introduce_named_lifetime, 152 introduce_named_lifetime,
153 r#"impl Cursor<'_<|>> { 153 r#"impl Cursor<'_$0> {
154 fn node(self) -> &SyntaxNode { 154 fn node(self) -> &SyntaxNode {
155 match self { 155 match self {
156 Cursor::Replace(node) | Cursor::Before(node) => node, 156 Cursor::Replace(node) | Cursor::Before(node) => node,
@@ -171,7 +171,7 @@ mod tests {
171 fn test_example_case_simplified() { 171 fn test_example_case_simplified() {
172 check_assist( 172 check_assist(
173 introduce_named_lifetime, 173 introduce_named_lifetime,
174 r#"impl Cursor<'_<|>> {"#, 174 r#"impl Cursor<'_$0> {"#,
175 r#"impl<'a> Cursor<'a> {"#, 175 r#"impl<'a> Cursor<'a> {"#,
176 ); 176 );
177 } 177 }
@@ -180,7 +180,7 @@ mod tests {
180 fn test_example_case_cursor_after_tick() { 180 fn test_example_case_cursor_after_tick() {
181 check_assist( 181 check_assist(
182 introduce_named_lifetime, 182 introduce_named_lifetime,
183 r#"impl Cursor<'<|>_> {"#, 183 r#"impl Cursor<'$0_> {"#,
184 r#"impl<'a> Cursor<'a> {"#, 184 r#"impl<'a> Cursor<'a> {"#,
185 ); 185 );
186 } 186 }
@@ -189,7 +189,7 @@ mod tests {
189 fn test_impl_with_other_type_param() { 189 fn test_impl_with_other_type_param() {
190 check_assist( 190 check_assist(
191 introduce_named_lifetime, 191 introduce_named_lifetime,
192 "impl<I> fmt::Display for SepByBuilder<'_<|>, I> 192 "impl<I> fmt::Display for SepByBuilder<'_$0, I>
193 where 193 where
194 I: Iterator, 194 I: Iterator,
195 I::Item: fmt::Display, 195 I::Item: fmt::Display,
@@ -206,28 +206,28 @@ mod tests {
206 fn test_example_case_cursor_before_tick() { 206 fn test_example_case_cursor_before_tick() {
207 check_assist( 207 check_assist(
208 introduce_named_lifetime, 208 introduce_named_lifetime,
209 r#"impl Cursor<<|>'_> {"#, 209 r#"impl Cursor<$0'_> {"#,
210 r#"impl<'a> Cursor<'a> {"#, 210 r#"impl<'a> Cursor<'a> {"#,
211 ); 211 );
212 } 212 }
213 213
214 #[test] 214 #[test]
215 fn test_not_applicable_cursor_position() { 215 fn test_not_applicable_cursor_position() {
216 check_assist_not_applicable(introduce_named_lifetime, r#"impl Cursor<'_><|> {"#); 216 check_assist_not_applicable(introduce_named_lifetime, r#"impl Cursor<'_>$0 {"#);
217 check_assist_not_applicable(introduce_named_lifetime, r#"impl Cursor<|><'_> {"#); 217 check_assist_not_applicable(introduce_named_lifetime, r#"impl Cursor$0<'_> {"#);
218 } 218 }
219 219
220 #[test] 220 #[test]
221 fn test_not_applicable_lifetime_already_name() { 221 fn test_not_applicable_lifetime_already_name() {
222 check_assist_not_applicable(introduce_named_lifetime, r#"impl Cursor<'a<|>> {"#); 222 check_assist_not_applicable(introduce_named_lifetime, r#"impl Cursor<'a$0> {"#);
223 check_assist_not_applicable(introduce_named_lifetime, r#"fn my_fun<'a>() -> X<'a<|>>"#); 223 check_assist_not_applicable(introduce_named_lifetime, r#"fn my_fun<'a>() -> X<'a$0>"#);
224 } 224 }
225 225
226 #[test] 226 #[test]
227 fn test_with_type_parameter() { 227 fn test_with_type_parameter() {
228 check_assist( 228 check_assist(
229 introduce_named_lifetime, 229 introduce_named_lifetime,
230 r#"impl<T> Cursor<T, '_<|>>"#, 230 r#"impl<T> Cursor<T, '_$0>"#,
231 r#"impl<T, 'a> Cursor<T, 'a>"#, 231 r#"impl<T, 'a> Cursor<T, 'a>"#,
232 ); 232 );
233 } 233 }
@@ -236,7 +236,7 @@ mod tests {
236 fn test_with_existing_lifetime_name_conflict() { 236 fn test_with_existing_lifetime_name_conflict() {
237 check_assist( 237 check_assist(
238 introduce_named_lifetime, 238 introduce_named_lifetime,
239 r#"impl<'a, 'b> Cursor<'a, 'b, '_<|>>"#, 239 r#"impl<'a, 'b> Cursor<'a, 'b, '_$0>"#,
240 r#"impl<'a, 'b, 'c> Cursor<'a, 'b, 'c>"#, 240 r#"impl<'a, 'b, 'c> Cursor<'a, 'b, 'c>"#,
241 ); 241 );
242 } 242 }
@@ -245,7 +245,7 @@ mod tests {
245 fn test_function_return_value_anon_lifetime_param() { 245 fn test_function_return_value_anon_lifetime_param() {
246 check_assist( 246 check_assist(
247 introduce_named_lifetime, 247 introduce_named_lifetime,
248 r#"fn my_fun() -> X<'_<|>>"#, 248 r#"fn my_fun() -> X<'_$0>"#,
249 r#"fn my_fun<'a>() -> X<'a>"#, 249 r#"fn my_fun<'a>() -> X<'a>"#,
250 ); 250 );
251 } 251 }
@@ -254,7 +254,7 @@ mod tests {
254 fn test_function_return_value_anon_reference_lifetime() { 254 fn test_function_return_value_anon_reference_lifetime() {
255 check_assist( 255 check_assist(
256 introduce_named_lifetime, 256 introduce_named_lifetime,
257 r#"fn my_fun() -> &'_<|> X"#, 257 r#"fn my_fun() -> &'_$0 X"#,
258 r#"fn my_fun<'a>() -> &'a X"#, 258 r#"fn my_fun<'a>() -> &'a X"#,
259 ); 259 );
260 } 260 }
@@ -263,7 +263,7 @@ mod tests {
263 fn test_function_param_anon_lifetime() { 263 fn test_function_param_anon_lifetime() {
264 check_assist( 264 check_assist(
265 introduce_named_lifetime, 265 introduce_named_lifetime,
266 r#"fn my_fun(x: X<'_<|>>)"#, 266 r#"fn my_fun(x: X<'_$0>)"#,
267 r#"fn my_fun<'a>(x: X<'a>)"#, 267 r#"fn my_fun<'a>(x: X<'a>)"#,
268 ); 268 );
269 } 269 }
@@ -272,7 +272,7 @@ mod tests {
272 fn test_function_add_lifetime_to_params() { 272 fn test_function_add_lifetime_to_params() {
273 check_assist( 273 check_assist(
274 introduce_named_lifetime, 274 introduce_named_lifetime,
275 r#"fn my_fun(f: &Foo) -> X<'_<|>>"#, 275 r#"fn my_fun(f: &Foo) -> X<'_$0>"#,
276 r#"fn my_fun<'a>(f: &'a Foo) -> X<'a>"#, 276 r#"fn my_fun<'a>(f: &'a Foo) -> X<'a>"#,
277 ); 277 );
278 } 278 }
@@ -281,7 +281,7 @@ mod tests {
281 fn test_function_add_lifetime_to_params_in_presence_of_other_lifetime() { 281 fn test_function_add_lifetime_to_params_in_presence_of_other_lifetime() {
282 check_assist( 282 check_assist(
283 introduce_named_lifetime, 283 introduce_named_lifetime,
284 r#"fn my_fun<'other>(f: &Foo, b: &'other Bar) -> X<'_<|>>"#, 284 r#"fn my_fun<'other>(f: &Foo, b: &'other Bar) -> X<'_$0>"#,
285 r#"fn my_fun<'other, 'a>(f: &'a Foo, b: &'other Bar) -> X<'a>"#, 285 r#"fn my_fun<'other, 'a>(f: &'a Foo, b: &'other Bar) -> X<'a>"#,
286 ); 286 );
287 } 287 }
@@ -291,7 +291,7 @@ mod tests {
291 // this is not permitted under lifetime elision rules 291 // this is not permitted under lifetime elision rules
292 check_assist_not_applicable( 292 check_assist_not_applicable(
293 introduce_named_lifetime, 293 introduce_named_lifetime,
294 r#"fn my_fun(f: &Foo, b: &Bar) -> X<'_<|>>"#, 294 r#"fn my_fun(f: &Foo, b: &Bar) -> X<'_$0>"#,
295 ); 295 );
296 } 296 }
297 297
@@ -299,7 +299,7 @@ mod tests {
299 fn test_function_add_lifetime_to_self_ref_param() { 299 fn test_function_add_lifetime_to_self_ref_param() {
300 check_assist( 300 check_assist(
301 introduce_named_lifetime, 301 introduce_named_lifetime,
302 r#"fn my_fun<'other>(&self, f: &Foo, b: &'other Bar) -> X<'_<|>>"#, 302 r#"fn my_fun<'other>(&self, f: &Foo, b: &'other Bar) -> X<'_$0>"#,
303 r#"fn my_fun<'other, 'a>(&'a self, f: &Foo, b: &'other Bar) -> X<'a>"#, 303 r#"fn my_fun<'other, 'a>(&'a self, f: &Foo, b: &'other Bar) -> X<'a>"#,
304 ); 304 );
305 } 305 }
@@ -308,7 +308,7 @@ mod tests {
308 fn test_function_add_lifetime_to_param_with_non_ref_self() { 308 fn test_function_add_lifetime_to_param_with_non_ref_self() {
309 check_assist( 309 check_assist(
310 introduce_named_lifetime, 310 introduce_named_lifetime,
311 r#"fn my_fun<'other>(self, f: &Foo, b: &'other Bar) -> X<'_<|>>"#, 311 r#"fn my_fun<'other>(self, f: &Foo, b: &'other Bar) -> X<'_$0>"#,
312 r#"fn my_fun<'other, 'a>(self, f: &'a Foo, b: &'other Bar) -> X<'a>"#, 312 r#"fn my_fun<'other, 'a>(self, f: &'a Foo, b: &'other Bar) -> X<'a>"#,
313 ); 313 );
314 } 314 }
diff --git a/crates/assists/src/handlers/invert_if.rs b/crates/assists/src/handlers/invert_if.rs
index f9c33b3f7..5b69dafd4 100644
--- a/crates/assists/src/handlers/invert_if.rs
+++ b/crates/assists/src/handlers/invert_if.rs
@@ -18,7 +18,7 @@ use crate::{
18// 18//
19// ``` 19// ```
20// fn main() { 20// fn main() {
21// if<|> !y { A } else { B } 21// if$0 !y { A } else { B }
22// } 22// }
23// ``` 23// ```
24// -> 24// ->
@@ -72,7 +72,7 @@ mod tests {
72 fn invert_if_composite_condition() { 72 fn invert_if_composite_condition() {
73 check_assist( 73 check_assist(
74 invert_if, 74 invert_if,
75 "fn f() { i<|>f x == 3 || x == 4 || x == 5 { 1 } else { 3 * 2 } }", 75 "fn f() { i$0f x == 3 || x == 4 || x == 5 { 1 } else { 3 * 2 } }",
76 "fn f() { if !(x == 3 || x == 4 || x == 5) { 3 * 2 } else { 1 } }", 76 "fn f() { if !(x == 3 || x == 4 || x == 5) { 3 * 2 } else { 1 } }",
77 ) 77 )
78 } 78 }
@@ -81,7 +81,7 @@ mod tests {
81 fn invert_if_remove_not_parentheses() { 81 fn invert_if_remove_not_parentheses() {
82 check_assist( 82 check_assist(
83 invert_if, 83 invert_if,
84 "fn f() { i<|>f !(x == 3 || x == 4 || x == 5) { 3 * 2 } else { 1 } }", 84 "fn f() { i$0f !(x == 3 || x == 4 || x == 5) { 3 * 2 } else { 1 } }",
85 "fn f() { if x == 3 || x == 4 || x == 5 { 1 } else { 3 * 2 } }", 85 "fn f() { if x == 3 || x == 4 || x == 5 { 1 } else { 3 * 2 } }",
86 ) 86 )
87 } 87 }
@@ -90,7 +90,7 @@ mod tests {
90 fn invert_if_remove_inequality() { 90 fn invert_if_remove_inequality() {
91 check_assist( 91 check_assist(
92 invert_if, 92 invert_if,
93 "fn f() { i<|>f x != 3 { 1 } else { 3 + 2 } }", 93 "fn f() { i$0f x != 3 { 1 } else { 3 + 2 } }",
94 "fn f() { if x == 3 { 3 + 2 } else { 1 } }", 94 "fn f() { if x == 3 { 3 + 2 } else { 1 } }",
95 ) 95 )
96 } 96 }
@@ -99,7 +99,7 @@ mod tests {
99 fn invert_if_remove_not() { 99 fn invert_if_remove_not() {
100 check_assist( 100 check_assist(
101 invert_if, 101 invert_if,
102 "fn f() { <|>if !cond { 3 * 2 } else { 1 } }", 102 "fn f() { $0if !cond { 3 * 2 } else { 1 } }",
103 "fn f() { if cond { 1 } else { 3 * 2 } }", 103 "fn f() { if cond { 1 } else { 3 * 2 } }",
104 ) 104 )
105 } 105 }
@@ -108,21 +108,21 @@ mod tests {
108 fn invert_if_general_case() { 108 fn invert_if_general_case() {
109 check_assist( 109 check_assist(
110 invert_if, 110 invert_if,
111 "fn f() { i<|>f cond { 3 * 2 } else { 1 } }", 111 "fn f() { i$0f cond { 3 * 2 } else { 1 } }",
112 "fn f() { if !cond { 1 } else { 3 * 2 } }", 112 "fn f() { if !cond { 1 } else { 3 * 2 } }",
113 ) 113 )
114 } 114 }
115 115
116 #[test] 116 #[test]
117 fn invert_if_doesnt_apply_with_cursor_not_on_if() { 117 fn invert_if_doesnt_apply_with_cursor_not_on_if() {
118 check_assist_not_applicable(invert_if, "fn f() { if !<|>cond { 3 * 2 } else { 1 } }") 118 check_assist_not_applicable(invert_if, "fn f() { if !$0cond { 3 * 2 } else { 1 } }")
119 } 119 }
120 120
121 #[test] 121 #[test]
122 fn invert_if_doesnt_apply_with_if_let() { 122 fn invert_if_doesnt_apply_with_if_let() {
123 check_assist_not_applicable( 123 check_assist_not_applicable(
124 invert_if, 124 invert_if,
125 "fn f() { i<|>f let Some(_) = Some(1) { 1 } else { 0 } }", 125 "fn f() { i$0f let Some(_) = Some(1) { 1 } else { 0 } }",
126 ) 126 )
127 } 127 }
128 128
@@ -130,7 +130,7 @@ mod tests {
130 fn invert_if_option_case() { 130 fn invert_if_option_case() {
131 check_assist( 131 check_assist(
132 invert_if, 132 invert_if,
133 "fn f() { if<|> doc_style.is_some() { Class::DocComment } else { Class::Comment } }", 133 "fn f() { if$0 doc_style.is_some() { Class::DocComment } else { Class::Comment } }",
134 "fn f() { if doc_style.is_none() { Class::Comment } else { Class::DocComment } }", 134 "fn f() { if doc_style.is_none() { Class::Comment } else { Class::DocComment } }",
135 ) 135 )
136 } 136 }
@@ -139,7 +139,7 @@ mod tests {
139 fn invert_if_result_case() { 139 fn invert_if_result_case() {
140 check_assist( 140 check_assist(
141 invert_if, 141 invert_if,
142 "fn f() { i<|>f doc_style.is_err() { Class::Err } else { Class::Ok } }", 142 "fn f() { i$0f doc_style.is_err() { Class::Err } else { Class::Ok } }",
143 "fn f() { if doc_style.is_ok() { Class::Ok } else { Class::Err } }", 143 "fn f() { if doc_style.is_ok() { Class::Ok } else { Class::Err } }",
144 ) 144 )
145 } 145 }
diff --git a/crates/assists/src/handlers/merge_imports.rs b/crates/assists/src/handlers/merge_imports.rs
index 2f0dc7831..7bd7e1e36 100644
--- a/crates/assists/src/handlers/merge_imports.rs
+++ b/crates/assists/src/handlers/merge_imports.rs
@@ -15,7 +15,7 @@ use crate::{
15// Merges two imports with a common prefix. 15// Merges two imports with a common prefix.
16// 16//
17// ``` 17// ```
18// use std::<|>fmt::Formatter; 18// use std::$0fmt::Formatter;
19// use std::io; 19// use std::io;
20// ``` 20// ```
21// -> 21// ->
@@ -75,7 +75,7 @@ mod tests {
75 check_assist( 75 check_assist(
76 merge_imports, 76 merge_imports,
77 r" 77 r"
78use std::fmt<|>::{Display, Debug}; 78use std::fmt$0::{Display, Debug};
79use std::fmt::{Display, Debug}; 79use std::fmt::{Display, Debug};
80", 80",
81 r" 81 r"
@@ -89,7 +89,7 @@ use std::fmt::{Debug, Display};
89 check_assist( 89 check_assist(
90 merge_imports, 90 merge_imports,
91 r" 91 r"
92use std::fmt<|>::Debug; 92use std::fmt$0::Debug;
93use std::fmt::Display; 93use std::fmt::Display;
94", 94",
95 r" 95 r"
@@ -104,7 +104,7 @@ use std::fmt::{Debug, Display};
104 merge_imports, 104 merge_imports,
105 r" 105 r"
106use std::fmt::Debug; 106use std::fmt::Debug;
107use std::fmt<|>::Display; 107use std::fmt$0::Display;
108", 108",
109 r" 109 r"
110use std::fmt::{Debug, Display}; 110use std::fmt::{Debug, Display};
@@ -117,7 +117,7 @@ use std::fmt::{Debug, Display};
117 check_assist( 117 check_assist(
118 merge_imports, 118 merge_imports,
119 r" 119 r"
120use std::fmt<|>; 120use std::fmt$0;
121use std::fmt::Display; 121use std::fmt::Display;
122", 122",
123 r" 123 r"
@@ -131,7 +131,7 @@ use std::fmt::{self, Display};
131 check_assist( 131 check_assist(
132 merge_imports, 132 merge_imports,
133 r" 133 r"
134use std::{fmt, <|>fmt::Display}; 134use std::{fmt, $0fmt::Display};
135", 135",
136 r" 136 r"
137use std::{fmt::{self, Display}}; 137use std::{fmt::{self, Display}};
@@ -144,7 +144,7 @@ use std::{fmt::{self, Display}};
144 check_assist_not_applicable( 144 check_assist_not_applicable(
145 merge_imports, 145 merge_imports,
146 r" 146 r"
147pub use std::fmt<|>::Debug; 147pub use std::fmt$0::Debug;
148use std::fmt::Display; 148use std::fmt::Display;
149", 149",
150 ); 150 );
@@ -155,7 +155,7 @@ use std::fmt::Display;
155 check_assist_not_applicable( 155 check_assist_not_applicable(
156 merge_imports, 156 merge_imports,
157 r" 157 r"
158use std::fmt<|>::Debug; 158use std::fmt$0::Debug;
159pub use std::fmt::Display; 159pub use std::fmt::Display;
160", 160",
161 ); 161 );
@@ -166,7 +166,7 @@ pub use std::fmt::Display;
166 check_assist_not_applicable( 166 check_assist_not_applicable(
167 merge_imports, 167 merge_imports,
168 r" 168 r"
169pub(crate) use std::fmt<|>::Debug; 169pub(crate) use std::fmt$0::Debug;
170pub use std::fmt::Display; 170pub use std::fmt::Display;
171", 171",
172 ); 172 );
@@ -177,7 +177,7 @@ pub use std::fmt::Display;
177 check_assist_not_applicable( 177 check_assist_not_applicable(
178 merge_imports, 178 merge_imports,
179 r" 179 r"
180pub use std::fmt<|>::Debug; 180pub use std::fmt$0::Debug;
181pub(crate) use std::fmt::Display; 181pub(crate) use std::fmt::Display;
182", 182",
183 ); 183 );
@@ -188,7 +188,7 @@ pub(crate) use std::fmt::Display;
188 check_assist( 188 check_assist(
189 merge_imports, 189 merge_imports,
190 r" 190 r"
191pub use std::fmt<|>::Debug; 191pub use std::fmt$0::Debug;
192pub use std::fmt::Display; 192pub use std::fmt::Display;
193", 193",
194 r" 194 r"
@@ -202,7 +202,7 @@ pub use std::fmt::{Debug, Display};
202 check_assist( 202 check_assist(
203 merge_imports, 203 merge_imports,
204 r" 204 r"
205pub(crate) use std::fmt<|>::Debug; 205pub(crate) use std::fmt$0::Debug;
206pub(crate) use std::fmt::Display; 206pub(crate) use std::fmt::Display;
207", 207",
208 r" 208 r"
@@ -216,7 +216,7 @@ pub(crate) use std::fmt::{Debug, Display};
216 check_assist( 216 check_assist(
217 merge_imports, 217 merge_imports,
218 r" 218 r"
219use std::{fmt<|>::Debug, fmt::Display}; 219use std::{fmt$0::Debug, fmt::Display};
220", 220",
221 r" 221 r"
222use std::{fmt::{Debug, Display}}; 222use std::{fmt::{Debug, Display}};
@@ -229,7 +229,7 @@ use std::{fmt::{Debug, Display}};
229 check_assist( 229 check_assist(
230 merge_imports, 230 merge_imports,
231 r" 231 r"
232use std::{fmt::Debug, fmt<|>::Display}; 232use std::{fmt::Debug, fmt$0::Display};
233", 233",
234 r" 234 r"
235use std::{fmt::{Debug, Display}}; 235use std::{fmt::{Debug, Display}};
@@ -242,7 +242,7 @@ use std::{fmt::{Debug, Display}};
242 check_assist( 242 check_assist(
243 merge_imports, 243 merge_imports,
244 r" 244 r"
245use std<|>::cell::*; 245use std$0::cell::*;
246use std::str; 246use std::str;
247", 247",
248 r" 248 r"
@@ -256,7 +256,7 @@ use std::{cell::*, str};
256 check_assist( 256 check_assist(
257 merge_imports, 257 merge_imports,
258 r" 258 r"
259use std<|>::cell::*; 259use std$0::cell::*;
260use std::str::*; 260use std::str::*;
261", 261",
262 r" 262 r"
@@ -270,7 +270,7 @@ use std::{cell::*, str::*};
270 check_assist( 270 check_assist(
271 merge_imports, 271 merge_imports,
272 r" 272 r"
273use foo<|>::bar; 273use foo$0::bar;
274use foo::baz; 274use foo::baz;
275 275
276/// Doc comment 276/// Doc comment
@@ -289,7 +289,7 @@ use foo::{bar, baz};
289 merge_imports, 289 merge_imports,
290 r" 290 r"
291use { 291use {
292 foo<|>::bar, 292 foo$0::bar,
293 foo::baz, 293 foo::baz,
294}; 294};
295", 295",
@@ -304,7 +304,7 @@ use {
304 r" 304 r"
305use { 305use {
306 foo::baz, 306 foo::baz,
307 foo<|>::bar, 307 foo$0::bar,
308}; 308};
309", 309",
310 r" 310 r"
@@ -321,7 +321,7 @@ use {
321 merge_imports, 321 merge_imports,
322 r" 322 r"
323use foo::bar::baz; 323use foo::bar::baz;
324use foo::<|>{ 324use foo::$0{
325 FooBar, 325 FooBar,
326}; 326};
327", 327",
@@ -336,7 +336,7 @@ use foo::{FooBar, bar::baz};
336 check_assist_not_applicable( 336 check_assist_not_applicable(
337 merge_imports, 337 merge_imports,
338 r" 338 r"
339use std::<|> 339use std::$0
340fn main() {}", 340fn main() {}",
341 ); 341 );
342 } 342 }
diff --git a/crates/assists/src/handlers/merge_match_arms.rs b/crates/assists/src/handlers/merge_match_arms.rs
index c347eb40e..9bf076cb9 100644
--- a/crates/assists/src/handlers/merge_match_arms.rs
+++ b/crates/assists/src/handlers/merge_match_arms.rs
@@ -17,7 +17,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists, TextRange};
17// 17//
18// fn handle(action: Action) { 18// fn handle(action: Action) {
19// match action { 19// match action {
20// <|>Action::Move(..) => foo(), 20// $0Action::Move(..) => foo(),
21// Action::Stop => foo(), 21// Action::Stop => foo(),
22// } 22// }
23// } 23// }
@@ -106,7 +106,7 @@ mod tests {
106 fn main() { 106 fn main() {
107 let x = X::A; 107 let x = X::A;
108 let y = match x { 108 let y = match x {
109 X::A => { 1i32<|> } 109 X::A => { 1i32$0 }
110 X::B => { 1i32 } 110 X::B => { 1i32 }
111 X::C => { 2i32 } 111 X::C => { 2i32 }
112 } 112 }
@@ -138,7 +138,7 @@ mod tests {
138 fn main() { 138 fn main() {
139 let x = X::A; 139 let x = X::A;
140 let y = match x { 140 let y = match x {
141 X::A | X::B => {<|> 1i32 }, 141 X::A | X::B => {$0 1i32 },
142 X::C | X::D => { 1i32 }, 142 X::C | X::D => { 1i32 },
143 X::E => { 2i32 }, 143 X::E => { 2i32 },
144 } 144 }
@@ -171,7 +171,7 @@ mod tests {
171 let x = X::A; 171 let x = X::A;
172 let y = match x { 172 let y = match x {
173 X::A => { 1i32 }, 173 X::A => { 1i32 },
174 X::B => { 2i<|>32 }, 174 X::B => { 2i$032 },
175 _ => { 2i32 } 175 _ => { 2i32 }
176 } 176 }
177 } 177 }
@@ -200,7 +200,7 @@ mod tests {
200 200
201 fn main() { 201 fn main() {
202 match X::A { 202 match X::A {
203 X::A<|> => 92, 203 X::A$0 => 92,
204 X::B => 92, 204 X::B => 92,
205 X::C => 92, 205 X::C => 92,
206 X::D => 62, 206 X::D => 62,
@@ -237,7 +237,7 @@ mod tests {
237 fn main() { 237 fn main() {
238 let x = X::A; 238 let x = X::A;
239 let y = match x { 239 let y = match x {
240 X::A(a) if a > 5 => { <|>1i32 }, 240 X::A(a) if a > 5 => { $01i32 },
241 X::B => { 1i32 }, 241 X::B => { 1i32 },
242 X::C => { 2i32 } 242 X::C => { 2i32 }
243 } 243 }
diff --git a/crates/assists/src/handlers/move_bounds.rs b/crates/assists/src/handlers/move_bounds.rs
index e2e461520..cf260c6f8 100644
--- a/crates/assists/src/handlers/move_bounds.rs
+++ b/crates/assists/src/handlers/move_bounds.rs
@@ -12,7 +12,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
12// Moves inline type bounds to a where clause. 12// Moves inline type bounds to a where clause.
13// 13//
14// ``` 14// ```
15// fn apply<T, U, <|>F: FnOnce(T) -> U>(f: F, x: T) -> U { 15// fn apply<T, U, $0F: FnOnce(T) -> U>(f: F, x: T) -> U {
16// f(x) 16// f(x)
17// } 17// }
18// ``` 18// ```
@@ -103,7 +103,7 @@ mod tests {
103 check_assist( 103 check_assist(
104 move_bounds_to_where_clause, 104 move_bounds_to_where_clause,
105 r#" 105 r#"
106 fn foo<T: u32, <|>F: FnOnce(T) -> T>() {} 106 fn foo<T: u32, $0F: FnOnce(T) -> T>() {}
107 "#, 107 "#,
108 r#" 108 r#"
109 fn foo<T, F>() where T: u32, F: FnOnce(T) -> T {} 109 fn foo<T, F>() where T: u32, F: FnOnce(T) -> T {}
@@ -116,7 +116,7 @@ mod tests {
116 check_assist( 116 check_assist(
117 move_bounds_to_where_clause, 117 move_bounds_to_where_clause,
118 r#" 118 r#"
119 impl<U: u32, <|>T> A<U, T> {} 119 impl<U: u32, $0T> A<U, T> {}
120 "#, 120 "#,
121 r#" 121 r#"
122 impl<U, T> A<U, T> where U: u32 {} 122 impl<U, T> A<U, T> where U: u32 {}
@@ -129,7 +129,7 @@ mod tests {
129 check_assist( 129 check_assist(
130 move_bounds_to_where_clause, 130 move_bounds_to_where_clause,
131 r#" 131 r#"
132 struct A<<|>T: Iterator<Item = u32>> {} 132 struct A<$0T: Iterator<Item = u32>> {}
133 "#, 133 "#,
134 r#" 134 r#"
135 struct A<T> where T: Iterator<Item = u32> {} 135 struct A<T> where T: Iterator<Item = u32> {}
@@ -142,7 +142,7 @@ mod tests {
142 check_assist( 142 check_assist(
143 move_bounds_to_where_clause, 143 move_bounds_to_where_clause,
144 r#" 144 r#"
145 struct Pair<<|>T: u32>(T, T); 145 struct Pair<$0T: u32>(T, T);
146 "#, 146 "#,
147 r#" 147 r#"
148 struct Pair<T>(T, T) where T: u32; 148 struct Pair<T>(T, T) where T: u32;
diff --git a/crates/assists/src/handlers/move_guard.rs b/crates/assists/src/handlers/move_guard.rs
index eaffd80ce..3f22302a9 100644
--- a/crates/assists/src/handlers/move_guard.rs
+++ b/crates/assists/src/handlers/move_guard.rs
@@ -14,7 +14,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
14// 14//
15// fn handle(action: Action) { 15// fn handle(action: Action) {
16// match action { 16// match action {
17// Action::Move { distance } <|>if distance > 10 => foo(), 17// Action::Move { distance } $0if distance > 10 => foo(),
18// _ => (), 18// _ => (),
19// } 19// }
20// } 20// }
@@ -74,7 +74,7 @@ pub(crate) fn move_guard_to_arm_body(acc: &mut Assists, ctx: &AssistContext) ->
74// 74//
75// fn handle(action: Action) { 75// fn handle(action: Action) {
76// match action { 76// match action {
77// Action::Move { distance } => <|>if distance > 10 { foo() }, 77// Action::Move { distance } => $0if distance > 10 { foo() },
78// _ => (), 78// _ => (),
79// } 79// }
80// } 80// }
@@ -98,7 +98,7 @@ pub(crate) fn move_arm_cond_to_match_guard(acc: &mut Assists, ctx: &AssistContex
98 let mut replace_node = None; 98 let mut replace_node = None;
99 let if_expr: IfExpr = IfExpr::cast(arm_body.syntax().clone()).or_else(|| { 99 let if_expr: IfExpr = IfExpr::cast(arm_body.syntax().clone()).or_else(|| {
100 let block_expr = BlockExpr::cast(arm_body.syntax().clone())?; 100 let block_expr = BlockExpr::cast(arm_body.syntax().clone())?;
101 if let Expr::IfExpr(e) = block_expr.expr()? { 101 if let Expr::IfExpr(e) = block_expr.tail_expr()? {
102 replace_node = Some(block_expr.syntax().clone()); 102 replace_node = Some(block_expr.syntax().clone());
103 Some(e) 103 Some(e)
104 } else { 104 } else {
@@ -128,7 +128,7 @@ pub(crate) fn move_arm_cond_to_match_guard(acc: &mut Assists, ctx: &AssistContex
128 |edit| { 128 |edit| {
129 let then_only_expr = then_block.statements().next().is_none(); 129 let then_only_expr = then_block.statements().next().is_none();
130 130
131 match &then_block.expr() { 131 match &then_block.tail_expr() {
132 Some(then_expr) if then_only_expr => { 132 Some(then_expr) if then_only_expr => {
133 edit.replace(replace_node.text_range(), then_expr.syntax().text()) 133 edit.replace(replace_node.text_range(), then_expr.syntax().text())
134 } 134 }
@@ -158,7 +158,7 @@ mod tests {
158 r#" 158 r#"
159fn main() { 159fn main() {
160 match 92 { 160 match 92 {
161 x <|>if x > 10 => false, 161 x $0if x > 10 => false,
162 _ => true 162 _ => true
163 } 163 }
164} 164}
@@ -174,7 +174,7 @@ fn main() {
174 r#" 174 r#"
175fn main() { 175fn main() {
176 match 92 { 176 match 92 {
177 x <|>if x > 10 => false, 177 x $0if x > 10 => false,
178 _ => true 178 _ => true
179 } 179 }
180} 180}
@@ -199,7 +199,7 @@ fn main() {
199 r#" 199 r#"
200fn main() { 200fn main() {
201 match 92 { 201 match 92 {
202 <|>x @ 4 | x @ 5 if x > 5 => true, 202 $0x @ 4 | x @ 5 if x > 5 => true,
203 _ => false 203 _ => false
204 } 204 }
205} 205}
@@ -224,7 +224,7 @@ fn main() {
224 r#" 224 r#"
225fn main() { 225fn main() {
226 match 92 { 226 match 92 {
227 x => if x > 10 { <|>false }, 227 x => if x > 10 { $0false },
228 _ => true 228 _ => true
229 } 229 }
230} 230}
@@ -248,7 +248,7 @@ fn main() {
248fn main() { 248fn main() {
249 match 92 { 249 match 92 {
250 x => { 250 x => {
251 <|>if x > 10 { 251 $0if x > 10 {
252 false 252 false
253 } 253 }
254 }, 254 },
@@ -274,7 +274,7 @@ fn main() {
274 r#" 274 r#"
275fn main() { 275fn main() {
276 match 92 { 276 match 92 {
277 x => if let 62 = x { <|>false }, 277 x => if let 62 = x { $0false },
278 _ => true 278 _ => true
279 } 279 }
280} 280}
@@ -289,7 +289,7 @@ fn main() {
289 r#" 289 r#"
290fn main() { 290fn main() {
291 match 92 { 291 match 92 {
292 x => if x > 10 { <|> }, 292 x => if x > 10 { $0 },
293 _ => true 293 _ => true
294 } 294 }
295} 295}
@@ -313,7 +313,7 @@ fn main() {
313fn main() { 313fn main() {
314 match 92 { 314 match 92 {
315 x => if x > 10 { 315 x => if x > 10 {
316 92;<|> 316 92;$0
317 false 317 false
318 }, 318 },
319 _ => true 319 _ => true
@@ -343,7 +343,7 @@ fn main() {
343 match 92 { 343 match 92 {
344 x => { 344 x => {
345 if x > 10 { 345 if x > 10 {
346 92;<|> 346 92;$0
347 false 347 false
348 } 348 }
349 } 349 }
diff --git a/crates/assists/src/handlers/extract_module_to_file.rs b/crates/assists/src/handlers/move_module_to_file.rs
index 50bf67ef7..9d8579f47 100644
--- a/crates/assists/src/handlers/extract_module_to_file.rs
+++ b/crates/assists/src/handlers/move_module_to_file.rs
@@ -2,17 +2,18 @@ use ast::edit::IndentLevel;
2use ide_db::base_db::AnchoredPathBuf; 2use ide_db::base_db::AnchoredPathBuf;
3use syntax::{ 3use syntax::{
4 ast::{self, edit::AstNodeEdit, NameOwner}, 4 ast::{self, edit::AstNodeEdit, NameOwner},
5 AstNode, 5 AstNode, TextRange,
6}; 6};
7use test_utils::mark;
7 8
8use crate::{AssistContext, AssistId, AssistKind, Assists}; 9use crate::{AssistContext, AssistId, AssistKind, Assists};
9 10
10// Assist: extract_module_to_file 11// Assist: move_module_to_file
11// 12//
12// This assist extract module to file. 13// Moves inline module's contents to a separate file.
13// 14//
14// ``` 15// ```
15// mod foo {<|> 16// mod $0foo {
16// fn t() {} 17// fn t() {}
17// } 18// }
18// ``` 19// ```
@@ -20,19 +21,24 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
20// ``` 21// ```
21// mod foo; 22// mod foo;
22// ``` 23// ```
23pub(crate) fn extract_module_to_file(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 24pub(crate) fn move_module_to_file(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
24 let module_ast = ctx.find_node_at_offset::<ast::Module>()?; 25 let module_ast = ctx.find_node_at_offset::<ast::Module>()?;
26 let module_items = module_ast.item_list()?;
27
28 let l_curly_offset = module_items.syntax().text_range().start();
29 if l_curly_offset <= ctx.offset() {
30 mark::hit!(available_before_curly);
31 return None;
32 }
33 let target = TextRange::new(module_ast.syntax().text_range().start(), l_curly_offset);
34
25 let module_name = module_ast.name()?; 35 let module_name = module_ast.name()?;
26 36
27 let module_def = ctx.sema.to_def(&module_ast)?; 37 let module_def = ctx.sema.to_def(&module_ast)?;
28 let parent_module = module_def.parent(ctx.db())?; 38 let parent_module = module_def.parent(ctx.db())?;
29 39
30 let module_items = module_ast.item_list()?;
31 let target = module_ast.syntax().text_range();
32 let anchor_file_id = ctx.frange.file_id;
33
34 acc.add( 40 acc.add(
35 AssistId("extract_module_to_file", AssistKind::RefactorExtract), 41 AssistId("move_module_to_file", AssistKind::RefactorExtract),
36 "Extract module to file", 42 "Extract module to file",
37 target, 43 target,
38 |builder| { 44 |builder| {
@@ -53,9 +59,9 @@ pub(crate) fn extract_module_to_file(acc: &mut Assists, ctx: &AssistContext) ->
53 items 59 items
54 }; 60 };
55 61
56 builder.replace(target, format!("mod {};", module_name)); 62 builder.replace(module_ast.syntax().text_range(), format!("mod {};", module_name));
57 63
58 let dst = AnchoredPathBuf { anchor: anchor_file_id, path }; 64 let dst = AnchoredPathBuf { anchor: ctx.frange.file_id, path };
59 builder.create_file(dst, contents); 65 builder.create_file(dst, contents);
60 }, 66 },
61 ) 67 )
@@ -63,16 +69,16 @@ pub(crate) fn extract_module_to_file(acc: &mut Assists, ctx: &AssistContext) ->
63 69
64#[cfg(test)] 70#[cfg(test)]
65mod tests { 71mod tests {
66 use crate::tests::check_assist; 72 use crate::tests::{check_assist, check_assist_not_applicable};
67 73
68 use super::*; 74 use super::*;
69 75
70 #[test] 76 #[test]
71 fn extract_from_root() { 77 fn extract_from_root() {
72 check_assist( 78 check_assist(
73 extract_module_to_file, 79 move_module_to_file,
74 r#" 80 r#"
75mod tests {<|> 81mod $0tests {
76 #[test] fn t() {} 82 #[test] fn t() {}
77} 83}
78"#, 84"#,
@@ -88,12 +94,12 @@ mod tests;
88 #[test] 94 #[test]
89 fn extract_from_submodule() { 95 fn extract_from_submodule() {
90 check_assist( 96 check_assist(
91 extract_module_to_file, 97 move_module_to_file,
92 r#" 98 r#"
93//- /main.rs 99//- /main.rs
94mod submod; 100mod submod;
95//- /submod.rs 101//- /submod.rs
96mod inner<|> { 102$0mod inner {
97 fn f() {} 103 fn f() {}
98} 104}
99fn g() {} 105fn g() {}
@@ -111,12 +117,12 @@ fn f() {}
111 #[test] 117 #[test]
112 fn extract_from_mod_rs() { 118 fn extract_from_mod_rs() {
113 check_assist( 119 check_assist(
114 extract_module_to_file, 120 move_module_to_file,
115 r#" 121 r#"
116//- /main.rs 122//- /main.rs
117mod submodule; 123mod submodule;
118//- /submodule/mod.rs 124//- /submodule/mod.rs
119mod inner<|> { 125mod inner$0 {
120 fn f() {} 126 fn f() {}
121} 127}
122fn g() {} 128fn g() {}
@@ -130,4 +136,10 @@ fn f() {}
130"#, 136"#,
131 ); 137 );
132 } 138 }
139
140 #[test]
141 fn available_before_curly() {
142 mark::check!(available_before_curly);
143 check_assist_not_applicable(move_module_to_file, r#"mod m { $0 }"#);
144 }
133} 145}
diff --git a/crates/assists/src/handlers/pull_assignment_up.rs b/crates/assists/src/handlers/pull_assignment_up.rs
new file mode 100644
index 000000000..13e1cb754
--- /dev/null
+++ b/crates/assists/src/handlers/pull_assignment_up.rs
@@ -0,0 +1,400 @@
1use syntax::{
2 ast::{self, edit::AstNodeEdit, make},
3 AstNode,
4};
5use test_utils::mark;
6
7use crate::{
8 assist_context::{AssistContext, Assists},
9 AssistId, AssistKind,
10};
11
12// Assist: pull_assignment_up
13//
14// Extracts variable assignment to outside an if or match statement.
15//
16// ```
17// fn main() {
18// let mut foo = 6;
19//
20// if true {
21// $0foo = 5;
22// } else {
23// foo = 4;
24// }
25// }
26// ```
27// ->
28// ```
29// fn main() {
30// let mut foo = 6;
31//
32// foo = if true {
33// 5
34// } else {
35// 4
36// };
37// }
38// ```
39pub(crate) fn pull_assignment_up(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
40 let assign_expr = ctx.find_node_at_offset::<ast::BinExpr>()?;
41 let name_expr = if assign_expr.op_kind()? == ast::BinOp::Assignment {
42 assign_expr.lhs()?
43 } else {
44 return None;
45 };
46
47 let (old_stmt, new_stmt) = if let Some(if_expr) = ctx.find_node_at_offset::<ast::IfExpr>() {
48 (
49 ast::Expr::cast(if_expr.syntax().to_owned())?,
50 exprify_if(&if_expr, &ctx.sema, &name_expr)?.indent(if_expr.indent_level()),
51 )
52 } else if let Some(match_expr) = ctx.find_node_at_offset::<ast::MatchExpr>() {
53 (
54 ast::Expr::cast(match_expr.syntax().to_owned())?,
55 exprify_match(&match_expr, &ctx.sema, &name_expr)?,
56 )
57 } else {
58 return None;
59 };
60
61 let expr_stmt = make::expr_stmt(new_stmt);
62
63 acc.add(
64 AssistId("pull_assignment_up", AssistKind::RefactorExtract),
65 "Pull assignment up",
66 old_stmt.syntax().text_range(),
67 move |edit| {
68 edit.replace(old_stmt.syntax().text_range(), format!("{} = {};", name_expr, expr_stmt));
69 },
70 )
71}
72
73fn exprify_match(
74 match_expr: &ast::MatchExpr,
75 sema: &hir::Semantics<ide_db::RootDatabase>,
76 name: &ast::Expr,
77) -> Option<ast::Expr> {
78 let new_arm_list = match_expr
79 .match_arm_list()?
80 .arms()
81 .map(|arm| {
82 if let ast::Expr::BlockExpr(block) = arm.expr()? {
83 let new_block = exprify_block(&block, sema, name)?.indent(block.indent_level());
84 Some(arm.replace_descendant(block, new_block))
85 } else {
86 None
87 }
88 })
89 .collect::<Option<Vec<_>>>()?;
90 let new_arm_list = match_expr
91 .match_arm_list()?
92 .replace_descendants(match_expr.match_arm_list()?.arms().zip(new_arm_list));
93 Some(make::expr_match(match_expr.expr()?, new_arm_list))
94}
95
96fn exprify_if(
97 statement: &ast::IfExpr,
98 sema: &hir::Semantics<ide_db::RootDatabase>,
99 name: &ast::Expr,
100) -> Option<ast::Expr> {
101 let then_branch = exprify_block(&statement.then_branch()?, sema, name)?;
102 let else_branch = match statement.else_branch()? {
103 ast::ElseBranch::Block(ref block) => {
104 ast::ElseBranch::Block(exprify_block(block, sema, name)?)
105 }
106 ast::ElseBranch::IfExpr(expr) => {
107 mark::hit!(test_pull_assignment_up_chained_if);
108 ast::ElseBranch::IfExpr(ast::IfExpr::cast(
109 exprify_if(&expr, sema, name)?.syntax().to_owned(),
110 )?)
111 }
112 };
113 Some(make::expr_if(statement.condition()?, then_branch, Some(else_branch)))
114}
115
116fn exprify_block(
117 block: &ast::BlockExpr,
118 sema: &hir::Semantics<ide_db::RootDatabase>,
119 name: &ast::Expr,
120) -> Option<ast::BlockExpr> {
121 if block.tail_expr().is_some() {
122 return None;
123 }
124
125 let mut stmts: Vec<_> = block.statements().collect();
126 let stmt = stmts.pop()?;
127
128 if let ast::Stmt::ExprStmt(stmt) = stmt {
129 if let ast::Expr::BinExpr(expr) = stmt.expr()? {
130 if expr.op_kind()? == ast::BinOp::Assignment && is_equivalent(sema, &expr.lhs()?, name)
131 {
132 // The last statement in the block is an assignment to the name we want
133 return Some(make::block_expr(stmts, Some(expr.rhs()?)));
134 }
135 }
136 }
137 None
138}
139
140fn is_equivalent(
141 sema: &hir::Semantics<ide_db::RootDatabase>,
142 expr0: &ast::Expr,
143 expr1: &ast::Expr,
144) -> bool {
145 match (expr0, expr1) {
146 (ast::Expr::FieldExpr(field_expr0), ast::Expr::FieldExpr(field_expr1)) => {
147 mark::hit!(test_pull_assignment_up_field_assignment);
148 sema.resolve_field(field_expr0) == sema.resolve_field(field_expr1)
149 }
150 (ast::Expr::PathExpr(path0), ast::Expr::PathExpr(path1)) => {
151 let path0 = path0.path();
152 let path1 = path1.path();
153 if let (Some(path0), Some(path1)) = (path0, path1) {
154 sema.resolve_path(&path0) == sema.resolve_path(&path1)
155 } else {
156 false
157 }
158 }
159 _ => false,
160 }
161}
162
163#[cfg(test)]
164mod tests {
165 use super::*;
166
167 use crate::tests::{check_assist, check_assist_not_applicable};
168
169 #[test]
170 fn test_pull_assignment_up_if() {
171 check_assist(
172 pull_assignment_up,
173 r#"
174fn foo() {
175 let mut a = 1;
176
177 if true {
178 $0a = 2;
179 } else {
180 a = 3;
181 }
182}"#,
183 r#"
184fn foo() {
185 let mut a = 1;
186
187 a = if true {
188 2
189 } else {
190 3
191 };
192}"#,
193 );
194 }
195
196 #[test]
197 fn test_pull_assignment_up_match() {
198 check_assist(
199 pull_assignment_up,
200 r#"
201fn foo() {
202 let mut a = 1;
203
204 match 1 {
205 1 => {
206 $0a = 2;
207 },
208 2 => {
209 a = 3;
210 },
211 3 => {
212 a = 4;
213 }
214 }
215}"#,
216 r#"
217fn foo() {
218 let mut a = 1;
219
220 a = match 1 {
221 1 => {
222 2
223 },
224 2 => {
225 3
226 },
227 3 => {
228 4
229 }
230 };
231}"#,
232 );
233 }
234
235 #[test]
236 fn test_pull_assignment_up_not_last_not_applicable() {
237 check_assist_not_applicable(
238 pull_assignment_up,
239 r#"
240fn foo() {
241 let mut a = 1;
242
243 if true {
244 $0a = 2;
245 b = a;
246 } else {
247 a = 3;
248 }
249}"#,
250 )
251 }
252
253 #[test]
254 fn test_pull_assignment_up_chained_if() {
255 mark::check!(test_pull_assignment_up_chained_if);
256 check_assist(
257 pull_assignment_up,
258 r#"
259fn foo() {
260 let mut a = 1;
261
262 if true {
263 $0a = 2;
264 } else if false {
265 a = 3;
266 } else {
267 a = 4;
268 }
269}"#,
270 r#"
271fn foo() {
272 let mut a = 1;
273
274 a = if true {
275 2
276 } else if false {
277 3
278 } else {
279 4
280 };
281}"#,
282 );
283 }
284
285 #[test]
286 fn test_pull_assignment_up_retains_stmts() {
287 check_assist(
288 pull_assignment_up,
289 r#"
290fn foo() {
291 let mut a = 1;
292
293 if true {
294 let b = 2;
295 $0a = 2;
296 } else {
297 let b = 3;
298 a = 3;
299 }
300}"#,
301 r#"
302fn foo() {
303 let mut a = 1;
304
305 a = if true {
306 let b = 2;
307 2
308 } else {
309 let b = 3;
310 3
311 };
312}"#,
313 )
314 }
315
316 #[test]
317 fn pull_assignment_up_let_stmt_not_applicable() {
318 check_assist_not_applicable(
319 pull_assignment_up,
320 r#"
321fn foo() {
322 let mut a = 1;
323
324 let b = if true {
325 $0a = 2
326 } else {
327 a = 3
328 };
329}"#,
330 )
331 }
332
333 #[test]
334 fn pull_assignment_up_if_missing_assigment_not_applicable() {
335 check_assist_not_applicable(
336 pull_assignment_up,
337 r#"
338fn foo() {
339 let mut a = 1;
340
341 if true {
342 $0a = 2;
343 } else {}
344}"#,
345 )
346 }
347
348 #[test]
349 fn pull_assignment_up_match_missing_assigment_not_applicable() {
350 check_assist_not_applicable(
351 pull_assignment_up,
352 r#"
353fn foo() {
354 let mut a = 1;
355
356 match 1 {
357 1 => {
358 $0a = 2;
359 },
360 2 => {
361 a = 3;
362 },
363 3 => {},
364 }
365}"#,
366 )
367 }
368
369 #[test]
370 fn test_pull_assignment_up_field_assignment() {
371 mark::check!(test_pull_assignment_up_field_assignment);
372 check_assist(
373 pull_assignment_up,
374 r#"
375struct A(usize);
376
377fn foo() {
378 let mut a = A(1);
379
380 if true {
381 $0a.0 = 2;
382 } else {
383 a.0 = 3;
384 }
385}"#,
386 r#"
387struct A(usize);
388
389fn foo() {
390 let mut a = A(1);
391
392 a.0 = if true {
393 2
394 } else {
395 3
396 };
397}"#,
398 )
399 }
400}
diff --git a/crates/assists/src/handlers/qualify_path.rs b/crates/assists/src/handlers/qualify_path.rs
index 98cb09214..f7fbf37f4 100644
--- a/crates/assists/src/handlers/qualify_path.rs
+++ b/crates/assists/src/handlers/qualify_path.rs
@@ -22,7 +22,7 @@ use crate::{
22// 22//
23// ``` 23// ```
24// fn main() { 24// fn main() {
25// let map = HashMap<|>::new(); 25// let map = HashMap$0::new();
26// } 26// }
27// # pub mod std { pub mod collections { pub struct HashMap { } } } 27// # pub mod std { pub mod collections { pub struct HashMap { } } }
28// ``` 28// ```
@@ -221,7 +221,7 @@ mod tests {
221 221
222 use std::fmt; 222 use std::fmt;
223 223
224 <|>Formatter 224 $0Formatter
225 ", 225 ",
226 r" 226 r"
227 mod std { 227 mod std {
@@ -242,7 +242,7 @@ mod tests {
242 check_assist( 242 check_assist(
243 qualify_path, 243 qualify_path,
244 r" 244 r"
245 <|>PubStruct 245 $0PubStruct
246 246
247 pub mod PubMod { 247 pub mod PubMod {
248 pub struct PubStruct; 248 pub struct PubStruct;
@@ -266,7 +266,7 @@ mod tests {
266 macro_rules! foo { 266 macro_rules! foo {
267 ($i:ident) => { fn foo(a: $i) {} } 267 ($i:ident) => { fn foo(a: $i) {} }
268 } 268 }
269 foo!(Pub<|>Struct); 269 foo!(Pub$0Struct);
270 270
271 pub mod PubMod { 271 pub mod PubMod {
272 pub struct PubStruct; 272 pub struct PubStruct;
@@ -290,7 +290,7 @@ mod tests {
290 check_assist( 290 check_assist(
291 qualify_path, 291 qualify_path,
292 r" 292 r"
293 PubSt<|>ruct 293 PubSt$0ruct
294 294
295 pub mod PubMod1 { 295 pub mod PubMod1 {
296 pub struct PubStruct; 296 pub struct PubStruct;
@@ -325,7 +325,7 @@ mod tests {
325 r" 325 r"
326 use PubMod::PubStruct; 326 use PubMod::PubStruct;
327 327
328 PubStruct<|> 328 PubStruct$0
329 329
330 pub mod PubMod { 330 pub mod PubMod {
331 pub struct PubStruct; 331 pub struct PubStruct;
@@ -339,7 +339,7 @@ mod tests {
339 check_assist_not_applicable( 339 check_assist_not_applicable(
340 qualify_path, 340 qualify_path,
341 r" 341 r"
342 PrivateStruct<|> 342 PrivateStruct$0
343 343
344 pub mod PubMod { 344 pub mod PubMod {
345 struct PrivateStruct; 345 struct PrivateStruct;
@@ -353,7 +353,7 @@ mod tests {
353 check_assist_not_applicable( 353 check_assist_not_applicable(
354 qualify_path, 354 qualify_path,
355 " 355 "
356 PubStruct<|>", 356 PubStruct$0",
357 ); 357 );
358 } 358 }
359 359
@@ -362,7 +362,7 @@ mod tests {
362 check_assist_not_applicable( 362 check_assist_not_applicable(
363 qualify_path, 363 qualify_path,
364 r" 364 r"
365 use PubStruct<|>; 365 use PubStruct$0;
366 366
367 pub mod PubMod { 367 pub mod PubMod {
368 pub struct PubStruct; 368 pub struct PubStruct;
@@ -375,7 +375,7 @@ mod tests {
375 check_assist( 375 check_assist(
376 qualify_path, 376 qualify_path,
377 r" 377 r"
378 test_function<|> 378 test_function$0
379 379
380 pub mod PubMod { 380 pub mod PubMod {
381 pub fn test_function() {}; 381 pub fn test_function() {};
@@ -404,7 +404,7 @@ macro_rules! foo {
404 404
405//- /main.rs crate:main deps:crate_with_macro 405//- /main.rs crate:main deps:crate_with_macro
406fn main() { 406fn main() {
407 foo<|> 407 foo$0
408} 408}
409", 409",
410 r" 410 r"
@@ -421,7 +421,7 @@ fn main() {
421 qualify_path, 421 qualify_path,
422 r" 422 r"
423 struct AssistInfo { 423 struct AssistInfo {
424 group_label: Option<<|>GroupLabel>, 424 group_label: Option<$0GroupLabel>,
425 } 425 }
426 426
427 mod m { pub struct GroupLabel; } 427 mod m { pub struct GroupLabel; }
@@ -445,7 +445,7 @@ fn main() {
445 445
446 use mod1::mod2; 446 use mod1::mod2;
447 fn main() { 447 fn main() {
448 mod2::mod3::TestStruct<|> 448 mod2::mod3::TestStruct$0
449 } 449 }
450 ", 450 ",
451 ); 451 );
@@ -462,7 +462,7 @@ fn main() {
462 462
463 use test_mod::test_function; 463 use test_mod::test_function;
464 fn main() { 464 fn main() {
465 test_function<|> 465 test_function$0
466 } 466 }
467 ", 467 ",
468 ); 468 );
@@ -481,7 +481,7 @@ fn main() {
481 } 481 }
482 482
483 fn main() { 483 fn main() {
484 TestStruct::test_function<|> 484 TestStruct::test_function$0
485 } 485 }
486 ", 486 ",
487 r" 487 r"
@@ -513,7 +513,7 @@ fn main() {
513 } 513 }
514 514
515 fn main() { 515 fn main() {
516 TestStruct::TEST_CONST<|> 516 TestStruct::TEST_CONST$0
517 } 517 }
518 ", 518 ",
519 r" 519 r"
@@ -547,7 +547,7 @@ fn main() {
547 } 547 }
548 548
549 fn main() { 549 fn main() {
550 test_mod::TestStruct::test_function<|> 550 test_mod::TestStruct::test_function$0
551 } 551 }
552 ", 552 ",
553 r" 553 r"
@@ -594,7 +594,7 @@ fn main() {
594 594
595 use test_mod::TestTrait2; 595 use test_mod::TestTrait2;
596 fn main() { 596 fn main() {
597 test_mod::TestEnum::test_function<|>; 597 test_mod::TestEnum::test_function$0;
598 } 598 }
599 ", 599 ",
600 ) 600 )
@@ -617,7 +617,7 @@ fn main() {
617 } 617 }
618 618
619 fn main() { 619 fn main() {
620 test_mod::TestStruct::TEST_CONST<|> 620 test_mod::TestStruct::TEST_CONST$0
621 } 621 }
622 ", 622 ",
623 r" 623 r"
@@ -664,7 +664,7 @@ fn main() {
664 664
665 use test_mod::TestTrait2; 665 use test_mod::TestTrait2;
666 fn main() { 666 fn main() {
667 test_mod::TestEnum::TEST_CONST<|>; 667 test_mod::TestEnum::TEST_CONST$0;
668 } 668 }
669 ", 669 ",
670 ) 670 )
@@ -688,7 +688,7 @@ fn main() {
688 688
689 fn main() { 689 fn main() {
690 let test_struct = test_mod::TestStruct {}; 690 let test_struct = test_mod::TestStruct {};
691 test_struct.test_meth<|>od() 691 test_struct.test_meth$0od()
692 } 692 }
693 ", 693 ",
694 r" 694 r"
@@ -727,7 +727,7 @@ fn main() {
727 727
728 fn main() { 728 fn main() {
729 let test_struct = test_mod::TestStruct {}; 729 let test_struct = test_mod::TestStruct {};
730 test_struct.test_meth<|>od(42) 730 test_struct.test_meth$0od(42)
731 } 731 }
732 ", 732 ",
733 r" 733 r"
@@ -766,7 +766,7 @@ fn main() {
766 766
767 fn main() { 767 fn main() {
768 let test_struct = test_mod::TestStruct {}; 768 let test_struct = test_mod::TestStruct {};
769 test_struct.test_meth<|>od() 769 test_struct.test_meth$0od()
770 } 770 }
771 ", 771 ",
772 r" 772 r"
@@ -796,7 +796,7 @@ fn main() {
796 //- /main.rs crate:main deps:dep 796 //- /main.rs crate:main deps:dep
797 fn main() { 797 fn main() {
798 let test_struct = dep::test_mod::TestStruct {}; 798 let test_struct = dep::test_mod::TestStruct {};
799 test_struct.test_meth<|>od() 799 test_struct.test_meth$0od()
800 } 800 }
801 //- /dep.rs crate:dep 801 //- /dep.rs crate:dep
802 pub mod test_mod { 802 pub mod test_mod {
@@ -825,7 +825,7 @@ fn main() {
825 r" 825 r"
826 //- /main.rs crate:main deps:dep 826 //- /main.rs crate:main deps:dep
827 fn main() { 827 fn main() {
828 dep::test_mod::TestStruct::test_func<|>tion 828 dep::test_mod::TestStruct::test_func$0tion
829 } 829 }
830 //- /dep.rs crate:dep 830 //- /dep.rs crate:dep
831 pub mod test_mod { 831 pub mod test_mod {
@@ -853,7 +853,7 @@ fn main() {
853 r" 853 r"
854 //- /main.rs crate:main deps:dep 854 //- /main.rs crate:main deps:dep
855 fn main() { 855 fn main() {
856 dep::test_mod::TestStruct::CONST<|> 856 dep::test_mod::TestStruct::CONST$0
857 } 857 }
858 //- /dep.rs crate:dep 858 //- /dep.rs crate:dep
859 pub mod test_mod { 859 pub mod test_mod {
@@ -882,7 +882,7 @@ fn main() {
882 //- /main.rs crate:main deps:dep 882 //- /main.rs crate:main deps:dep
883 fn main() { 883 fn main() {
884 let test_struct = dep::test_mod::TestStruct {}; 884 let test_struct = dep::test_mod::TestStruct {};
885 test_struct.test_func<|>tion() 885 test_struct.test_func$0tion()
886 } 886 }
887 //- /dep.rs crate:dep 887 //- /dep.rs crate:dep
888 pub mod test_mod { 888 pub mod test_mod {
@@ -906,7 +906,7 @@ fn main() {
906 //- /main.rs crate:main deps:dep 906 //- /main.rs crate:main deps:dep
907 fn main() { 907 fn main() {
908 let test_struct = dep::test_mod::TestStruct {}; 908 let test_struct = dep::test_mod::TestStruct {};
909 test_struct.test_meth<|>od() 909 test_struct.test_meth$0od()
910 } 910 }
911 //- /dep.rs crate:dep 911 //- /dep.rs crate:dep
912 pub mod test_mod { 912 pub mod test_mod {
@@ -949,7 +949,7 @@ fn main() {
949 use test_mod::TestTrait2; 949 use test_mod::TestTrait2;
950 fn main() { 950 fn main() {
951 let one = test_mod::TestEnum::One; 951 let one = test_mod::TestEnum::One;
952 one.test<|>_method(); 952 one.test$0_method();
953 } 953 }
954 ", 954 ",
955 ) 955 )
@@ -965,7 +965,7 @@ pub struct Struct;
965 965
966//- /main.rs crate:main deps:dep 966//- /main.rs crate:main deps:dep
967fn main() { 967fn main() {
968 Struct<|> 968 Struct$0
969} 969}
970", 970",
971 r" 971 r"
@@ -992,7 +992,7 @@ pub fn panic_fmt() {}
992//- /main.rs crate:main deps:dep 992//- /main.rs crate:main deps:dep
993struct S; 993struct S;
994 994
995impl f<|>mt::Display for S {} 995impl f$0mt::Display for S {}
996", 996",
997 r" 997 r"
998struct S; 998struct S;
@@ -1019,7 +1019,7 @@ mac!();
1019 1019
1020//- /main.rs crate:main deps:dep 1020//- /main.rs crate:main deps:dep
1021fn main() { 1021fn main() {
1022 Cheese<|>; 1022 Cheese$0;
1023} 1023}
1024", 1024",
1025 r" 1025 r"
@@ -1042,7 +1042,7 @@ pub struct fmt;
1042 1042
1043//- /main.rs crate:main deps:dep 1043//- /main.rs crate:main deps:dep
1044fn main() { 1044fn main() {
1045 FMT<|>; 1045 FMT$0;
1046} 1046}
1047", 1047",
1048 r" 1048 r"
@@ -1062,7 +1062,7 @@ fn main() {
1062pub mod generic { pub struct Thing<'a, T>(&'a T); } 1062pub mod generic { pub struct Thing<'a, T>(&'a T); }
1063 1063
1064//- /main.rs crate:main deps:dep 1064//- /main.rs crate:main deps:dep
1065fn foo() -> Thin<|>g<'static, ()> {} 1065fn foo() -> Thin$0g<'static, ()> {}
1066 1066
1067fn main() {} 1067fn main() {}
1068", 1068",
@@ -1083,7 +1083,7 @@ fn main() {}
1083pub mod generic { pub struct Thing<'a, T>(&'a T); } 1083pub mod generic { pub struct Thing<'a, T>(&'a T); }
1084 1084
1085//- /main.rs crate:main deps:dep 1085//- /main.rs crate:main deps:dep
1086fn foo() -> Thin<|>g::<'static, ()> {} 1086fn foo() -> Thin$0g::<'static, ()> {}
1087 1087
1088fn main() {} 1088fn main() {}
1089", 1089",
@@ -1108,7 +1108,7 @@ fn main() {}
1108 } 1108 }
1109 1109
1110 fn main() { 1110 fn main() {
1111 TestStruct::<()>::TEST_CONST<|> 1111 TestStruct::<()>::TEST_CONST$0
1112 } 1112 }
1113 ", 1113 ",
1114 r" 1114 r"
@@ -1142,7 +1142,7 @@ fn main() {}
1142 } 1142 }
1143 1143
1144 fn main() { 1144 fn main() {
1145 test_mod::TestStruct::<()>::TEST_CONST<|> 1145 test_mod::TestStruct::<()>::TEST_CONST$0
1146 } 1146 }
1147 ", 1147 ",
1148 r" 1148 r"
@@ -1180,7 +1180,7 @@ fn main() {}
1180 1180
1181 fn main() { 1181 fn main() {
1182 let test_struct = test_mod::TestStruct {}; 1182 let test_struct = test_mod::TestStruct {};
1183 test_struct.test_meth<|>od::<()>() 1183 test_struct.test_meth$0od::<()>()
1184 } 1184 }
1185 ", 1185 ",
1186 r" 1186 r"
diff --git a/crates/assists/src/handlers/raw_string.rs b/crates/assists/src/handlers/raw_string.rs
index 4c759cc25..be963f162 100644
--- a/crates/assists/src/handlers/raw_string.rs
+++ b/crates/assists/src/handlers/raw_string.rs
@@ -11,7 +11,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
11// 11//
12// ``` 12// ```
13// fn main() { 13// fn main() {
14// "Hello,<|> World!"; 14// "Hello,$0 World!";
15// } 15// }
16// ``` 16// ```
17// -> 17// ->
@@ -53,7 +53,7 @@ pub(crate) fn make_raw_string(acc: &mut Assists, ctx: &AssistContext) -> Option<
53// 53//
54// ``` 54// ```
55// fn main() { 55// fn main() {
56// r#"Hello,<|> "World!""#; 56// r#"Hello,$0 "World!""#;
57// } 57// }
58// ``` 58// ```
59// -> 59// ->
@@ -95,7 +95,7 @@ pub(crate) fn make_usual_string(acc: &mut Assists, ctx: &AssistContext) -> Optio
95// 95//
96// ``` 96// ```
97// fn main() { 97// fn main() {
98// r#"Hello,<|> World!"#; 98// r#"Hello,$0 World!"#;
99// } 99// }
100// ``` 100// ```
101// -> 101// ->
@@ -123,7 +123,7 @@ pub(crate) fn add_hash(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
123// 123//
124// ``` 124// ```
125// fn main() { 125// fn main() {
126// r#"Hello,<|> World!"#; 126// r#"Hello,$0 World!"#;
127// } 127// }
128// ``` 128// ```
129// -> 129// ->
@@ -194,7 +194,7 @@ mod tests {
194 make_raw_string, 194 make_raw_string,
195 r#" 195 r#"
196 fn f() { 196 fn f() {
197 let s = <|>"random\nstring"; 197 let s = $0"random\nstring";
198 } 198 }
199 "#, 199 "#,
200 r#""random\nstring""#, 200 r#""random\nstring""#,
@@ -207,7 +207,7 @@ mod tests {
207 make_raw_string, 207 make_raw_string,
208 r#" 208 r#"
209fn f() { 209fn f() {
210 let s = <|>"random\nstring"; 210 let s = $0"random\nstring";
211} 211}
212"#, 212"#,
213 r##" 213 r##"
@@ -225,7 +225,7 @@ string"#;
225 make_raw_string, 225 make_raw_string,
226 r#" 226 r#"
227 fn f() { 227 fn f() {
228 format!(<|>"x = {}", 92) 228 format!($0"x = {}", 92)
229 } 229 }
230 "#, 230 "#,
231 r##" 231 r##"
@@ -242,7 +242,7 @@ string"#;
242 make_raw_string, 242 make_raw_string,
243 r###" 243 r###"
244fn f() { 244fn f() {
245 let s = <|>"#random##\nstring"; 245 let s = $0"#random##\nstring";
246} 246}
247"###, 247"###,
248 r####" 248 r####"
@@ -260,7 +260,7 @@ string"#;
260 make_raw_string, 260 make_raw_string,
261 r###" 261 r###"
262fn f() { 262fn f() {
263 let s = <|>"#random\"##\nstring"; 263 let s = $0"#random\"##\nstring";
264} 264}
265"###, 265"###,
266 r####" 266 r####"
@@ -278,7 +278,7 @@ string"###;
278 make_raw_string, 278 make_raw_string,
279 r#" 279 r#"
280 fn f() { 280 fn f() {
281 let s = <|>"random string"; 281 let s = $0"random string";
282 } 282 }
283 "#, 283 "#,
284 r##" 284 r##"
@@ -295,7 +295,7 @@ string"###;
295 make_raw_string, 295 make_raw_string,
296 r#" 296 r#"
297 fn f() { 297 fn f() {
298 let s = "foo<|> 298 let s = "foo$0
299 } 299 }
300 "#, 300 "#,
301 ) 301 )
@@ -307,7 +307,7 @@ string"###;
307 make_usual_string, 307 make_usual_string,
308 r#" 308 r#"
309 fn main() { 309 fn main() {
310 let s = r#"bar<|> 310 let s = r#"bar$0
311 } 311 }
312 "#, 312 "#,
313 ) 313 )
@@ -319,7 +319,7 @@ string"###;
319 add_hash, 319 add_hash,
320 r#" 320 r#"
321 fn f() { 321 fn f() {
322 let s = <|>r"random string"; 322 let s = $0r"random string";
323 } 323 }
324 "#, 324 "#,
325 r#"r"random string""#, 325 r#"r"random string""#,
@@ -332,7 +332,7 @@ string"###;
332 add_hash, 332 add_hash,
333 r#" 333 r#"
334 fn f() { 334 fn f() {
335 let s = <|>r"random string"; 335 let s = $0r"random string";
336 } 336 }
337 "#, 337 "#,
338 r##" 338 r##"
@@ -349,7 +349,7 @@ string"###;
349 add_hash, 349 add_hash,
350 r##" 350 r##"
351 fn f() { 351 fn f() {
352 let s = <|>r#"random"string"#; 352 let s = $0r#"random"string"#;
353 } 353 }
354 "##, 354 "##,
355 r###" 355 r###"
@@ -366,7 +366,7 @@ string"###;
366 add_hash, 366 add_hash,
367 r#" 367 r#"
368 fn f() { 368 fn f() {
369 let s = <|>"random string"; 369 let s = $0"random string";
370 } 370 }
371 "#, 371 "#,
372 ); 372 );
@@ -378,7 +378,7 @@ string"###;
378 remove_hash, 378 remove_hash,
379 r##" 379 r##"
380 fn f() { 380 fn f() {
381 let s = <|>r#"random string"#; 381 let s = $0r#"random string"#;
382 } 382 }
383 "##, 383 "##,
384 r##"r#"random string"#"##, 384 r##"r#"random string"#"##,
@@ -389,7 +389,7 @@ string"###;
389 fn remove_hash_works() { 389 fn remove_hash_works() {
390 check_assist( 390 check_assist(
391 remove_hash, 391 remove_hash,
392 r##"fn f() { let s = <|>r#"random string"#; }"##, 392 r##"fn f() { let s = $0r#"random string"#; }"##,
393 r#"fn f() { let s = r"random string"; }"#, 393 r#"fn f() { let s = r"random string"; }"#,
394 ) 394 )
395 } 395 }
@@ -401,7 +401,7 @@ string"###;
401 remove_hash, 401 remove_hash,
402 r##" 402 r##"
403 fn f() { 403 fn f() {
404 let s = <|>r#"random"str"ing"#; 404 let s = $0r#"random"str"ing"#;
405 } 405 }
406 "##, 406 "##,
407 ) 407 )
@@ -413,7 +413,7 @@ string"###;
413 remove_hash, 413 remove_hash,
414 r###" 414 r###"
415 fn f() { 415 fn f() {
416 let s = <|>r##"random string"##; 416 let s = $0r##"random string"##;
417 } 417 }
418 "###, 418 "###,
419 r##" 419 r##"
@@ -426,12 +426,12 @@ string"###;
426 426
427 #[test] 427 #[test]
428 fn remove_hash_doesnt_work() { 428 fn remove_hash_doesnt_work() {
429 check_assist_not_applicable(remove_hash, r#"fn f() { let s = <|>"random string"; }"#); 429 check_assist_not_applicable(remove_hash, r#"fn f() { let s = $0"random string"; }"#);
430 } 430 }
431 431
432 #[test] 432 #[test]
433 fn remove_hash_no_hash_doesnt_work() { 433 fn remove_hash_no_hash_doesnt_work() {
434 check_assist_not_applicable(remove_hash, r#"fn f() { let s = <|>r"random string"; }"#); 434 check_assist_not_applicable(remove_hash, r#"fn f() { let s = $0r"random string"; }"#);
435 } 435 }
436 436
437 #[test] 437 #[test]
@@ -440,7 +440,7 @@ string"###;
440 make_usual_string, 440 make_usual_string,
441 r##" 441 r##"
442 fn f() { 442 fn f() {
443 let s = <|>r#"random string"#; 443 let s = $0r#"random string"#;
444 } 444 }
445 "##, 445 "##,
446 r##"r#"random string"#"##, 446 r##"r#"random string"#"##,
@@ -453,7 +453,7 @@ string"###;
453 make_usual_string, 453 make_usual_string,
454 r##" 454 r##"
455 fn f() { 455 fn f() {
456 let s = <|>r#"random string"#; 456 let s = $0r#"random string"#;
457 } 457 }
458 "##, 458 "##,
459 r#" 459 r#"
@@ -470,7 +470,7 @@ string"###;
470 make_usual_string, 470 make_usual_string,
471 r##" 471 r##"
472 fn f() { 472 fn f() {
473 let s = <|>r#"random"str"ing"#; 473 let s = $0r#"random"str"ing"#;
474 } 474 }
475 "##, 475 "##,
476 r#" 476 r#"
@@ -487,7 +487,7 @@ string"###;
487 make_usual_string, 487 make_usual_string,
488 r###" 488 r###"
489 fn f() { 489 fn f() {
490 let s = <|>r##"random string"##; 490 let s = $0r##"random string"##;
491 } 491 }
492 "###, 492 "###,
493 r##" 493 r##"
@@ -504,7 +504,7 @@ string"###;
504 make_usual_string, 504 make_usual_string,
505 r#" 505 r#"
506 fn f() { 506 fn f() {
507 let s = <|>"random string"; 507 let s = $0"random string";
508 } 508 }
509 "#, 509 "#,
510 ); 510 );
diff --git a/crates/assists/src/handlers/remove_dbg.rs b/crates/assists/src/handlers/remove_dbg.rs
index eae6367c1..6114091f2 100644
--- a/crates/assists/src/handlers/remove_dbg.rs
+++ b/crates/assists/src/handlers/remove_dbg.rs
@@ -1,6 +1,6 @@
1use syntax::{ 1use syntax::{
2 ast::{self, AstNode}, 2 ast::{self, AstNode},
3 match_ast, SyntaxElement, SyntaxKind, TextRange, TextSize, T, 3 match_ast, SyntaxElement, TextRange, TextSize, T,
4}; 4};
5 5
6use crate::{AssistContext, AssistId, AssistKind, Assists}; 6use crate::{AssistContext, AssistId, AssistKind, Assists};
@@ -11,7 +11,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
11// 11//
12// ``` 12// ```
13// fn main() { 13// fn main() {
14// <|>dbg!(92); 14// $0dbg!(92);
15// } 15// }
16// ``` 16// ```
17// -> 17// ->
@@ -136,14 +136,14 @@ fn needs_parentheses_around_macro_contents(macro_contents: Vec<SyntaxElement>) -
136 symbol_kind => { 136 symbol_kind => {
137 let symbol_not_in_bracket = unpaired_brackets_in_contents.is_empty(); 137 let symbol_not_in_bracket = unpaired_brackets_in_contents.is_empty();
138 if symbol_not_in_bracket 138 if symbol_not_in_bracket
139 && symbol_kind != SyntaxKind::COLON // paths 139 && symbol_kind != T![:] // paths
140 && (symbol_kind != SyntaxKind::DOT // field/method access 140 && (symbol_kind != T![.] // field/method access
141 || macro_contents // range expressions consist of two SyntaxKind::Dot in macro invocations 141 || macro_contents // range expressions consist of two SyntaxKind::Dot in macro invocations
142 .peek() 142 .peek()
143 .map(|element| element.kind() == SyntaxKind::DOT) 143 .map(|element| element.kind() == T![.])
144 .unwrap_or(false)) 144 .unwrap_or(false))
145 && symbol_kind != SyntaxKind::QUESTION // try operator 145 && symbol_kind != T![?] // try operator
146 && (symbol_kind.is_punct() || symbol_kind == SyntaxKind::AS_KW) 146 && (symbol_kind.is_punct() || symbol_kind == T![as])
147 { 147 {
148 return true; 148 return true;
149 } 149 }
@@ -161,19 +161,19 @@ mod tests {
161 161
162 #[test] 162 #[test]
163 fn test_remove_dbg() { 163 fn test_remove_dbg() {
164 check_assist(remove_dbg, "<|>dbg!(1 + 1)", "1 + 1"); 164 check_assist(remove_dbg, "$0dbg!(1 + 1)", "1 + 1");
165 165
166 check_assist(remove_dbg, "dbg!<|>((1 + 1))", "(1 + 1)"); 166 check_assist(remove_dbg, "dbg!$0((1 + 1))", "(1 + 1)");
167 167
168 check_assist(remove_dbg, "dbg!(1 <|>+ 1)", "1 + 1"); 168 check_assist(remove_dbg, "dbg!(1 $0+ 1)", "1 + 1");
169 169
170 check_assist(remove_dbg, "let _ = <|>dbg!(1 + 1)", "let _ = 1 + 1"); 170 check_assist(remove_dbg, "let _ = $0dbg!(1 + 1)", "let _ = 1 + 1");
171 171
172 check_assist( 172 check_assist(
173 remove_dbg, 173 remove_dbg,
174 " 174 "
175fn foo(n: usize) { 175fn foo(n: usize) {
176 if let Some(_) = dbg!(n.<|>checked_sub(4)) { 176 if let Some(_) = dbg!(n.$0checked_sub(4)) {
177 // ... 177 // ...
178 } 178 }
179} 179}
@@ -187,20 +187,20 @@ fn foo(n: usize) {
187", 187",
188 ); 188 );
189 189
190 check_assist(remove_dbg, "<|>dbg!(Foo::foo_test()).bar()", "Foo::foo_test().bar()"); 190 check_assist(remove_dbg, "$0dbg!(Foo::foo_test()).bar()", "Foo::foo_test().bar()");
191 } 191 }
192 192
193 #[test] 193 #[test]
194 fn test_remove_dbg_with_brackets_and_braces() { 194 fn test_remove_dbg_with_brackets_and_braces() {
195 check_assist(remove_dbg, "dbg![<|>1 + 1]", "1 + 1"); 195 check_assist(remove_dbg, "dbg![$01 + 1]", "1 + 1");
196 check_assist(remove_dbg, "dbg!{<|>1 + 1}", "1 + 1"); 196 check_assist(remove_dbg, "dbg!{$01 + 1}", "1 + 1");
197 } 197 }
198 198
199 #[test] 199 #[test]
200 fn test_remove_dbg_not_applicable() { 200 fn test_remove_dbg_not_applicable() {
201 check_assist_not_applicable(remove_dbg, "<|>vec![1, 2, 3]"); 201 check_assist_not_applicable(remove_dbg, "$0vec![1, 2, 3]");
202 check_assist_not_applicable(remove_dbg, "<|>dbg(5, 6, 7)"); 202 check_assist_not_applicable(remove_dbg, "$0dbg(5, 6, 7)");
203 check_assist_not_applicable(remove_dbg, "<|>dbg!(5, 6, 7"); 203 check_assist_not_applicable(remove_dbg, "$0dbg!(5, 6, 7");
204 } 204 }
205 205
206 #[test] 206 #[test]
@@ -209,7 +209,7 @@ fn foo(n: usize) {
209 remove_dbg, 209 remove_dbg,
210 " 210 "
211fn foo(n: usize) { 211fn foo(n: usize) {
212 if let Some(_) = dbg!(n.<|>checked_sub(4)) { 212 if let Some(_) = dbg!(n.$0checked_sub(4)) {
213 // ... 213 // ...
214 } 214 }
215} 215}
@@ -226,7 +226,7 @@ fn foo(n: usize) {
226 // the ast::MacroCall to include the semicolon at the end 226 // the ast::MacroCall to include the semicolon at the end
227 check_assist( 227 check_assist(
228 remove_dbg, 228 remove_dbg,
229 r#"let res = <|>dbg!(1 * 20); // needless comment"#, 229 r#"let res = $0dbg!(1 * 20); // needless comment"#,
230 r#"let res = 1 * 20; // needless comment"#, 230 r#"let res = 1 * 20; // needless comment"#,
231 ); 231 );
232 } 232 }
@@ -238,7 +238,7 @@ fn foo(n: usize) {
238 " 238 "
239fn main() { 239fn main() {
240 let mut a = 1; 240 let mut a = 1;
241 while dbg!<|>(a) < 10000 { 241 while dbg!$0(a) < 10000 {
242 a += 1; 242 a += 1;
243 } 243 }
244} 244}
@@ -258,31 +258,31 @@ fn main() {
258 fn test_remove_dbg_keep_expression() { 258 fn test_remove_dbg_keep_expression() {
259 check_assist( 259 check_assist(
260 remove_dbg, 260 remove_dbg,
261 r#"let res = <|>dbg!(a + b).foo();"#, 261 r#"let res = $0dbg!(a + b).foo();"#,
262 r#"let res = (a + b).foo();"#, 262 r#"let res = (a + b).foo();"#,
263 ); 263 );
264 264
265 check_assist(remove_dbg, r#"let res = <|>dbg!(2 + 2) * 5"#, r#"let res = (2 + 2) * 5"#); 265 check_assist(remove_dbg, r#"let res = $0dbg!(2 + 2) * 5"#, r#"let res = (2 + 2) * 5"#);
266 check_assist(remove_dbg, r#"let res = <|>dbg![2 + 2] * 5"#, r#"let res = (2 + 2) * 5"#); 266 check_assist(remove_dbg, r#"let res = $0dbg![2 + 2] * 5"#, r#"let res = (2 + 2) * 5"#);
267 } 267 }
268 268
269 #[test] 269 #[test]
270 fn test_remove_dbg_method_chaining() { 270 fn test_remove_dbg_method_chaining() {
271 check_assist( 271 check_assist(
272 remove_dbg, 272 remove_dbg,
273 r#"let res = <|>dbg!(foo().bar()).baz();"#, 273 r#"let res = $0dbg!(foo().bar()).baz();"#,
274 r#"let res = foo().bar().baz();"#, 274 r#"let res = foo().bar().baz();"#,
275 ); 275 );
276 check_assist( 276 check_assist(
277 remove_dbg, 277 remove_dbg,
278 r#"let res = <|>dbg!(foo.bar()).baz();"#, 278 r#"let res = $0dbg!(foo.bar()).baz();"#,
279 r#"let res = foo.bar().baz();"#, 279 r#"let res = foo.bar().baz();"#,
280 ); 280 );
281 } 281 }
282 282
283 #[test] 283 #[test]
284 fn test_remove_dbg_field_chaining() { 284 fn test_remove_dbg_field_chaining() {
285 check_assist(remove_dbg, r#"let res = <|>dbg!(foo.bar).baz;"#, r#"let res = foo.bar.baz;"#); 285 check_assist(remove_dbg, r#"let res = $0dbg!(foo.bar).baz;"#, r#"let res = foo.bar.baz;"#);
286 } 286 }
287 287
288 #[test] 288 #[test]
@@ -295,7 +295,7 @@ fn square(x: u32) -> u32 {
295} 295}
296 296
297fn main() { 297fn main() {
298 let x = square(dbg<|>!(5 + 10)); 298 let x = square(dbg$0!(5 + 10));
299 println!("{}", x); 299 println!("{}", x);
300}"#, 300}"#,
301 "dbg!(5 + 10)", 301 "dbg!(5 + 10)",
@@ -309,7 +309,7 @@ fn square(x: u32) -> u32 {
309} 309}
310 310
311fn main() { 311fn main() {
312 let x = square(dbg<|>!(5 + 10)); 312 let x = square(dbg$0!(5 + 10));
313 println!("{}", x); 313 println!("{}", x);
314}"#, 314}"#,
315 r#" 315 r#"
@@ -328,7 +328,7 @@ fn main() {
328 fn test_remove_dbg_try_expr() { 328 fn test_remove_dbg_try_expr() {
329 check_assist( 329 check_assist(
330 remove_dbg, 330 remove_dbg,
331 r#"let res = <|>dbg!(result?).foo();"#, 331 r#"let res = $0dbg!(result?).foo();"#,
332 r#"let res = result?.foo();"#, 332 r#"let res = result?.foo();"#,
333 ); 333 );
334 } 334 }
@@ -337,7 +337,7 @@ fn main() {
337 fn test_remove_dbg_await_expr() { 337 fn test_remove_dbg_await_expr() {
338 check_assist( 338 check_assist(
339 remove_dbg, 339 remove_dbg,
340 r#"let res = <|>dbg!(fut.await).foo();"#, 340 r#"let res = $0dbg!(fut.await).foo();"#,
341 r#"let res = fut.await.foo();"#, 341 r#"let res = fut.await.foo();"#,
342 ); 342 );
343 } 343 }
@@ -346,7 +346,7 @@ fn main() {
346 fn test_remove_dbg_as_cast() { 346 fn test_remove_dbg_as_cast() {
347 check_assist( 347 check_assist(
348 remove_dbg, 348 remove_dbg,
349 r#"let res = <|>dbg!(3 as usize).foo();"#, 349 r#"let res = $0dbg!(3 as usize).foo();"#,
350 r#"let res = (3 as usize).foo();"#, 350 r#"let res = (3 as usize).foo();"#,
351 ); 351 );
352 } 352 }
@@ -355,12 +355,12 @@ fn main() {
355 fn test_remove_dbg_index_expr() { 355 fn test_remove_dbg_index_expr() {
356 check_assist( 356 check_assist(
357 remove_dbg, 357 remove_dbg,
358 r#"let res = <|>dbg!(array[3]).foo();"#, 358 r#"let res = $0dbg!(array[3]).foo();"#,
359 r#"let res = array[3].foo();"#, 359 r#"let res = array[3].foo();"#,
360 ); 360 );
361 check_assist( 361 check_assist(
362 remove_dbg, 362 remove_dbg,
363 r#"let res = <|>dbg!(tuple.3).foo();"#, 363 r#"let res = $0dbg!(tuple.3).foo();"#,
364 r#"let res = tuple.3.foo();"#, 364 r#"let res = tuple.3.foo();"#,
365 ); 365 );
366 } 366 }
@@ -369,12 +369,12 @@ fn main() {
369 fn test_remove_dbg_range_expr() { 369 fn test_remove_dbg_range_expr() {
370 check_assist( 370 check_assist(
371 remove_dbg, 371 remove_dbg,
372 r#"let res = <|>dbg!(foo..bar).foo();"#, 372 r#"let res = $0dbg!(foo..bar).foo();"#,
373 r#"let res = (foo..bar).foo();"#, 373 r#"let res = (foo..bar).foo();"#,
374 ); 374 );
375 check_assist( 375 check_assist(
376 remove_dbg, 376 remove_dbg,
377 r#"let res = <|>dbg!(foo..=bar).foo();"#, 377 r#"let res = $0dbg!(foo..=bar).foo();"#,
378 r#"let res = (foo..=bar).foo();"#, 378 r#"let res = (foo..=bar).foo();"#,
379 ); 379 );
380 } 380 }
@@ -384,7 +384,7 @@ fn main() {
384 check_assist( 384 check_assist(
385 remove_dbg, 385 remove_dbg,
386 r#"fn foo() { 386 r#"fn foo() {
387 if <|>dbg!(x || y) {} 387 if $0dbg!(x || y) {}
388}"#, 388}"#,
389 r#"fn foo() { 389 r#"fn foo() {
390 if x || y {} 390 if x || y {}
@@ -393,7 +393,7 @@ fn main() {
393 check_assist( 393 check_assist(
394 remove_dbg, 394 remove_dbg,
395 r#"fn foo() { 395 r#"fn foo() {
396 while let foo = <|>dbg!(&x) {} 396 while let foo = $0dbg!(&x) {}
397}"#, 397}"#,
398 r#"fn foo() { 398 r#"fn foo() {
399 while let foo = &x {} 399 while let foo = &x {}
@@ -402,7 +402,7 @@ fn main() {
402 check_assist( 402 check_assist(
403 remove_dbg, 403 remove_dbg,
404 r#"fn foo() { 404 r#"fn foo() {
405 if let foo = <|>dbg!(&x) {} 405 if let foo = $0dbg!(&x) {}
406}"#, 406}"#,
407 r#"fn foo() { 407 r#"fn foo() {
408 if let foo = &x {} 408 if let foo = &x {}
@@ -411,7 +411,7 @@ fn main() {
411 check_assist( 411 check_assist(
412 remove_dbg, 412 remove_dbg,
413 r#"fn foo() { 413 r#"fn foo() {
414 match <|>dbg!(&x) {} 414 match $0dbg!(&x) {}
415}"#, 415}"#,
416 r#"fn foo() { 416 r#"fn foo() {
417 match &x {} 417 match &x {}
diff --git a/crates/assists/src/handlers/remove_mut.rs b/crates/assists/src/handlers/remove_mut.rs
index 575b271f7..30d36dacd 100644
--- a/crates/assists/src/handlers/remove_mut.rs
+++ b/crates/assists/src/handlers/remove_mut.rs
@@ -8,7 +8,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
8// 8//
9// ``` 9// ```
10// impl Walrus { 10// impl Walrus {
11// fn feed(&mut<|> self, amount: u32) {} 11// fn feed(&mut$0 self, amount: u32) {}
12// } 12// }
13// ``` 13// ```
14// -> 14// ->
diff --git a/crates/assists/src/handlers/remove_unused_param.rs b/crates/assists/src/handlers/remove_unused_param.rs
index f72dd49ed..c961680e2 100644
--- a/crates/assists/src/handlers/remove_unused_param.rs
+++ b/crates/assists/src/handlers/remove_unused_param.rs
@@ -1,8 +1,8 @@
1use ide_db::{defs::Definition, search::Reference}; 1use ide_db::{base_db::FileId, defs::Definition, search::FileReference};
2use syntax::{ 2use syntax::{
3 algo::find_node_at_range, 3 algo::find_node_at_range,
4 ast::{self, ArgListOwner}, 4 ast::{self, ArgListOwner},
5 AstNode, SyntaxKind, SyntaxNode, TextRange, T, 5 AstNode, SourceFile, SyntaxKind, SyntaxNode, TextRange, T,
6}; 6};
7use test_utils::mark; 7use test_utils::mark;
8use SyntaxKind::WHITESPACE; 8use SyntaxKind::WHITESPACE;
@@ -16,7 +16,7 @@ use crate::{
16// Removes unused function parameter. 16// Removes unused function parameter.
17// 17//
18// ``` 18// ```
19// fn frobnicate(x: i32<|>) {} 19// fn frobnicate(x: i32$0) {}
20// 20//
21// fn main() { 21// fn main() {
22// frobnicate(92); 22// frobnicate(92);
@@ -58,32 +58,41 @@ pub(crate) fn remove_unused_param(acc: &mut Assists, ctx: &AssistContext) -> Opt
58 param.syntax().text_range(), 58 param.syntax().text_range(),
59 |builder| { 59 |builder| {
60 builder.delete(range_to_remove(param.syntax())); 60 builder.delete(range_to_remove(param.syntax()));
61 for usage in fn_def.usages(&ctx.sema).all() { 61 for (file_id, references) in fn_def.usages(&ctx.sema).all() {
62 process_usage(ctx, builder, usage, param_position); 62 process_usages(ctx, builder, file_id, references, param_position);
63 } 63 }
64 }, 64 },
65 ) 65 )
66} 66}
67 67
68fn process_usage( 68fn process_usages(
69 ctx: &AssistContext, 69 ctx: &AssistContext,
70 builder: &mut AssistBuilder, 70 builder: &mut AssistBuilder,
71 usage: Reference, 71 file_id: FileId,
72 references: Vec<FileReference>,
72 arg_to_remove: usize, 73 arg_to_remove: usize,
73) -> Option<()> { 74) {
74 let source_file = ctx.sema.parse(usage.file_range.file_id); 75 let source_file = ctx.sema.parse(file_id);
75 let call_expr: ast::CallExpr = 76 builder.edit_file(file_id);
76 find_node_at_range(source_file.syntax(), usage.file_range.range)?; 77 for usage in references {
78 if let Some(text_range) = process_usage(&source_file, usage, arg_to_remove) {
79 builder.delete(text_range);
80 }
81 }
82}
83
84fn process_usage(
85 source_file: &SourceFile,
86 FileReference { range, .. }: FileReference,
87 arg_to_remove: usize,
88) -> Option<TextRange> {
89 let call_expr: ast::CallExpr = find_node_at_range(source_file.syntax(), range)?;
77 let call_expr_range = call_expr.expr()?.syntax().text_range(); 90 let call_expr_range = call_expr.expr()?.syntax().text_range();
78 if !call_expr_range.contains_range(usage.file_range.range) { 91 if !call_expr_range.contains_range(range) {
79 return None; 92 return None;
80 } 93 }
81 let arg = call_expr.arg_list()?.args().nth(arg_to_remove)?; 94 let arg = call_expr.arg_list()?.args().nth(arg_to_remove)?;
82 95 Some(range_to_remove(arg.syntax()))
83 builder.edit_file(usage.file_range.file_id);
84 builder.delete(range_to_remove(arg.syntax()));
85
86 Some(())
87} 96}
88 97
89fn range_to_remove(node: &SyntaxNode) -> TextRange { 98fn range_to_remove(node: &SyntaxNode) -> TextRange {
@@ -123,7 +132,7 @@ mod tests {
123 remove_unused_param, 132 remove_unused_param,
124 r#" 133 r#"
125fn a() { foo(9, 2) } 134fn a() { foo(9, 2) }
126fn foo(x: i32, <|>y: i32) { x; } 135fn foo(x: i32, $0y: i32) { x; }
127fn b() { foo(9, 2,) } 136fn b() { foo(9, 2,) }
128"#, 137"#,
129 r#" 138 r#"
@@ -139,7 +148,7 @@ fn b() { foo(9, ) }
139 check_assist( 148 check_assist(
140 remove_unused_param, 149 remove_unused_param,
141 r#" 150 r#"
142fn foo(<|>x: i32, y: i32) { y; } 151fn foo($0x: i32, y: i32) { y; }
143fn a() { foo(1, 2) } 152fn a() { foo(1, 2) }
144fn b() { foo(1, 2,) } 153fn b() { foo(1, 2,) }
145"#, 154"#,
@@ -156,7 +165,7 @@ fn b() { foo(2,) }
156 check_assist( 165 check_assist(
157 remove_unused_param, 166 remove_unused_param,
158 r#" 167 r#"
159fn foo(<|>x: i32) { 0; } 168fn foo($0x: i32) { 0; }
160fn a() { foo(1) } 169fn a() { foo(1) }
161fn b() { foo(1, ) } 170fn b() { foo(1, ) }
162"#, 171"#,
@@ -173,7 +182,7 @@ fn b() { foo( ) }
173 check_assist( 182 check_assist(
174 remove_unused_param, 183 remove_unused_param,
175 r#" 184 r#"
176fn foo(x: i32, <|>y: i32, z: i32) { x; } 185fn foo(x: i32, $0y: i32, z: i32) { x; }
177fn a() { foo(1, 2, 3) } 186fn a() { foo(1, 2, 3) }
178fn b() { foo(1, 2, 3,) } 187fn b() { foo(1, 2, 3,) }
179"#, 188"#,
@@ -190,7 +199,7 @@ fn b() { foo(1, 3,) }
190 check_assist( 199 check_assist(
191 remove_unused_param, 200 remove_unused_param,
192 r#" 201 r#"
193mod bar { pub fn foo(x: i32, <|>y: i32) { x; } } 202mod bar { pub fn foo(x: i32, $0y: i32) { x; } }
194fn b() { bar::foo(9, 2) } 203fn b() { bar::foo(9, 2) }
195"#, 204"#,
196 r#" 205 r#"
@@ -205,7 +214,7 @@ fn b() { bar::foo(9) }
205 check_assist( 214 check_assist(
206 remove_unused_param, 215 remove_unused_param,
207 r#" 216 r#"
208pub fn foo<T>(x: T, <|>y: i32) { x; } 217pub fn foo<T>(x: T, $0y: i32) { x; }
209fn b() { foo::<i32>(9, 2) } 218fn b() { foo::<i32>(9, 2) }
210"#, 219"#,
211 r#" 220 r#"
@@ -220,7 +229,7 @@ fn b() { foo::<i32>(9) }
220 check_assist( 229 check_assist(
221 remove_unused_param, 230 remove_unused_param,
222 r#" 231 r#"
223pub fn foo<T>(x: i32, <|>y: T) { x; } 232pub fn foo<T>(x: i32, $0y: T) { x; }
224fn b() { foo::<i32>(9, 2) } 233fn b() { foo::<i32>(9, 2) }
225fn b2() { foo(9, 2) } 234fn b2() { foo(9, 2) }
226"#, 235"#,
@@ -238,7 +247,7 @@ fn b2() { foo(9) }
238 check_assist_not_applicable( 247 check_assist_not_applicable(
239 remove_unused_param, 248 remove_unused_param,
240 r#" 249 r#"
241fn foo(x: i32, <|>y: i32) { y; } 250fn foo(x: i32, $0y: i32) { y; }
242fn main() { foo(9, 2) } 251fn main() { foo(9, 2) }
243"#, 252"#,
244 ); 253 );
@@ -250,7 +259,7 @@ fn main() { foo(9, 2) }
250 remove_unused_param, 259 remove_unused_param,
251 r#" 260 r#"
252//- /main.rs 261//- /main.rs
253fn foo(x: i32, <|>y: i32) { x; } 262fn foo(x: i32, $0y: i32) { x; }
254 263
255mod foo; 264mod foo;
256 265
diff --git a/crates/assists/src/handlers/reorder_fields.rs b/crates/assists/src/handlers/reorder_fields.rs
index fe5574242..fba7d6ddb 100644
--- a/crates/assists/src/handlers/reorder_fields.rs
+++ b/crates/assists/src/handlers/reorder_fields.rs
@@ -15,7 +15,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
15// 15//
16// ``` 16// ```
17// struct Foo {foo: i32, bar: i32}; 17// struct Foo {foo: i32, bar: i32};
18// const test: Foo = <|>Foo {bar: 0, foo: 1} 18// const test: Foo = $0Foo {bar: 0, foo: 1}
19// ``` 19// ```
20// -> 20// ->
21// ``` 21// ```
@@ -126,7 +126,7 @@ struct Foo {
126 bar: i32, 126 bar: i32,
127} 127}
128 128
129const test: Foo = <|>Foo { foo: 0, bar: 0 }; 129const test: Foo = $0Foo { foo: 0, bar: 0 };
130"#, 130"#,
131 ) 131 )
132 } 132 }
@@ -137,7 +137,7 @@ const test: Foo = <|>Foo { foo: 0, bar: 0 };
137 reorder_fields, 137 reorder_fields,
138 r#" 138 r#"
139struct Foo {}; 139struct Foo {};
140const test: Foo = <|>Foo {} 140const test: Foo = $0Foo {}
141"#, 141"#,
142 ) 142 )
143 } 143 }
@@ -148,7 +148,7 @@ const test: Foo = <|>Foo {}
148 reorder_fields, 148 reorder_fields,
149 r#" 149 r#"
150struct Foo {foo: i32, bar: i32}; 150struct Foo {foo: i32, bar: i32};
151const test: Foo = <|>Foo {bar: 0, foo: 1} 151const test: Foo = $0Foo {bar: 0, foo: 1}
152"#, 152"#,
153 r#" 153 r#"
154struct Foo {foo: i32, bar: i32}; 154struct Foo {foo: i32, bar: i32};
@@ -166,7 +166,7 @@ struct Foo { foo: i64, bar: i64, baz: i64 }
166 166
167fn f(f: Foo) -> { 167fn f(f: Foo) -> {
168 match f { 168 match f {
169 <|>Foo { baz: 0, ref mut bar, .. } => (), 169 $0Foo { baz: 0, ref mut bar, .. } => (),
170 _ => () 170 _ => ()
171 } 171 }
172} 172}
@@ -197,7 +197,7 @@ struct Foo {
197impl Foo { 197impl Foo {
198 fn new() -> Foo { 198 fn new() -> Foo {
199 let foo = String::new(); 199 let foo = String::new();
200 <|>Foo { 200 $0Foo {
201 bar: foo.clone(), 201 bar: foo.clone(),
202 extra: "Extra field", 202 extra: "Extra field",
203 foo, 203 foo,
diff --git a/crates/assists/src/handlers/reorder_impl.rs b/crates/assists/src/handlers/reorder_impl.rs
new file mode 100644
index 000000000..309f291c8
--- /dev/null
+++ b/crates/assists/src/handlers/reorder_impl.rs
@@ -0,0 +1,201 @@
1use itertools::Itertools;
2use rustc_hash::FxHashMap;
3
4use hir::{PathResolution, Semantics};
5use ide_db::RootDatabase;
6use syntax::{
7 algo,
8 ast::{self, NameOwner},
9 AstNode,
10};
11use test_utils::mark;
12
13use crate::{AssistContext, AssistId, AssistKind, Assists};
14
15// Assist: reorder_impl
16//
17// Reorder the methods of an `impl Trait`. The methods will be ordered
18// in the same order as in the trait definition.
19//
20// ```
21// trait Foo {
22// fn a() {}
23// fn b() {}
24// fn c() {}
25// }
26//
27// struct Bar;
28// $0impl Foo for Bar {
29// fn b() {}
30// fn c() {}
31// fn a() {}
32// }
33// ```
34// ->
35// ```
36// trait Foo {
37// fn a() {}
38// fn b() {}
39// fn c() {}
40// }
41//
42// struct Bar;
43// impl Foo for Bar {
44// fn a() {}
45// fn b() {}
46// fn c() {}
47// }
48// ```
49//
50pub(crate) fn reorder_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
51 let impl_ast = ctx.find_node_at_offset::<ast::Impl>()?;
52 let items = impl_ast.assoc_item_list()?;
53 let methods = get_methods(&items);
54
55 let path = impl_ast
56 .trait_()
57 .and_then(|t| match t {
58 ast::Type::PathType(path) => Some(path),
59 _ => None,
60 })?
61 .path()?;
62
63 let ranks = compute_method_ranks(&path, ctx)?;
64 let sorted: Vec<_> = methods
65 .iter()
66 .cloned()
67 .sorted_by_key(|f| {
68 f.name().and_then(|n| ranks.get(&n.to_string()).copied()).unwrap_or(usize::max_value())
69 })
70 .collect();
71
72 // Don't edit already sorted methods:
73 if methods == sorted {
74 mark::hit!(not_applicable_if_sorted);
75 return None;
76 }
77
78 let target = items.syntax().text_range();
79 acc.add(AssistId("reorder_impl", AssistKind::RefactorRewrite), "Sort methods", target, |edit| {
80 let mut rewriter = algo::SyntaxRewriter::default();
81 for (old, new) in methods.iter().zip(&sorted) {
82 rewriter.replace(old.syntax(), new.syntax());
83 }
84 edit.rewrite(rewriter);
85 })
86}
87
88fn compute_method_ranks(path: &ast::Path, ctx: &AssistContext) -> Option<FxHashMap<String, usize>> {
89 let td = trait_definition(path, &ctx.sema)?;
90
91 Some(
92 td.items(ctx.db())
93 .iter()
94 .flat_map(|i| match i {
95 hir::AssocItem::Function(f) => Some(f),
96 _ => None,
97 })
98 .enumerate()
99 .map(|(idx, func)| ((func.name(ctx.db()).to_string(), idx)))
100 .collect(),
101 )
102}
103
104fn trait_definition(path: &ast::Path, sema: &Semantics<RootDatabase>) -> Option<hir::Trait> {
105 match sema.resolve_path(path)? {
106 PathResolution::Def(hir::ModuleDef::Trait(trait_)) => Some(trait_),
107 _ => None,
108 }
109}
110
111fn get_methods(items: &ast::AssocItemList) -> Vec<ast::Fn> {
112 items
113 .assoc_items()
114 .flat_map(|i| match i {
115 ast::AssocItem::Fn(f) => Some(f),
116 _ => None,
117 })
118 .filter(|f| f.name().is_some())
119 .collect()
120}
121
122#[cfg(test)]
123mod tests {
124 use test_utils::mark;
125
126 use crate::tests::{check_assist, check_assist_not_applicable};
127
128 use super::*;
129
130 #[test]
131 fn not_applicable_if_sorted() {
132 mark::check!(not_applicable_if_sorted);
133 check_assist_not_applicable(
134 reorder_impl,
135 r#"
136trait Bar {
137 fn a() {}
138 fn z() {}
139 fn b() {}
140}
141struct Foo;
142$0impl Bar for Foo {
143 fn a() {}
144 fn z() {}
145 fn b() {}
146}
147 "#,
148 )
149 }
150
151 #[test]
152 fn not_applicable_if_empty() {
153 check_assist_not_applicable(
154 reorder_impl,
155 r#"
156trait Bar {};
157struct Foo;
158$0impl Bar for Foo {}
159 "#,
160 )
161 }
162
163 #[test]
164 fn reorder_impl_trait_methods() {
165 check_assist(
166 reorder_impl,
167 r#"
168trait Bar {
169 fn a() {}
170 fn c() {}
171 fn b() {}
172 fn d() {}
173}
174
175struct Foo;
176$0impl Bar for Foo {
177 fn d() {}
178 fn b() {}
179 fn c() {}
180 fn a() {}
181}
182 "#,
183 r#"
184trait Bar {
185 fn a() {}
186 fn c() {}
187 fn b() {}
188 fn d() {}
189}
190
191struct Foo;
192impl Bar for Foo {
193 fn a() {}
194 fn c() {}
195 fn b() {}
196 fn d() {}
197}
198 "#,
199 )
200 }
201}
diff --git a/crates/assists/src/handlers/replace_derive_with_manual_impl.rs b/crates/assists/src/handlers/replace_derive_with_manual_impl.rs
index cb7a5c104..bd4c1c806 100644
--- a/crates/assists/src/handlers/replace_derive_with_manual_impl.rs
+++ b/crates/assists/src/handlers/replace_derive_with_manual_impl.rs
@@ -22,7 +22,7 @@ use crate::{
22// 22//
23// ``` 23// ```
24// # trait Debug { fn fmt(&self, f: &mut Formatter) -> Result<()>; } 24// # trait Debug { fn fmt(&self, f: &mut Formatter) -> Result<()>; }
25// #[derive(Deb<|>ug, Display)] 25// #[derive(Deb$0ug, Display)]
26// struct S; 26// struct S;
27// ``` 27// ```
28// -> 28// ->
@@ -219,7 +219,7 @@ mod fmt {
219 } 219 }
220} 220}
221 221
222#[derive(Debu<|>g)] 222#[derive(Debu$0g)]
223struct Foo { 223struct Foo {
224 bar: String, 224 bar: String,
225} 225}
@@ -261,7 +261,7 @@ mod foo {
261 } 261 }
262} 262}
263 263
264#[derive(<|>Bar)] 264#[derive($0Bar)]
265struct Foo { 265struct Foo {
266 bar: String, 266 bar: String,
267} 267}
@@ -300,7 +300,7 @@ impl foo::Bar for Foo {
300 check_assist( 300 check_assist(
301 replace_derive_with_manual_impl, 301 replace_derive_with_manual_impl,
302 " 302 "
303#[derive(Debu<|>g)] 303#[derive(Debu$0g)]
304struct Foo { 304struct Foo {
305 bar: String, 305 bar: String,
306} 306}
@@ -322,7 +322,7 @@ impl Debug for Foo {
322 check_assist( 322 check_assist(
323 replace_derive_with_manual_impl, 323 replace_derive_with_manual_impl,
324 " 324 "
325#[derive(Debug<|>)] 325#[derive(Debug$0)]
326pub struct Foo { 326pub struct Foo {
327 bar: String, 327 bar: String,
328} 328}
@@ -344,7 +344,7 @@ impl Debug for Foo {
344 check_assist( 344 check_assist(
345 replace_derive_with_manual_impl, 345 replace_derive_with_manual_impl,
346 " 346 "
347#[derive(Display, Debug<|>, Serialize)] 347#[derive(Display, Debug$0, Serialize)]
348struct Foo {} 348struct Foo {}
349 ", 349 ",
350 " 350 "
@@ -363,7 +363,7 @@ impl Debug for Foo {
363 check_assist_not_applicable( 363 check_assist_not_applicable(
364 replace_derive_with_manual_impl, 364 replace_derive_with_manual_impl,
365 " 365 "
366#[derive(<|>)] 366#[derive($0)]
367struct Foo {} 367struct Foo {}
368 ", 368 ",
369 ) 369 )
@@ -374,7 +374,7 @@ struct Foo {}
374 check_assist_not_applicable( 374 check_assist_not_applicable(
375 replace_derive_with_manual_impl, 375 replace_derive_with_manual_impl,
376 " 376 "
377#[derive<|>(Debug)] 377#[derive$0(Debug)]
378struct Foo {} 378struct Foo {}
379 ", 379 ",
380 ); 380 );
@@ -382,7 +382,7 @@ struct Foo {}
382 check_assist_not_applicable( 382 check_assist_not_applicable(
383 replace_derive_with_manual_impl, 383 replace_derive_with_manual_impl,
384 " 384 "
385#[derive(Debug)<|>] 385#[derive(Debug)$0]
386struct Foo {} 386struct Foo {}
387 ", 387 ",
388 ) 388 )
@@ -393,7 +393,7 @@ struct Foo {}
393 check_assist_not_applicable( 393 check_assist_not_applicable(
394 replace_derive_with_manual_impl, 394 replace_derive_with_manual_impl,
395 " 395 "
396#[allow(non_camel_<|>case_types)] 396#[allow(non_camel_$0case_types)]
397struct Foo {} 397struct Foo {}
398 ", 398 ",
399 ) 399 )
diff --git a/crates/assists/src/handlers/replace_if_let_with_match.rs b/crates/assists/src/handlers/replace_if_let_with_match.rs
index 4a355c66f..aee3397ab 100644
--- a/crates/assists/src/handlers/replace_if_let_with_match.rs
+++ b/crates/assists/src/handlers/replace_if_let_with_match.rs
@@ -20,7 +20,7 @@ use crate::{utils::unwrap_trivial_block, AssistContext, AssistId, AssistKind, As
20// enum Action { Move { distance: u32 }, Stop } 20// enum Action { Move { distance: u32 }, Stop }
21// 21//
22// fn handle(action: Action) { 22// fn handle(action: Action) {
23// <|>if let Action::Move { distance } = action { 23// $0if let Action::Move { distance } = action {
24// foo(distance) 24// foo(distance)
25// } else { 25// } else {
26// bar() 26// bar()
@@ -89,7 +89,7 @@ pub(crate) fn replace_if_let_with_match(acc: &mut Assists, ctx: &AssistContext)
89// enum Action { Move { distance: u32 }, Stop } 89// enum Action { Move { distance: u32 }, Stop }
90// 90//
91// fn handle(action: Action) { 91// fn handle(action: Action) {
92// <|>match action { 92// $0match action {
93// Action::Move { distance } => foo(distance), 93// Action::Move { distance } => foo(distance),
94// _ => bar(), 94// _ => bar(),
95// } 95// }
@@ -138,7 +138,7 @@ pub(crate) fn replace_match_with_if_let(acc: &mut Assists, ctx: &AssistContext)
138 }; 138 };
139 let else_expr = match else_expr { 139 let else_expr = match else_expr {
140 ast::Expr::BlockExpr(block) 140 ast::Expr::BlockExpr(block)
141 if block.statements().count() == 0 && block.expr().is_none() => 141 if block.statements().count() == 0 && block.tail_expr().is_none() =>
142 { 142 {
143 None 143 None
144 } 144 }
@@ -179,7 +179,7 @@ mod tests {
179 r#" 179 r#"
180impl VariantData { 180impl VariantData {
181 pub fn is_struct(&self) -> bool { 181 pub fn is_struct(&self) -> bool {
182 if <|>let VariantData::Struct(..) = *self { 182 if $0let VariantData::Struct(..) = *self {
183 true 183 true
184 } else { 184 } else {
185 false 185 false
@@ -204,7 +204,7 @@ impl VariantData {
204 replace_if_let_with_match, 204 replace_if_let_with_match,
205 r#" 205 r#"
206fn foo() { 206fn foo() {
207 if <|>let VariantData::Struct(..) = a { 207 if $0let VariantData::Struct(..) = a {
208 bar( 208 bar(
209 123 209 123
210 ) 210 )
@@ -233,7 +233,7 @@ fn foo() {
233 r#" 233 r#"
234impl VariantData { 234impl VariantData {
235 pub fn is_struct(&self) -> bool { 235 pub fn is_struct(&self) -> bool {
236 if <|>let VariantData::Struct(..) = *self { 236 if $0let VariantData::Struct(..) = *self {
237 true 237 true
238 } else { 238 } else {
239 false 239 false
@@ -257,7 +257,7 @@ enum Option<T> { Some(T), None }
257use Option::*; 257use Option::*;
258 258
259fn foo(x: Option<i32>) { 259fn foo(x: Option<i32>) {
260 <|>if let Some(x) = x { 260 $0if let Some(x) = x {
261 println!("{}", x) 261 println!("{}", x)
262 } else { 262 } else {
263 println!("none") 263 println!("none")
@@ -287,7 +287,7 @@ enum Result<T, E> { Ok(T), Err(E) }
287use Result::*; 287use Result::*;
288 288
289fn foo(x: Result<i32, ()>) { 289fn foo(x: Result<i32, ()>) {
290 <|>if let Ok(x) = x { 290 $0if let Ok(x) = x {
291 println!("{}", x) 291 println!("{}", x)
292 } else { 292 } else {
293 println!("none") 293 println!("none")
@@ -315,7 +315,7 @@ fn foo(x: Result<i32, ()>) {
315 r#" 315 r#"
316fn main() { 316fn main() {
317 if true { 317 if true {
318 <|>if let Ok(rel_path) = path.strip_prefix(root_path) { 318 $0if let Ok(rel_path) = path.strip_prefix(root_path) {
319 let rel_path = RelativePathBuf::from_path(rel_path).ok()?; 319 let rel_path = RelativePathBuf::from_path(rel_path).ok()?;
320 Some((*id, rel_path)) 320 Some((*id, rel_path))
321 } else { 321 } else {
@@ -347,7 +347,7 @@ fn main() {
347 r#" 347 r#"
348impl VariantData { 348impl VariantData {
349 pub fn is_struct(&self) -> bool { 349 pub fn is_struct(&self) -> bool {
350 <|>match *self { 350 $0match *self {
351 VariantData::Struct(..) => true, 351 VariantData::Struct(..) => true,
352 _ => false, 352 _ => false,
353 } 353 }
@@ -372,7 +372,7 @@ impl VariantData {
372 replace_match_with_if_let, 372 replace_match_with_if_let,
373 r#" 373 r#"
374fn foo() { 374fn foo() {
375 <|>match a { 375 $0match a {
376 VariantData::Struct(..) => { 376 VariantData::Struct(..) => {
377 bar( 377 bar(
378 123 378 123
@@ -401,7 +401,7 @@ fn foo() {
401 r#" 401 r#"
402impl VariantData { 402impl VariantData {
403 pub fn is_struct(&self) -> bool { 403 pub fn is_struct(&self) -> bool {
404 <|>match *self { 404 $0match *self {
405 VariantData::Struct(..) => true, 405 VariantData::Struct(..) => true,
406 _ => false, 406 _ => false,
407 } 407 }
@@ -423,7 +423,7 @@ enum Option<T> { Some(T), None }
423use Option::*; 423use Option::*;
424 424
425fn foo(x: Option<i32>) { 425fn foo(x: Option<i32>) {
426 <|>match x { 426 $0match x {
427 Some(x) => println!("{}", x), 427 Some(x) => println!("{}", x),
428 None => println!("none"), 428 None => println!("none"),
429 } 429 }
@@ -453,7 +453,7 @@ enum Result<T, E> { Ok(T), Err(E) }
453use Result::*; 453use Result::*;
454 454
455fn foo(x: Result<i32, ()>) { 455fn foo(x: Result<i32, ()>) {
456 <|>match x { 456 $0match x {
457 Ok(x) => println!("{}", x), 457 Ok(x) => println!("{}", x),
458 Err(_) => println!("none"), 458 Err(_) => println!("none"),
459 } 459 }
@@ -481,7 +481,7 @@ fn foo(x: Result<i32, ()>) {
481 r#" 481 r#"
482fn main() { 482fn main() {
483 if true { 483 if true {
484 <|>match path.strip_prefix(root_path) { 484 $0match path.strip_prefix(root_path) {
485 Ok(rel_path) => { 485 Ok(rel_path) => {
486 let rel_path = RelativePathBuf::from_path(rel_path).ok()?; 486 let rel_path = RelativePathBuf::from_path(rel_path).ok()?;
487 Some((*id, rel_path)) 487 Some((*id, rel_path))
@@ -512,7 +512,7 @@ fn main() {
512 replace_match_with_if_let, 512 replace_match_with_if_let,
513 r#" 513 r#"
514fn main() { 514fn main() {
515 <|>match path.strip_prefix(root_path) { 515 $0match path.strip_prefix(root_path) {
516 Ok(rel_path) => println!("{}", rel_path), 516 Ok(rel_path) => println!("{}", rel_path),
517 _ => (), 517 _ => (),
518 } 518 }
diff --git a/crates/assists/src/handlers/replace_impl_trait_with_generic.rs b/crates/assists/src/handlers/replace_impl_trait_with_generic.rs
index 6738bc134..ff25b61ea 100644
--- a/crates/assists/src/handlers/replace_impl_trait_with_generic.rs
+++ b/crates/assists/src/handlers/replace_impl_trait_with_generic.rs
@@ -7,7 +7,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
7// Replaces `impl Trait` function argument with the named generic. 7// Replaces `impl Trait` function argument with the named generic.
8// 8//
9// ``` 9// ```
10// fn foo(bar: <|>impl Bar) {} 10// fn foo(bar: $0impl Bar) {}
11// ``` 11// ```
12// -> 12// ->
13// ``` 13// ```
@@ -56,7 +56,7 @@ mod tests {
56 check_assist( 56 check_assist(
57 replace_impl_trait_with_generic, 57 replace_impl_trait_with_generic,
58 r#" 58 r#"
59 fn foo<G>(bar: <|>impl Bar) {} 59 fn foo<G>(bar: $0impl Bar) {}
60 "#, 60 "#,
61 r#" 61 r#"
62 fn foo<G, B: Bar>(bar: B) {} 62 fn foo<G, B: Bar>(bar: B) {}
@@ -69,7 +69,7 @@ mod tests {
69 check_assist( 69 check_assist(
70 replace_impl_trait_with_generic, 70 replace_impl_trait_with_generic,
71 r#" 71 r#"
72 fn foo(bar: <|>impl Bar) {} 72 fn foo(bar: $0impl Bar) {}
73 "#, 73 "#,
74 r#" 74 r#"
75 fn foo<B: Bar>(bar: B) {} 75 fn foo<B: Bar>(bar: B) {}
@@ -82,7 +82,7 @@ mod tests {
82 check_assist( 82 check_assist(
83 replace_impl_trait_with_generic, 83 replace_impl_trait_with_generic,
84 r#" 84 r#"
85 fn foo<G>(foo: impl Foo, bar: <|>impl Bar) {} 85 fn foo<G>(foo: impl Foo, bar: $0impl Bar) {}
86 "#, 86 "#,
87 r#" 87 r#"
88 fn foo<G, B: Bar>(foo: impl Foo, bar: B) {} 88 fn foo<G, B: Bar>(foo: impl Foo, bar: B) {}
@@ -95,7 +95,7 @@ mod tests {
95 check_assist( 95 check_assist(
96 replace_impl_trait_with_generic, 96 replace_impl_trait_with_generic,
97 r#" 97 r#"
98 fn foo<>(bar: <|>impl Bar) {} 98 fn foo<>(bar: $0impl Bar) {}
99 "#, 99 "#,
100 r#" 100 r#"
101 fn foo<B: Bar>(bar: B) {} 101 fn foo<B: Bar>(bar: B) {}
@@ -109,7 +109,7 @@ mod tests {
109 replace_impl_trait_with_generic, 109 replace_impl_trait_with_generic,
110 r#" 110 r#"
111 fn foo< 111 fn foo<
112 >(bar: <|>impl Bar) {} 112 >(bar: $0impl Bar) {}
113 "#, 113 "#,
114 r#" 114 r#"
115 fn foo<B: Bar 115 fn foo<B: Bar
@@ -124,7 +124,7 @@ mod tests {
124 check_assist( 124 check_assist(
125 replace_impl_trait_with_generic, 125 replace_impl_trait_with_generic,
126 r#" 126 r#"
127 fn foo<B>(bar: <|>impl Bar) {} 127 fn foo<B>(bar: $0impl Bar) {}
128 "#, 128 "#,
129 r#" 129 r#"
130 fn foo<B, C: Bar>(bar: C) {} 130 fn foo<B, C: Bar>(bar: C) {}
@@ -141,7 +141,7 @@ mod tests {
141 G: Foo, 141 G: Foo,
142 F, 142 F,
143 H, 143 H,
144 >(bar: <|>impl Bar) {} 144 >(bar: $0impl Bar) {}
145 "#, 145 "#,
146 r#" 146 r#"
147 fn foo< 147 fn foo<
@@ -158,7 +158,7 @@ mod tests {
158 check_assist( 158 check_assist(
159 replace_impl_trait_with_generic, 159 replace_impl_trait_with_generic,
160 r#" 160 r#"
161 fn foo(bar: <|>impl Foo + Bar) {} 161 fn foo(bar: $0impl Foo + Bar) {}
162 "#, 162 "#,
163 r#" 163 r#"
164 fn foo<F: Foo + Bar>(bar: F) {} 164 fn foo<F: Foo + Bar>(bar: F) {}
diff --git a/crates/assists/src/handlers/replace_let_with_if_let.rs b/crates/assists/src/handlers/replace_let_with_if_let.rs
index 5970e283c..5a27ada6b 100644
--- a/crates/assists/src/handlers/replace_let_with_if_let.rs
+++ b/crates/assists/src/handlers/replace_let_with_if_let.rs
@@ -20,7 +20,7 @@ use ide_db::ty_filter::TryEnum;
20// # enum Option<T> { Some(T), None } 20// # enum Option<T> { Some(T), None }
21// 21//
22// fn main(action: Action) { 22// fn main(action: Action) {
23// <|>let x = compute(); 23// $0let x = compute();
24// } 24// }
25// 25//
26// fn compute() -> Option<i32> { None } 26// fn compute() -> Option<i32> { None }
@@ -85,7 +85,7 @@ mod tests {
85enum E<T> { X(T), Y(T) } 85enum E<T> { X(T), Y(T) }
86 86
87fn main() { 87fn main() {
88 <|>let x = E::X(92); 88 $0let x = E::X(92);
89} 89}
90 ", 90 ",
91 r" 91 r"
diff --git a/crates/assists/src/handlers/replace_qualified_name_with_use.rs b/crates/assists/src/handlers/replace_qualified_name_with_use.rs
index 8193e45a8..f3bc6cf39 100644
--- a/crates/assists/src/handlers/replace_qualified_name_with_use.rs
+++ b/crates/assists/src/handlers/replace_qualified_name_with_use.rs
@@ -9,7 +9,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
9// Adds a use statement for a given fully-qualified name. 9// Adds a use statement for a given fully-qualified name.
10// 10//
11// ``` 11// ```
12// fn process(map: std::collections::<|>HashMap<String, String>) {} 12// fn process(map: std::collections::$0HashMap<String, String>) {}
13// ``` 13// ```
14// -> 14// ->
15// ``` 15// ```
@@ -127,7 +127,7 @@ mod tests {
127 r"use std::fs; 127 r"use std::fs;
128 128
129fn main() { 129fn main() {
130 std::f<|>s::Path 130 std::f$0s::Path
131}", 131}",
132 r"use std::fs; 132 r"use std::fs;
133 133
@@ -142,7 +142,7 @@ fn main() {
142 check_assist( 142 check_assist(
143 replace_qualified_name_with_use, 143 replace_qualified_name_with_use,
144 r" 144 r"
145std::fmt::Debug<|> 145std::fmt::Debug$0
146 ", 146 ",
147 r" 147 r"
148use std::fmt::Debug; 148use std::fmt::Debug;
@@ -156,7 +156,7 @@ Debug
156 check_assist( 156 check_assist(
157 replace_qualified_name_with_use, 157 replace_qualified_name_with_use,
158 r" 158 r"
159std::fmt::Debug<|> 159std::fmt::Debug$0
160 160
161fn main() { 161fn main() {
162} 162}
@@ -180,7 +180,7 @@ fn main() {
180fn main() { 180fn main() {
181} 181}
182 182
183std::fmt::Debug<|> 183std::fmt::Debug$0
184 ", 184 ",
185 r" 185 r"
186use std::fmt::Debug; 186use std::fmt::Debug;
@@ -198,7 +198,7 @@ Debug
198 check_assist( 198 check_assist(
199 replace_qualified_name_with_use, 199 replace_qualified_name_with_use,
200 r" 200 r"
201std::fmt<|>::Debug 201std::fmt$0::Debug
202 ", 202 ",
203 r" 203 r"
204use std::fmt; 204use std::fmt;
@@ -215,7 +215,7 @@ fmt::Debug
215 r" 215 r"
216use stdx; 216use stdx;
217 217
218impl std::fmt::Debug<|> for Foo { 218impl std::fmt::Debug$0 for Foo {
219} 219}
220 ", 220 ",
221 r" 221 r"
@@ -234,7 +234,7 @@ impl Debug for Foo {
234 check_assist( 234 check_assist(
235 replace_qualified_name_with_use, 235 replace_qualified_name_with_use,
236 r" 236 r"
237impl std::fmt::Debug<|> for Foo { 237impl std::fmt::Debug$0 for Foo {
238} 238}
239 ", 239 ",
240 r" 240 r"
@@ -251,7 +251,7 @@ impl Debug for Foo {
251 check_assist( 251 check_assist(
252 replace_qualified_name_with_use, 252 replace_qualified_name_with_use,
253 r" 253 r"
254 impl std::fmt::Debug<|> for Foo { 254 impl std::fmt::Debug$0 for Foo {
255 } 255 }
256 ", 256 ",
257 r" 257 r"
@@ -270,7 +270,7 @@ impl Debug for Foo {
270 r" 270 r"
271use std::fmt; 271use std::fmt;
272 272
273impl std::io<|> for Foo { 273impl std::io$0 for Foo {
274} 274}
275 ", 275 ",
276 r" 276 r"
@@ -289,7 +289,7 @@ impl io for Foo {
289 r" 289 r"
290use std::fmt; 290use std::fmt;
291 291
292impl std::fmt::Debug<|> for Foo { 292impl std::fmt::Debug$0 for Foo {
293} 293}
294 ", 294 ",
295 r" 295 r"
@@ -308,7 +308,7 @@ impl Debug for Foo {
308 r" 308 r"
309use std::fmt::Debug; 309use std::fmt::Debug;
310 310
311impl std::fmt<|> for Foo { 311impl std::fmt$0 for Foo {
312} 312}
313 ", 313 ",
314 r" 314 r"
@@ -327,7 +327,7 @@ impl fmt for Foo {
327 r" 327 r"
328use std::fmt::{Debug, nested::{Display}}; 328use std::fmt::{Debug, nested::{Display}};
329 329
330impl std::fmt::nested<|> for Foo { 330impl std::fmt::nested$0 for Foo {
331} 331}
332", 332",
333 r" 333 r"
@@ -346,7 +346,7 @@ impl nested for Foo {
346 r" 346 r"
347use std::fmt::{Debug, nested::{self, Display}}; 347use std::fmt::{Debug, nested::{self, Display}};
348 348
349impl std::fmt::nested<|> for Foo { 349impl std::fmt::nested$0 for Foo {
350} 350}
351", 351",
352 r" 352 r"
@@ -365,7 +365,7 @@ impl nested for Foo {
365 r" 365 r"
366use std::fmt::{Debug, nested::{Display}}; 366use std::fmt::{Debug, nested::{Display}};
367 367
368impl std::fmt::nested::Debug<|> for Foo { 368impl std::fmt::nested::Debug$0 for Foo {
369} 369}
370", 370",
371 r" 371 r"
@@ -384,7 +384,7 @@ impl Debug for Foo {
384 r" 384 r"
385use std::fmt::Debug; 385use std::fmt::Debug;
386 386
387impl std::fmt::nested::Display<|> for Foo { 387impl std::fmt::nested::Display$0 for Foo {
388} 388}
389", 389",
390 r" 390 r"
@@ -403,7 +403,7 @@ impl Display for Foo {
403 r" 403 r"
404use std::fmt::nested::Debug; 404use std::fmt::nested::Debug;
405 405
406impl std::fmt::Display<|> for Foo { 406impl std::fmt::Display$0 for Foo {
407} 407}
408", 408",
409 r" 409 r"
@@ -425,7 +425,7 @@ use crate::{
425 AssocItem, 425 AssocItem,
426}; 426};
427 427
428fn foo() { crate::ty::lower<|>::trait_env() } 428fn foo() { crate::ty::lower$0::trait_env() }
429", 429",
430 r" 430 r"
431use crate::{AssocItem, ty::{Substs, Ty, lower}}; 431use crate::{AssocItem, ty::{Substs, Ty, lower}};
@@ -442,7 +442,7 @@ fn foo() { lower::trait_env() }
442 r" 442 r"
443use std::fmt as foo; 443use std::fmt as foo;
444 444
445impl foo::Debug<|> for Foo { 445impl foo::Debug$0 for Foo {
446} 446}
447", 447",
448 r" 448 r"
@@ -462,7 +462,7 @@ impl Debug for Foo {
462 check_assist_not_applicable( 462 check_assist_not_applicable(
463 replace_qualified_name_with_use, 463 replace_qualified_name_with_use,
464 r" 464 r"
465impl foo<|> for Foo { 465impl foo$0 for Foo {
466} 466}
467", 467",
468 ); 468 );
@@ -473,7 +473,7 @@ impl foo<|> for Foo {
473 check_assist_not_applicable( 473 check_assist_not_applicable(
474 replace_qualified_name_with_use, 474 replace_qualified_name_with_use,
475 r" 475 r"
476use std::fmt<|>; 476use std::fmt$0;
477", 477",
478 ); 478 );
479 } 479 }
@@ -485,7 +485,7 @@ use std::fmt<|>;
485 r" 485 r"
486mod foo { 486mod foo {
487 mod bar { 487 mod bar {
488 std::fmt::Debug<|> 488 std::fmt::Debug$0
489 } 489 }
490} 490}
491 ", 491 ",
@@ -509,7 +509,7 @@ mod foo {
509#![allow(dead_code)] 509#![allow(dead_code)]
510 510
511fn main() { 511fn main() {
512 std::fmt::Debug<|> 512 std::fmt::Debug$0
513} 513}
514 ", 514 ",
515 r" 515 r"
@@ -530,7 +530,7 @@ fn main() {
530 replace_qualified_name_with_use, 530 replace_qualified_name_with_use,
531 r" 531 r"
532fn main() { 532fn main() {
533 std::fmt::Debug<|>; 533 std::fmt::Debug$0;
534 let x: std::fmt::Debug = std::fmt::Debug; 534 let x: std::fmt::Debug = std::fmt::Debug;
535} 535}
536 ", 536 ",
@@ -552,7 +552,7 @@ fn main() {
552 r" 552 r"
553mod m { 553mod m {
554 fn f() { 554 fn f() {
555 std::fmt::Debug<|>; 555 std::fmt::Debug$0;
556 let x: std::fmt::Debug = std::fmt::Debug; 556 let x: std::fmt::Debug = std::fmt::Debug;
557 } 557 }
558 fn g() { 558 fn g() {
@@ -590,7 +590,7 @@ fn f() {
590 replace_qualified_name_with_use, 590 replace_qualified_name_with_use,
591 r" 591 r"
592fn main() { 592fn main() {
593 std::fmt::Debug<|>; 593 std::fmt::Debug$0;
594} 594}
595 595
596mod sub { 596mod sub {
@@ -623,7 +623,7 @@ mod sub {
623use std::fmt::Display; 623use std::fmt::Display;
624 624
625fn main() { 625fn main() {
626 std::fmt<|>; 626 std::fmt$0;
627} 627}
628 ", 628 ",
629 r" 629 r"
@@ -643,7 +643,7 @@ fn main() {
643 r" 643 r"
644pub use std::fmt; 644pub use std::fmt;
645 645
646impl std::io<|> for Foo { 646impl std::io$0 for Foo {
647} 647}
648 ", 648 ",
649 r" 649 r"
@@ -663,7 +663,7 @@ impl io for Foo {
663 r" 663 r"
664pub(crate) use std::fmt; 664pub(crate) use std::fmt;
665 665
666impl std::io<|> for Foo { 666impl std::io$0 for Foo {
667} 667}
668 ", 668 ",
669 r" 669 r"
diff --git a/crates/assists/src/handlers/replace_string_with_char.rs b/crates/assists/src/handlers/replace_string_with_char.rs
index b4b898846..317318c24 100644
--- a/crates/assists/src/handlers/replace_string_with_char.rs
+++ b/crates/assists/src/handlers/replace_string_with_char.rs
@@ -8,7 +8,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
8// 8//
9// ``` 9// ```
10// fn main() { 10// fn main() {
11// find("{<|>"); 11// find("{$0");
12// } 12// }
13// ``` 13// ```
14// -> 14// ->
@@ -48,7 +48,7 @@ mod tests {
48 replace_string_with_char, 48 replace_string_with_char,
49 r#" 49 r#"
50 fn f() { 50 fn f() {
51 let s = "<|>c"; 51 let s = "$0c";
52 } 52 }
53 "#, 53 "#,
54 r#""c""#, 54 r#""c""#,
@@ -61,7 +61,7 @@ mod tests {
61 replace_string_with_char, 61 replace_string_with_char,
62 r#" 62 r#"
63 fn f() { 63 fn f() {
64 let s = "<|>c"; 64 let s = "$0c";
65 } 65 }
66 "#, 66 "#,
67 r##" 67 r##"
@@ -78,7 +78,7 @@ mod tests {
78 replace_string_with_char, 78 replace_string_with_char,
79 r#" 79 r#"
80 fn f() { 80 fn f() {
81 let s = "<|>😀"; 81 let s = "$0😀";
82 } 82 }
83 "#, 83 "#,
84 r##" 84 r##"
@@ -95,7 +95,7 @@ mod tests {
95 replace_string_with_char, 95 replace_string_with_char,
96 r#" 96 r#"
97 fn f() { 97 fn f() {
98 let s = "<|>test"; 98 let s = "$0test";
99 } 99 }
100 "#, 100 "#,
101 ) 101 )
@@ -107,7 +107,7 @@ mod tests {
107 replace_string_with_char, 107 replace_string_with_char,
108 r#" 108 r#"
109 fn f() { 109 fn f() {
110 format!(<|>"x", 92) 110 format!($0"x", 92)
111 } 111 }
112 "#, 112 "#,
113 r##" 113 r##"
@@ -124,7 +124,7 @@ mod tests {
124 replace_string_with_char, 124 replace_string_with_char,
125 r#" 125 r#"
126 fn f() { 126 fn f() {
127 find(<|>"x"); 127 find($0"x");
128 } 128 }
129 "#, 129 "#,
130 r##" 130 r##"
diff --git a/crates/assists/src/handlers/replace_unwrap_with_match.rs b/crates/assists/src/handlers/replace_unwrap_with_match.rs
index f547066f0..a986a6ae8 100644
--- a/crates/assists/src/handlers/replace_unwrap_with_match.rs
+++ b/crates/assists/src/handlers/replace_unwrap_with_match.rs
@@ -23,7 +23,7 @@ use ide_db::ty_filter::TryEnum;
23// enum Result<T, E> { Ok(T), Err(E) } 23// enum Result<T, E> { Ok(T), Err(E) }
24// fn main() { 24// fn main() {
25// let x: Result<i32, i32> = Result::Ok(92); 25// let x: Result<i32, i32> = Result::Ok(92);
26// let y = x.<|>unwrap(); 26// let y = x.$0unwrap();
27// } 27// }
28// ``` 28// ```
29// -> 29// ->
@@ -101,7 +101,7 @@ enum Result<T, E> { Ok(T), Err(E) }
101fn i<T>(a: T) -> T { a } 101fn i<T>(a: T) -> T { a }
102fn main() { 102fn main() {
103 let x: Result<i32, i32> = Result::Ok(92); 103 let x: Result<i32, i32> = Result::Ok(92);
104 let y = i(x).<|>unwrap(); 104 let y = i(x).$0unwrap();
105} 105}
106 ", 106 ",
107 r" 107 r"
@@ -127,7 +127,7 @@ enum Option<T> { Some(T), None }
127fn i<T>(a: T) -> T { a } 127fn i<T>(a: T) -> T { a }
128fn main() { 128fn main() {
129 let x = Option::Some(92); 129 let x = Option::Some(92);
130 let y = i(x).<|>unwrap(); 130 let y = i(x).$0unwrap();
131} 131}
132 ", 132 ",
133 r" 133 r"
@@ -153,7 +153,7 @@ enum Result<T, E> { Ok(T), Err(E) }
153fn i<T>(a: T) -> T { a } 153fn i<T>(a: T) -> T { a }
154fn main() { 154fn main() {
155 let x: Result<i32, i32> = Result::Ok(92); 155 let x: Result<i32, i32> = Result::Ok(92);
156 let y = i(x).<|>unwrap().count_zeroes(); 156 let y = i(x).$0unwrap().count_zeroes();
157} 157}
158 ", 158 ",
159 r" 159 r"
@@ -179,7 +179,7 @@ enum Option<T> { Some(T), None }
179fn i<T>(a: T) -> T { a } 179fn i<T>(a: T) -> T { a }
180fn main() { 180fn main() {
181 let x = Option::Some(92); 181 let x = Option::Some(92);
182 let y = i(x).<|>unwrap(); 182 let y = i(x).$0unwrap();
183} 183}
184 ", 184 ",
185 r"i(x).unwrap()", 185 r"i(x).unwrap()",
diff --git a/crates/assists/src/handlers/split_import.rs b/crates/assists/src/handlers/split_import.rs
index ef1f6b8a1..9319a4267 100644
--- a/crates/assists/src/handlers/split_import.rs
+++ b/crates/assists/src/handlers/split_import.rs
@@ -9,7 +9,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
9// Wraps the tail of import into braces. 9// Wraps the tail of import into braces.
10// 10//
11// ``` 11// ```
12// use std::<|>collections::HashMap; 12// use std::$0collections::HashMap;
13// ``` 13// ```
14// -> 14// ->
15// ``` 15// ```
@@ -43,7 +43,7 @@ mod tests {
43 fn test_split_import() { 43 fn test_split_import() {
44 check_assist( 44 check_assist(
45 split_import, 45 split_import,
46 "use crate::<|>db::RootDatabase;", 46 "use crate::$0db::RootDatabase;",
47 "use crate::{db::RootDatabase};", 47 "use crate::{db::RootDatabase};",
48 ) 48 )
49 } 49 }
@@ -52,19 +52,19 @@ mod tests {
52 fn split_import_works_with_trees() { 52 fn split_import_works_with_trees() {
53 check_assist( 53 check_assist(
54 split_import, 54 split_import,
55 "use crate:<|>:db::{RootDatabase, FileSymbol}", 55 "use crate:$0:db::{RootDatabase, FileSymbol}",
56 "use crate::{db::{RootDatabase, FileSymbol}}", 56 "use crate::{db::{RootDatabase, FileSymbol}}",
57 ) 57 )
58 } 58 }
59 59
60 #[test] 60 #[test]
61 fn split_import_target() { 61 fn split_import_target() {
62 check_assist_target(split_import, "use crate::<|>db::{RootDatabase, FileSymbol}", "::"); 62 check_assist_target(split_import, "use crate::$0db::{RootDatabase, FileSymbol}", "::");
63 } 63 }
64 64
65 #[test] 65 #[test]
66 fn issue4044() { 66 fn issue4044() {
67 check_assist_not_applicable(split_import, "use crate::<|>:::self;") 67 check_assist_not_applicable(split_import, "use crate::$0:::self;")
68 } 68 }
69 69
70 #[test] 70 #[test]
@@ -72,7 +72,7 @@ mod tests {
72 check_assist_not_applicable( 72 check_assist_not_applicable(
73 split_import, 73 split_import,
74 r" 74 r"
75use std::<|> 75use std::$0
76fn main() {}", 76fn main() {}",
77 ); 77 );
78 } 78 }
diff --git a/crates/assists/src/handlers/toggle_ignore.rs b/crates/assists/src/handlers/toggle_ignore.rs
index 14b420421..33e12a7d0 100644
--- a/crates/assists/src/handlers/toggle_ignore.rs
+++ b/crates/assists/src/handlers/toggle_ignore.rs
@@ -10,7 +10,7 @@ use crate::{utils::test_related_attribute, AssistContext, AssistId, AssistKind,
10// Adds `#[ignore]` attribute to the test. 10// Adds `#[ignore]` attribute to the test.
11// 11//
12// ``` 12// ```
13// <|>#[test] 13// $0#[test]
14// fn arithmetics { 14// fn arithmetics {
15// assert_eq!(2 + 2, 5); 15// assert_eq!(2 + 2, 5);
16// } 16// }
@@ -69,7 +69,7 @@ mod tests {
69 check_assist( 69 check_assist(
70 toggle_ignore, 70 toggle_ignore,
71 r#" 71 r#"
72 #[test<|>] 72 #[test$0]
73 fn test() {} 73 fn test() {}
74 "#, 74 "#,
75 r#" 75 r#"
@@ -85,7 +85,7 @@ mod tests {
85 check_assist( 85 check_assist(
86 toggle_ignore, 86 toggle_ignore,
87 r#" 87 r#"
88 #[test<|>] 88 #[test$0]
89 #[ignore] 89 #[ignore]
90 fn test() {} 90 fn test() {}
91 "#, 91 "#,
diff --git a/crates/assists/src/handlers/unwrap_block.rs b/crates/assists/src/handlers/unwrap_block.rs
index 676db7137..ed6f6177d 100644
--- a/crates/assists/src/handlers/unwrap_block.rs
+++ b/crates/assists/src/handlers/unwrap_block.rs
@@ -14,7 +14,7 @@ use crate::{utils::unwrap_trivial_block, AssistContext, AssistId, AssistKind, As
14// 14//
15// ``` 15// ```
16// fn foo() { 16// fn foo() {
17// if true {<|> 17// if true {$0
18// println!("foo"); 18// println!("foo");
19// } 19// }
20// } 20// }
@@ -124,7 +124,7 @@ mod tests {
124 unwrap_block, 124 unwrap_block,
125 r#" 125 r#"
126fn main() { 126fn main() {
127 <|>{ 127 $0{
128 92 128 92
129 } 129 }
130} 130}
@@ -143,7 +143,7 @@ fn main() {
143 unwrap_block, 143 unwrap_block,
144 r#" 144 r#"
145fn main() { 145fn main() {
146 <|>{ 146 $0{
147 92; 147 92;
148 } 148 }
149 () 149 ()
@@ -161,7 +161,7 @@ fn main() {
161 unwrap_block, 161 unwrap_block,
162 r#" 162 r#"
163fn main() { 163fn main() {
164 <|>{ 164 $0{
165 92 165 92
166 } 166 }
167 () 167 ()
@@ -183,7 +183,7 @@ fn main() {
183 r#" 183 r#"
184fn main() { 184fn main() {
185 bar(); 185 bar();
186 if true {<|> 186 if true {$0
187 foo(); 187 foo();
188 188
189 //comment 189 //comment
@@ -217,7 +217,7 @@ fn main() {
217 217
218 //comment 218 //comment
219 bar(); 219 bar();
220 } else {<|> 220 } else {$0
221 println!("bar"); 221 println!("bar");
222 } 222 }
223} 223}
@@ -249,7 +249,7 @@ fn main() {
249 249
250 //comment 250 //comment
251 //bar(); 251 //bar();
252 } else if false {<|> 252 } else if false {$0
253 println!("bar"); 253 println!("bar");
254 } else { 254 } else {
255 println!("foo"); 255 println!("foo");
@@ -285,7 +285,7 @@ fn main() {
285 //bar(); 285 //bar();
286 } else if false { 286 } else if false {
287 println!("bar"); 287 println!("bar");
288 } else if true {<|> 288 } else if true {$0
289 println!("foo"); 289 println!("foo");
290 } 290 }
291} 291}
@@ -323,7 +323,7 @@ fn main() {
323 println!("bar"); 323 println!("bar");
324 } else if true { 324 } else if true {
325 println!("foo"); 325 println!("foo");
326 } else {<|> 326 } else {$0
327 println!("else"); 327 println!("else");
328 } 328 }
329} 329}
@@ -361,7 +361,7 @@ fn main() {
361 //bar(); 361 //bar();
362 } else if false { 362 } else if false {
363 println!("bar"); 363 println!("bar");
364 } else if true {<|> 364 } else if true {$0
365 println!("foo"); 365 println!("foo");
366 } else { 366 } else {
367 println!("else"); 367 println!("else");
@@ -391,7 +391,7 @@ fn main() {
391 unwrap_block, 391 unwrap_block,
392 r#" 392 r#"
393fn main() { 393fn main() {
394 bar();<|> 394 bar();$0
395 if true { 395 if true {
396 foo(); 396 foo();
397 397
@@ -411,7 +411,7 @@ fn main() {
411 unwrap_block, 411 unwrap_block,
412 r#" 412 r#"
413fn main() { 413fn main() {
414 for i in 0..5 {<|> 414 for i in 0..5 {$0
415 if true { 415 if true {
416 foo(); 416 foo();
417 417
@@ -445,7 +445,7 @@ fn main() {
445 r#" 445 r#"
446fn main() { 446fn main() {
447 for i in 0..5 { 447 for i in 0..5 {
448 if true {<|> 448 if true {$0
449 foo(); 449 foo();
450 450
451 //comment 451 //comment
@@ -475,7 +475,7 @@ fn main() {
475 unwrap_block, 475 unwrap_block,
476 r#" 476 r#"
477fn main() { 477fn main() {
478 loop {<|> 478 loop {$0
479 if true { 479 if true {
480 foo(); 480 foo();
481 481
@@ -508,7 +508,7 @@ fn main() {
508 unwrap_block, 508 unwrap_block,
509 r#" 509 r#"
510fn main() { 510fn main() {
511 while true {<|> 511 while true {$0
512 if true { 512 if true {
513 foo(); 513 foo();
514 514
@@ -542,7 +542,7 @@ fn main() {
542 r#" 542 r#"
543fn main() { 543fn main() {
544 match rel_path { 544 match rel_path {
545 Ok(rel_path) => {<|> 545 Ok(rel_path) => {$0
546 let rel_path = RelativePathBuf::from_path(rel_path).ok()?; 546 let rel_path = RelativePathBuf::from_path(rel_path).ok()?;
547 Some((*id, rel_path)) 547 Some((*id, rel_path))
548 } 548 }
@@ -567,7 +567,7 @@ fn main() {
567fn main() { 567fn main() {
568 while true { 568 while true {
569 if true { 569 if true {
570 foo();<|> 570 foo();$0
571 571
572 //comment 572 //comment
573 bar(); 573 bar();
diff --git a/crates/assists/src/handlers/wrap_return_type_in_result.rs b/crates/assists/src/handlers/wrap_return_type_in_result.rs
index 59e5debb1..fec16fc49 100644
--- a/crates/assists/src/handlers/wrap_return_type_in_result.rs
+++ b/crates/assists/src/handlers/wrap_return_type_in_result.rs
@@ -13,7 +13,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
13// Wrap the function's return type into Result. 13// Wrap the function's return type into Result.
14// 14//
15// ``` 15// ```
16// fn foo() -> i32<|> { 42i32 } 16// fn foo() -> i32$0 { 42i32 }
17// ``` 17// ```
18// -> 18// ->
19// ``` 19// ```
@@ -98,7 +98,7 @@ impl TailReturnCollector {
98 } 98 }
99 99
100 // Browse tail expressions for each block 100 // Browse tail expressions for each block
101 if let Some(expr) = block_expr.expr() { 101 if let Some(expr) = block_expr.tail_expr() {
102 if let Some(last_exprs) = get_tail_expr_from_block(&expr) { 102 if let Some(last_exprs) = get_tail_expr_from_block(&expr) {
103 for last_expr in last_exprs { 103 for last_expr in last_exprs {
104 let last_expr = match last_expr { 104 let last_expr = match last_expr {
@@ -170,7 +170,7 @@ impl TailReturnCollector {
170 } 170 }
171 171
172 fn collect_tail_exprs(&mut self, block: &BlockExpr) { 172 fn collect_tail_exprs(&mut self, block: &BlockExpr) {
173 if let Some(expr) = block.expr() { 173 if let Some(expr) = block.tail_expr() {
174 self.handle_exprs(&expr, true); 174 self.handle_exprs(&expr, true);
175 self.fetch_tail_exprs(&expr); 175 self.fetch_tail_exprs(&expr);
176 } 176 }
@@ -206,7 +206,7 @@ fn get_tail_expr_from_block(expr: &Expr) -> Option<Vec<NodeType>> {
206 Expr::IfExpr(if_expr) => { 206 Expr::IfExpr(if_expr) => {
207 let mut nodes = vec![]; 207 let mut nodes = vec![];
208 for block in if_expr.blocks() { 208 for block in if_expr.blocks() {
209 if let Some(block_expr) = block.expr() { 209 if let Some(block_expr) = block.tail_expr() {
210 if let Some(tail_exprs) = get_tail_expr_from_block(&block_expr) { 210 if let Some(tail_exprs) = get_tail_expr_from_block(&block_expr) {
211 nodes.extend(tail_exprs); 211 nodes.extend(tail_exprs);
212 } 212 }
@@ -228,7 +228,7 @@ fn get_tail_expr_from_block(expr: &Expr) -> Option<Vec<NodeType>> {
228 while_expr.syntax().last_child().map(|lc| vec![NodeType::Node(lc)]) 228 while_expr.syntax().last_child().map(|lc| vec![NodeType::Node(lc)])
229 } 229 }
230 Expr::BlockExpr(block_expr) => { 230 Expr::BlockExpr(block_expr) => {
231 block_expr.expr().map(|lc| vec![NodeType::Node(lc.syntax().clone())]) 231 block_expr.tail_expr().map(|lc| vec![NodeType::Node(lc.syntax().clone())])
232 } 232 }
233 Expr::MatchExpr(match_expr) => { 233 Expr::MatchExpr(match_expr) => {
234 let arm_list = match_expr.match_arm_list()?; 234 let arm_list = match_expr.match_arm_list()?;
@@ -282,7 +282,7 @@ mod tests {
282 check_assist( 282 check_assist(
283 wrap_return_type_in_result, 283 wrap_return_type_in_result,
284 r#" 284 r#"
285fn foo() -> i3<|>2 { 285fn foo() -> i3$02 {
286 let test = "test"; 286 let test = "test";
287 return 42i32; 287 return 42i32;
288} 288}
@@ -302,7 +302,7 @@ fn foo() -> Result<i32, ${0:_}> {
302 wrap_return_type_in_result, 302 wrap_return_type_in_result,
303 r#" 303 r#"
304fn foo() { 304fn foo() {
305 || -> i32<|> { 305 || -> i32$0 {
306 let test = "test"; 306 let test = "test";
307 return 42i32; 307 return 42i32;
308 }; 308 };
@@ -325,7 +325,7 @@ fn foo() {
325 wrap_return_type_in_result, 325 wrap_return_type_in_result,
326 r#" 326 r#"
327fn foo() -> i32 { 327fn foo() -> i32 {
328 let test = "test";<|> 328 let test = "test";$0
329 return 42i32; 329 return 42i32;
330} 330}
331"#, 331"#,
@@ -339,7 +339,7 @@ fn foo() -> i32 {
339 r#" 339 r#"
340fn foo() { 340fn foo() {
341 || -> i32 { 341 || -> i32 {
342 let test = "test";<|> 342 let test = "test";$0
343 return 42i32; 343 return 42i32;
344 }; 344 };
345} 345}
@@ -349,7 +349,7 @@ fn foo() {
349 349
350 #[test] 350 #[test]
351 fn wrap_return_type_in_result_closure_non_block() { 351 fn wrap_return_type_in_result_closure_non_block() {
352 check_assist_not_applicable(wrap_return_type_in_result, r#"fn foo() { || -> i<|>32 3; }"#); 352 check_assist_not_applicable(wrap_return_type_in_result, r#"fn foo() { || -> i$032 3; }"#);
353 } 353 }
354 354
355 #[test] 355 #[test]
@@ -357,7 +357,7 @@ fn foo() {
357 check_assist_not_applicable( 357 check_assist_not_applicable(
358 wrap_return_type_in_result, 358 wrap_return_type_in_result,
359 r#" 359 r#"
360fn foo() -> std::result::Result<i32<|>, String> { 360fn foo() -> std::result::Result<i32$0, String> {
361 let test = "test"; 361 let test = "test";
362 return 42i32; 362 return 42i32;
363} 363}
@@ -371,7 +371,7 @@ fn foo() -> std::result::Result<i32<|>, String> {
371 check_assist_not_applicable( 371 check_assist_not_applicable(
372 wrap_return_type_in_result, 372 wrap_return_type_in_result,
373 r#" 373 r#"
374fn foo() -> Result<i32<|>, String> { 374fn foo() -> Result<i32$0, String> {
375 let test = "test"; 375 let test = "test";
376 return 42i32; 376 return 42i32;
377} 377}
@@ -385,7 +385,7 @@ fn foo() -> Result<i32<|>, String> {
385 wrap_return_type_in_result, 385 wrap_return_type_in_result,
386 r#" 386 r#"
387fn foo() { 387fn foo() {
388 || -> Result<i32<|>, String> { 388 || -> Result<i32$0, String> {
389 let test = "test"; 389 let test = "test";
390 return 42i32; 390 return 42i32;
391 }; 391 };
@@ -399,7 +399,7 @@ fn foo() {
399 check_assist( 399 check_assist(
400 wrap_return_type_in_result, 400 wrap_return_type_in_result,
401 r#" 401 r#"
402fn foo() -> <|>i32 { 402fn foo() -> $0i32 {
403 let test = "test"; 403 let test = "test";
404 return 42i32; 404 return 42i32;
405} 405}
@@ -418,7 +418,7 @@ fn foo() -> Result<i32, ${0:_}> {
418 check_assist( 418 check_assist(
419 wrap_return_type_in_result, 419 wrap_return_type_in_result,
420 r#" 420 r#"
421fn foo() -><|> i32 { 421fn foo() ->$0 i32 {
422 let test = "test"; 422 let test = "test";
423 42i32 423 42i32
424} 424}
@@ -438,7 +438,7 @@ fn foo() -> Result<i32, ${0:_}> {
438 wrap_return_type_in_result, 438 wrap_return_type_in_result,
439 r#" 439 r#"
440fn foo() { 440fn foo() {
441 || -><|> i32 { 441 || ->$0 i32 {
442 let test = "test"; 442 let test = "test";
443 42i32 443 42i32
444 }; 444 };
@@ -459,7 +459,7 @@ fn foo() {
459 fn wrap_return_type_in_result_simple_with_tail_only() { 459 fn wrap_return_type_in_result_simple_with_tail_only() {
460 check_assist( 460 check_assist(
461 wrap_return_type_in_result, 461 wrap_return_type_in_result,
462 r#"fn foo() -> i32<|> { 42i32 }"#, 462 r#"fn foo() -> i32$0 { 42i32 }"#,
463 r#"fn foo() -> Result<i32, ${0:_}> { Ok(42i32) }"#, 463 r#"fn foo() -> Result<i32, ${0:_}> { Ok(42i32) }"#,
464 ); 464 );
465 } 465 }
@@ -469,7 +469,7 @@ fn foo() {
469 check_assist( 469 check_assist(
470 wrap_return_type_in_result, 470 wrap_return_type_in_result,
471 r#" 471 r#"
472fn foo() -> i32<|> { 472fn foo() -> i32$0 {
473 if true { 473 if true {
474 42i32 474 42i32
475 } else { 475 } else {
@@ -495,7 +495,7 @@ fn foo() -> Result<i32, ${0:_}> {
495 wrap_return_type_in_result, 495 wrap_return_type_in_result,
496 r#" 496 r#"
497fn foo() { 497fn foo() {
498 || -> i32<|> { 498 || -> i32$0 {
499 if true { 499 if true {
500 42i32 500 42i32
501 } else { 501 } else {
@@ -523,7 +523,7 @@ fn foo() {
523 check_assist( 523 check_assist(
524 wrap_return_type_in_result, 524 wrap_return_type_in_result,
525 r#" 525 r#"
526fn foo() -> i32<|> { 526fn foo() -> i32$0 {
527 if true { 527 if true {
528 if false { 528 if false {
529 1 529 1
@@ -556,7 +556,7 @@ fn foo() -> Result<i32, ${0:_}> {
556 check_assist( 556 check_assist(
557 wrap_return_type_in_result, 557 wrap_return_type_in_result,
558 r#" 558 r#"
559async fn foo() -> i<|>32 { 559async fn foo() -> i$032 {
560 if true { 560 if true {
561 if false { 561 if false {
562 1.await 562 1.await
@@ -588,7 +588,7 @@ async fn foo() -> Result<i32, ${0:_}> {
588 fn wrap_return_type_in_result_simple_with_array() { 588 fn wrap_return_type_in_result_simple_with_array() {
589 check_assist( 589 check_assist(
590 wrap_return_type_in_result, 590 wrap_return_type_in_result,
591 r#"fn foo() -> [i32;<|> 3] { [1, 2, 3] }"#, 591 r#"fn foo() -> [i32;$0 3] { [1, 2, 3] }"#,
592 r#"fn foo() -> Result<[i32; 3], ${0:_}> { Ok([1, 2, 3]) }"#, 592 r#"fn foo() -> Result<[i32; 3], ${0:_}> { Ok([1, 2, 3]) }"#,
593 ); 593 );
594 } 594 }
@@ -598,7 +598,7 @@ async fn foo() -> Result<i32, ${0:_}> {
598 check_assist( 598 check_assist(
599 wrap_return_type_in_result, 599 wrap_return_type_in_result,
600 r#" 600 r#"
601fn foo() -<|>> i32 { 601fn foo() -$0> i32 {
602 if true { 602 if true {
603 if false { 603 if false {
604 1 as i32 604 1 as i32
@@ -631,7 +631,7 @@ fn foo() -> Result<i32, ${0:_}> {
631 check_assist( 631 check_assist(
632 wrap_return_type_in_result, 632 wrap_return_type_in_result,
633 r#" 633 r#"
634fn foo() -> i32<|> { 634fn foo() -> i32$0 {
635 let my_var = 5; 635 let my_var = 5;
636 match my_var { 636 match my_var {
637 5 => 42i32, 637 5 => 42i32,
@@ -656,7 +656,7 @@ fn foo() -> Result<i32, ${0:_}> {
656 check_assist( 656 check_assist(
657 wrap_return_type_in_result, 657 wrap_return_type_in_result,
658 r#" 658 r#"
659fn foo() -> i32<|> { 659fn foo() -> i32$0 {
660 let my_var = 5; 660 let my_var = 5;
661 loop { 661 loop {
662 println!("test"); 662 println!("test");
@@ -683,7 +683,7 @@ fn foo() -> Result<i32, ${0:_}> {
683 check_assist( 683 check_assist(
684 wrap_return_type_in_result, 684 wrap_return_type_in_result,
685 r#" 685 r#"
686fn foo() -> i32<|> { 686fn foo() -> i32$0 {
687 let my_var = let x = loop { 687 let my_var = let x = loop {
688 break 1; 688 break 1;
689 }; 689 };
@@ -706,7 +706,7 @@ fn foo() -> Result<i32, ${0:_}> {
706 check_assist( 706 check_assist(
707 wrap_return_type_in_result, 707 wrap_return_type_in_result,
708 r#" 708 r#"
709fn foo() -> i32<|> { 709fn foo() -> i32$0 {
710 let my_var = 5; 710 let my_var = 5;
711 let res = match my_var { 711 let res = match my_var {
712 5 => 42i32, 712 5 => 42i32,
@@ -730,7 +730,7 @@ fn foo() -> Result<i32, ${0:_}> {
730 check_assist( 730 check_assist(
731 wrap_return_type_in_result, 731 wrap_return_type_in_result,
732 r#" 732 r#"
733fn foo() -> i32<|> { 733fn foo() -> i32$0 {
734 let my_var = 5; 734 let my_var = 5;
735 let res = if my_var == 5 { 735 let res = if my_var == 5 {
736 42i32 736 42i32
@@ -759,7 +759,7 @@ fn foo() -> Result<i32, ${0:_}> {
759 check_assist( 759 check_assist(
760 wrap_return_type_in_result, 760 wrap_return_type_in_result,
761 r#" 761 r#"
762fn foo() -> i32<|> { 762fn foo() -> i32$0 {
763 let my_var = 5; 763 let my_var = 5;
764 match my_var { 764 match my_var {
765 5 => { 765 5 => {
@@ -808,7 +808,7 @@ fn foo() -> Result<i32, ${0:_}> {
808 check_assist( 808 check_assist(
809 wrap_return_type_in_result, 809 wrap_return_type_in_result,
810 r#" 810 r#"
811fn foo() -> i<|>32 { 811fn foo() -> i$032 {
812 let test = "test"; 812 let test = "test";
813 if test == "test" { 813 if test == "test" {
814 return 24i32; 814 return 24i32;
@@ -833,7 +833,7 @@ fn foo() -> Result<i32, ${0:_}> {
833 check_assist( 833 check_assist(
834 wrap_return_type_in_result, 834 wrap_return_type_in_result,
835 r#" 835 r#"
836fn foo(the_field: u32) -><|> u32 { 836fn foo(the_field: u32) ->$0 u32 {
837 let true_closure = || { return true; }; 837 let true_closure = || { return true; };
838 if the_field < 5 { 838 if the_field < 5 {
839 let mut i = 0; 839 let mut i = 0;
@@ -865,7 +865,7 @@ fn foo(the_field: u32) -> Result<u32, ${0:_}> {
865 check_assist( 865 check_assist(
866 wrap_return_type_in_result, 866 wrap_return_type_in_result,
867 r#" 867 r#"
868 fn foo(the_field: u32) -> u32<|> { 868 fn foo(the_field: u32) -> u32$0 {
869 let true_closure = || { 869 let true_closure = || {
870 return true; 870 return true;
871 }; 871 };
@@ -912,7 +912,7 @@ fn foo(the_field: u32) -> Result<u32, ${0:_}> {
912 check_assist( 912 check_assist(
913 wrap_return_type_in_result, 913 wrap_return_type_in_result,
914 r#" 914 r#"
915fn foo() -> i32<|> { 915fn foo() -> i32$0 {
916 let test = "test"; 916 let test = "test";
917 if test == "test" { 917 if test == "test" {
918 return 24i32; 918 return 24i32;
@@ -946,7 +946,7 @@ fn foo() -> Result<i32, ${0:_}> {
946 check_assist( 946 check_assist(
947 wrap_return_type_in_result, 947 wrap_return_type_in_result,
948 r#" 948 r#"
949fn foo() -> i32<|> { 949fn foo() -> i32$0 {
950 let test = "test"; 950 let test = "test";
951 if test == "test" { 951 if test == "test" {
952 return 24i32; 952 return 24i32;
@@ -984,7 +984,7 @@ fn foo() -> Result<i32, ${0:_}> {
984 check_assist( 984 check_assist(
985 wrap_return_type_in_result, 985 wrap_return_type_in_result,
986 r#" 986 r#"
987fn foo() -> i3<|>2 { 987fn foo() -> i3$02 {
988 let test = "test"; 988 let test = "test";
989 let other = 5; 989 let other = 5;
990 if test == "test" { 990 if test == "test" {
@@ -1030,7 +1030,7 @@ fn foo() -> Result<i32, ${0:_}> {
1030 check_assist( 1030 check_assist(
1031 wrap_return_type_in_result, 1031 wrap_return_type_in_result,
1032 r#" 1032 r#"
1033fn foo(the_field: u32) -> u32<|> { 1033fn foo(the_field: u32) -> u32$0 {
1034 if the_field < 5 { 1034 if the_field < 5 {
1035 let mut i = 0; 1035 let mut i = 0;
1036 loop { 1036 loop {
@@ -1070,7 +1070,7 @@ fn foo(the_field: u32) -> Result<u32, ${0:_}> {
1070 check_assist( 1070 check_assist(
1071 wrap_return_type_in_result, 1071 wrap_return_type_in_result,
1072 r#" 1072 r#"
1073fn foo(the_field: u32) -> u3<|>2 { 1073fn foo(the_field: u32) -> u3$02 {
1074 if the_field < 5 { 1074 if the_field < 5 {
1075 let mut i = 0; 1075 let mut i = 0;
1076 match i { 1076 match i {
@@ -1098,7 +1098,7 @@ fn foo(the_field: u32) -> Result<u32, ${0:_}> {
1098 check_assist( 1098 check_assist(
1099 wrap_return_type_in_result, 1099 wrap_return_type_in_result,
1100 r#" 1100 r#"
1101fn foo(the_field: u32) -> u32<|> { 1101fn foo(the_field: u32) -> u32$0 {
1102 if the_field < 5 { 1102 if the_field < 5 {
1103 let mut i = 0; 1103 let mut i = 0;
1104 if i == 5 { 1104 if i == 5 {
@@ -1128,7 +1128,7 @@ fn foo(the_field: u32) -> Result<u32, ${0:_}> {
1128 check_assist( 1128 check_assist(
1129 wrap_return_type_in_result, 1129 wrap_return_type_in_result,
1130 r#" 1130 r#"
1131fn foo(the_field: u32) -> <|>u32 { 1131fn foo(the_field: u32) -> $0u32 {
1132 if the_field < 5 { 1132 if the_field < 5 {
1133 let mut i = 0; 1133 let mut i = 0;
1134 if i == 5 { 1134 if i == 5 {
diff --git a/crates/assists/src/lib.rs b/crates/assists/src/lib.rs
index fdec886e9..1080294ab 100644
--- a/crates/assists/src/lib.rs
+++ b/crates/assists/src/lib.rs
@@ -24,7 +24,7 @@ use syntax::TextRange;
24 24
25pub(crate) use crate::assist_context::{AssistContext, Assists}; 25pub(crate) use crate::assist_context::{AssistContext, Assists};
26 26
27pub use assist_config::AssistConfig; 27pub use assist_config::{AssistConfig, InsertUseConfig};
28 28
29#[derive(Debug, Clone, Copy, PartialEq, Eq)] 29#[derive(Debug, Clone, Copy, PartialEq, Eq)]
30pub enum AssistKind { 30pub enum AssistKind {
@@ -116,7 +116,6 @@ mod handlers {
116 mod convert_integer_literal; 116 mod convert_integer_literal;
117 mod early_return; 117 mod early_return;
118 mod expand_glob_import; 118 mod expand_glob_import;
119 mod extract_module_to_file;
120 mod extract_struct_from_enum_variant; 119 mod extract_struct_from_enum_variant;
121 mod extract_variable; 120 mod extract_variable;
122 mod fill_match_arms; 121 mod fill_match_arms;
@@ -124,13 +123,14 @@ mod handlers {
124 mod flip_binexpr; 123 mod flip_binexpr;
125 mod flip_comma; 124 mod flip_comma;
126 mod flip_trait_bound; 125 mod flip_trait_bound;
127 mod generate_derive;
128 mod generate_default_from_enum_variant; 126 mod generate_default_from_enum_variant;
127 mod generate_derive;
129 mod generate_from_impl_for_enum; 128 mod generate_from_impl_for_enum;
130 mod generate_function; 129 mod generate_function;
131 mod generate_impl; 130 mod generate_impl;
132 mod generate_new; 131 mod generate_new;
133 mod infer_function_return_type; 132 mod infer_function_return_type;
133 mod inline_function;
134 mod inline_local_variable; 134 mod inline_local_variable;
135 mod introduce_named_lifetime; 135 mod introduce_named_lifetime;
136 mod invert_if; 136 mod invert_if;
@@ -138,12 +138,15 @@ mod handlers {
138 mod merge_match_arms; 138 mod merge_match_arms;
139 mod move_bounds; 139 mod move_bounds;
140 mod move_guard; 140 mod move_guard;
141 mod move_module_to_file;
142 mod pull_assignment_up;
141 mod qualify_path; 143 mod qualify_path;
142 mod raw_string; 144 mod raw_string;
143 mod remove_dbg; 145 mod remove_dbg;
144 mod remove_mut; 146 mod remove_mut;
145 mod remove_unused_param; 147 mod remove_unused_param;
146 mod reorder_fields; 148 mod reorder_fields;
149 mod reorder_impl;
147 mod replace_derive_with_manual_impl; 150 mod replace_derive_with_manual_impl;
148 mod replace_if_let_with_match; 151 mod replace_if_let_with_match;
149 mod replace_impl_trait_with_generic; 152 mod replace_impl_trait_with_generic;
@@ -167,7 +170,7 @@ mod handlers {
167 convert_integer_literal::convert_integer_literal, 170 convert_integer_literal::convert_integer_literal,
168 early_return::convert_to_guarded_return, 171 early_return::convert_to_guarded_return,
169 expand_glob_import::expand_glob_import, 172 expand_glob_import::expand_glob_import,
170 extract_module_to_file::extract_module_to_file, 173 move_module_to_file::move_module_to_file,
171 extract_struct_from_enum_variant::extract_struct_from_enum_variant, 174 extract_struct_from_enum_variant::extract_struct_from_enum_variant,
172 extract_variable::extract_variable, 175 extract_variable::extract_variable,
173 fill_match_arms::fill_match_arms, 176 fill_match_arms::fill_match_arms,
@@ -175,13 +178,14 @@ mod handlers {
175 flip_binexpr::flip_binexpr, 178 flip_binexpr::flip_binexpr,
176 flip_comma::flip_comma, 179 flip_comma::flip_comma,
177 flip_trait_bound::flip_trait_bound, 180 flip_trait_bound::flip_trait_bound,
178 generate_derive::generate_derive,
179 generate_default_from_enum_variant::generate_default_from_enum_variant, 181 generate_default_from_enum_variant::generate_default_from_enum_variant,
182 generate_derive::generate_derive,
180 generate_from_impl_for_enum::generate_from_impl_for_enum, 183 generate_from_impl_for_enum::generate_from_impl_for_enum,
181 generate_function::generate_function, 184 generate_function::generate_function,
182 generate_impl::generate_impl, 185 generate_impl::generate_impl,
183 generate_new::generate_new, 186 generate_new::generate_new,
184 infer_function_return_type::infer_function_return_type, 187 infer_function_return_type::infer_function_return_type,
188 inline_function::inline_function,
185 inline_local_variable::inline_local_variable, 189 inline_local_variable::inline_local_variable,
186 introduce_named_lifetime::introduce_named_lifetime, 190 introduce_named_lifetime::introduce_named_lifetime,
187 invert_if::invert_if, 191 invert_if::invert_if,
@@ -190,6 +194,7 @@ mod handlers {
190 move_bounds::move_bounds_to_where_clause, 194 move_bounds::move_bounds_to_where_clause,
191 move_guard::move_arm_cond_to_match_guard, 195 move_guard::move_arm_cond_to_match_guard,
192 move_guard::move_guard_to_arm_body, 196 move_guard::move_guard_to_arm_body,
197 pull_assignment_up::pull_assignment_up,
193 qualify_path::qualify_path, 198 qualify_path::qualify_path,
194 raw_string::add_hash, 199 raw_string::add_hash,
195 raw_string::make_usual_string, 200 raw_string::make_usual_string,
@@ -198,6 +203,7 @@ mod handlers {
198 remove_mut::remove_mut, 203 remove_mut::remove_mut,
199 remove_unused_param::remove_unused_param, 204 remove_unused_param::remove_unused_param,
200 reorder_fields::reorder_fields, 205 reorder_fields::reorder_fields,
206 reorder_impl::reorder_impl,
201 replace_derive_with_manual_impl::replace_derive_with_manual_impl, 207 replace_derive_with_manual_impl::replace_derive_with_manual_impl,
202 replace_if_let_with_match::replace_if_let_with_match, 208 replace_if_let_with_match::replace_if_let_with_match,
203 replace_if_let_with_match::replace_match_with_if_let, 209 replace_if_let_with_match::replace_match_with_if_let,
diff --git a/crates/assists/src/tests.rs b/crates/assists/src/tests.rs
index 21e448fb8..fef29a0b8 100644
--- a/crates/assists/src/tests.rs
+++ b/crates/assists/src/tests.rs
@@ -1,15 +1,29 @@
1mod generated; 1mod generated;
2 2
3use hir::Semantics; 3use hir::Semantics;
4use ide_db::base_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt}; 4use ide_db::{
5use ide_db::source_change::FileSystemEdit; 5 base_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt},
6use ide_db::RootDatabase; 6 helpers::{insert_use::MergeBehavior, SnippetCap},
7 source_change::FileSystemEdit,
8 RootDatabase,
9};
7use syntax::TextRange; 10use syntax::TextRange;
8use test_utils::{assert_eq_text, extract_offset, extract_range}; 11use test_utils::{assert_eq_text, extract_offset, extract_range};
9 12
10use crate::{handlers::Handler, Assist, AssistConfig, AssistContext, AssistKind, Assists}; 13use crate::{
14 handlers::Handler, Assist, AssistConfig, AssistContext, AssistKind, Assists, InsertUseConfig,
15};
11use stdx::{format_to, trim_indent}; 16use stdx::{format_to, trim_indent};
12 17
18pub(crate) const TEST_CONFIG: AssistConfig = AssistConfig {
19 snippet_cap: SnippetCap::new(true),
20 allowed: None,
21 insert_use: InsertUseConfig {
22 merge: Some(MergeBehavior::Full),
23 prefix_kind: hir::PrefixKind::Plain,
24 },
25};
26
13pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) { 27pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) {
14 RootDatabase::with_single_file(text) 28 RootDatabase::with_single_file(text)
15} 29}
@@ -48,14 +62,14 @@ fn check_doc_test(assist_id: &str, before: &str, after: &str) {
48 let before = db.file_text(file_id).to_string(); 62 let before = db.file_text(file_id).to_string();
49 let frange = FileRange { file_id, range: selection.into() }; 63 let frange = FileRange { file_id, range: selection.into() };
50 64
51 let assist = Assist::get(&db, &AssistConfig::default(), true, frange) 65 let assist = Assist::get(&db, &TEST_CONFIG, true, frange)
52 .into_iter() 66 .into_iter()
53 .find(|assist| assist.id.0 == assist_id) 67 .find(|assist| assist.id.0 == assist_id)
54 .unwrap_or_else(|| { 68 .unwrap_or_else(|| {
55 panic!( 69 panic!(
56 "\n\nAssist is not applicable: {}\nAvailable assists: {}", 70 "\n\nAssist is not applicable: {}\nAvailable assists: {}",
57 assist_id, 71 assist_id,
58 Assist::get(&db, &AssistConfig::default(), false, frange) 72 Assist::get(&db, &TEST_CONFIG, false, frange)
59 .into_iter() 73 .into_iter()
60 .map(|assist| assist.id.0) 74 .map(|assist| assist.id.0)
61 .collect::<Vec<_>>() 75 .collect::<Vec<_>>()
@@ -89,7 +103,7 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult, assist_label:
89 let frange = FileRange { file_id: file_with_caret_id, range: range_or_offset.into() }; 103 let frange = FileRange { file_id: file_with_caret_id, range: range_or_offset.into() };
90 104
91 let sema = Semantics::new(&db); 105 let sema = Semantics::new(&db);
92 let config = AssistConfig::default(); 106 let config = TEST_CONFIG;
93 let ctx = AssistContext::new(sema, &config, frange); 107 let ctx = AssistContext::new(sema, &config, frange);
94 let mut acc = Assists::new(&ctx, true); 108 let mut acc = Assists::new(&ctx, true);
95 handler(&mut acc, &ctx); 109 handler(&mut acc, &ctx);
@@ -152,11 +166,11 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult, assist_label:
152 166
153#[test] 167#[test]
154fn assist_order_field_struct() { 168fn assist_order_field_struct() {
155 let before = "struct Foo { <|>bar: u32 }"; 169 let before = "struct Foo { $0bar: u32 }";
156 let (before_cursor_pos, before) = extract_offset(before); 170 let (before_cursor_pos, before) = extract_offset(before);
157 let (db, file_id) = with_single_file(&before); 171 let (db, file_id) = with_single_file(&before);
158 let frange = FileRange { file_id, range: TextRange::empty(before_cursor_pos) }; 172 let frange = FileRange { file_id, range: TextRange::empty(before_cursor_pos) };
159 let assists = Assist::get(&db, &AssistConfig::default(), false, frange); 173 let assists = Assist::get(&db, &TEST_CONFIG, false, frange);
160 let mut assists = assists.iter(); 174 let mut assists = assists.iter();
161 175
162 assert_eq!(assists.next().expect("expected assist").label, "Change visibility to pub(crate)"); 176 assert_eq!(assists.next().expect("expected assist").label, "Change visibility to pub(crate)");
@@ -167,7 +181,7 @@ fn assist_order_field_struct() {
167fn assist_order_if_expr() { 181fn assist_order_if_expr() {
168 let before = " 182 let before = "
169 pub fn test_some_range(a: int) -> bool { 183 pub fn test_some_range(a: int) -> bool {
170 if let 2..6 = <|>5<|> { 184 if let 2..6 = $05$0 {
171 true 185 true
172 } else { 186 } else {
173 false 187 false
@@ -176,7 +190,7 @@ fn assist_order_if_expr() {
176 let (range, before) = extract_range(before); 190 let (range, before) = extract_range(before);
177 let (db, file_id) = with_single_file(&before); 191 let (db, file_id) = with_single_file(&before);
178 let frange = FileRange { file_id, range }; 192 let frange = FileRange { file_id, range };
179 let assists = Assist::get(&db, &AssistConfig::default(), false, frange); 193 let assists = Assist::get(&db, &TEST_CONFIG, false, frange);
180 let mut assists = assists.iter(); 194 let mut assists = assists.iter();
181 195
182 assert_eq!(assists.next().expect("expected assist").label, "Extract into variable"); 196 assert_eq!(assists.next().expect("expected assist").label, "Extract into variable");
@@ -187,7 +201,7 @@ fn assist_order_if_expr() {
187fn assist_filter_works() { 201fn assist_filter_works() {
188 let before = " 202 let before = "
189 pub fn test_some_range(a: int) -> bool { 203 pub fn test_some_range(a: int) -> bool {
190 if let 2..6 = <|>5<|> { 204 if let 2..6 = $05$0 {
191 true 205 true
192 } else { 206 } else {
193 false 207 false
@@ -198,7 +212,7 @@ fn assist_filter_works() {
198 let frange = FileRange { file_id, range }; 212 let frange = FileRange { file_id, range };
199 213
200 { 214 {
201 let mut cfg = AssistConfig::default(); 215 let mut cfg = TEST_CONFIG;
202 cfg.allowed = Some(vec![AssistKind::Refactor]); 216 cfg.allowed = Some(vec![AssistKind::Refactor]);
203 217
204 let assists = Assist::get(&db, &cfg, false, frange); 218 let assists = Assist::get(&db, &cfg, false, frange);
@@ -209,7 +223,7 @@ fn assist_filter_works() {
209 } 223 }
210 224
211 { 225 {
212 let mut cfg = AssistConfig::default(); 226 let mut cfg = TEST_CONFIG;
213 cfg.allowed = Some(vec![AssistKind::RefactorExtract]); 227 cfg.allowed = Some(vec![AssistKind::RefactorExtract]);
214 let assists = Assist::get(&db, &cfg, false, frange); 228 let assists = Assist::get(&db, &cfg, false, frange);
215 assert_eq!(assists.len(), 1); 229 assert_eq!(assists.len(), 1);
@@ -219,7 +233,7 @@ fn assist_filter_works() {
219 } 233 }
220 234
221 { 235 {
222 let mut cfg = AssistConfig::default(); 236 let mut cfg = TEST_CONFIG;
223 cfg.allowed = Some(vec![AssistKind::QuickFix]); 237 cfg.allowed = Some(vec![AssistKind::QuickFix]);
224 let assists = Assist::get(&db, &cfg, false, frange); 238 let assists = Assist::get(&db, &cfg, false, frange);
225 assert!(assists.is_empty(), "All asserts but quickfixes should be filtered out"); 239 assert!(assists.is_empty(), "All asserts but quickfixes should be filtered out");
diff --git a/crates/assists/src/tests/generated.rs b/crates/assists/src/tests/generated.rs
index d3dfe24e7..217f577eb 100644
--- a/crates/assists/src/tests/generated.rs
+++ b/crates/assists/src/tests/generated.rs
@@ -8,7 +8,7 @@ fn doctest_add_explicit_type() {
8 "add_explicit_type", 8 "add_explicit_type",
9 r#####" 9 r#####"
10fn main() { 10fn main() {
11 let x<|> = 92; 11 let x$0 = 92;
12} 12}
13"#####, 13"#####,
14 r#####" 14 r#####"
@@ -25,7 +25,7 @@ fn doctest_add_hash() {
25 "add_hash", 25 "add_hash",
26 r#####" 26 r#####"
27fn main() { 27fn main() {
28 r#"Hello,<|> World!"#; 28 r#"Hello,$0 World!"#;
29} 29}
30"#####, 30"#####,
31 r#####" 31 r#####"
@@ -49,7 +49,7 @@ trait Trait {
49 49
50impl Trait for () { 50impl Trait for () {
51 type X = (); 51 type X = ();
52 fn foo(&self) {}<|> 52 fn foo(&self) {}$0
53 53
54} 54}
55"#####, 55"#####,
@@ -81,7 +81,7 @@ trait Trait<T> {
81 fn bar(&self) {} 81 fn bar(&self) {}
82} 82}
83 83
84impl Trait<u32> for () {<|> 84impl Trait<u32> for () {$0
85 85
86} 86}
87"#####, 87"#####,
@@ -110,7 +110,7 @@ fn doctest_add_turbo_fish() {
110 r#####" 110 r#####"
111fn make<T>() -> T { todo!() } 111fn make<T>() -> T { todo!() }
112fn main() { 112fn main() {
113 let x = make<|>(); 113 let x = make$0();
114} 114}
115"#####, 115"#####,
116 r#####" 116 r#####"
@@ -128,7 +128,7 @@ fn doctest_apply_demorgan() {
128 "apply_demorgan", 128 "apply_demorgan",
129 r#####" 129 r#####"
130fn main() { 130fn main() {
131 if x != 4 ||<|> !y {} 131 if x != 4 ||$0 !y {}
132} 132}
133"#####, 133"#####,
134 r#####" 134 r#####"
@@ -145,7 +145,7 @@ fn doctest_auto_import() {
145 "auto_import", 145 "auto_import",
146 r#####" 146 r#####"
147fn main() { 147fn main() {
148 let map = HashMap<|>::new(); 148 let map = HashMap$0::new();
149} 149}
150pub mod std { pub mod collections { pub struct HashMap { } } } 150pub mod std { pub mod collections { pub struct HashMap { } } }
151"#####, 151"#####,
@@ -165,7 +165,7 @@ fn doctest_change_visibility() {
165 check_doc_test( 165 check_doc_test(
166 "change_visibility", 166 "change_visibility",
167 r#####" 167 r#####"
168<|>fn frobnicate() {} 168$0fn frobnicate() {}
169"#####, 169"#####,
170 r#####" 170 r#####"
171pub(crate) fn frobnicate() {} 171pub(crate) fn frobnicate() {}
@@ -178,7 +178,7 @@ fn doctest_convert_integer_literal() {
178 check_doc_test( 178 check_doc_test(
179 "convert_integer_literal", 179 "convert_integer_literal",
180 r#####" 180 r#####"
181const _: i32 = 10<|>; 181const _: i32 = 10$0;
182"#####, 182"#####,
183 r#####" 183 r#####"
184const _: i32 = 0b1010; 184const _: i32 = 0b1010;
@@ -192,7 +192,7 @@ fn doctest_convert_to_guarded_return() {
192 "convert_to_guarded_return", 192 "convert_to_guarded_return",
193 r#####" 193 r#####"
194fn main() { 194fn main() {
195 <|>if cond { 195 $0if cond {
196 foo(); 196 foo();
197 bar(); 197 bar();
198 } 198 }
@@ -220,7 +220,7 @@ mod foo {
220 pub struct Baz; 220 pub struct Baz;
221} 221}
222 222
223use foo::*<|>; 223use foo::*$0;
224 224
225fn qux(bar: Bar, baz: Baz) {} 225fn qux(bar: Bar, baz: Baz) {}
226"#####, 226"#####,
@@ -238,26 +238,11 @@ fn qux(bar: Bar, baz: Baz) {}
238} 238}
239 239
240#[test] 240#[test]
241fn doctest_extract_module_to_file() {
242 check_doc_test(
243 "extract_module_to_file",
244 r#####"
245mod foo {<|>
246 fn t() {}
247}
248"#####,
249 r#####"
250mod foo;
251"#####,
252 )
253}
254
255#[test]
256fn doctest_extract_struct_from_enum_variant() { 241fn doctest_extract_struct_from_enum_variant() {
257 check_doc_test( 242 check_doc_test(
258 "extract_struct_from_enum_variant", 243 "extract_struct_from_enum_variant",
259 r#####" 244 r#####"
260enum A { <|>One(u32, u32) } 245enum A { $0One(u32, u32) }
261"#####, 246"#####,
262 r#####" 247 r#####"
263struct One(pub u32, pub u32); 248struct One(pub u32, pub u32);
@@ -273,7 +258,7 @@ fn doctest_extract_variable() {
273 "extract_variable", 258 "extract_variable",
274 r#####" 259 r#####"
275fn main() { 260fn main() {
276 <|>(1 + 2)<|> * 4; 261 $0(1 + 2)$0 * 4;
277} 262}
278"#####, 263"#####,
279 r#####" 264 r#####"
@@ -294,7 +279,7 @@ enum Action { Move { distance: u32 }, Stop }
294 279
295fn handle(action: Action) { 280fn handle(action: Action) {
296 match action { 281 match action {
297 <|> 282 $0
298 } 283 }
299} 284}
300"#####, 285"#####,
@@ -320,7 +305,7 @@ mod m {
320 fn frobnicate() {} 305 fn frobnicate() {}
321} 306}
322fn main() { 307fn main() {
323 m::frobnicate<|>() {} 308 m::frobnicate$0() {}
324} 309}
325"#####, 310"#####,
326 r#####" 311 r#####"
@@ -340,7 +325,7 @@ fn doctest_flip_binexpr() {
340 "flip_binexpr", 325 "flip_binexpr",
341 r#####" 326 r#####"
342fn main() { 327fn main() {
343 let _ = 90 +<|> 2; 328 let _ = 90 +$0 2;
344} 329}
345"#####, 330"#####,
346 r#####" 331 r#####"
@@ -357,7 +342,7 @@ fn doctest_flip_comma() {
357 "flip_comma", 342 "flip_comma",
358 r#####" 343 r#####"
359fn main() { 344fn main() {
360 ((1, 2),<|> (3, 4)); 345 ((1, 2),$0 (3, 4));
361} 346}
362"#####, 347"#####,
363 r#####" 348 r#####"
@@ -373,7 +358,7 @@ fn doctest_flip_trait_bound() {
373 check_doc_test( 358 check_doc_test(
374 "flip_trait_bound", 359 "flip_trait_bound",
375 r#####" 360 r#####"
376fn foo<T: Clone +<|> Copy>() { } 361fn foo<T: Clone +$0 Copy>() { }
377"#####, 362"#####,
378 r#####" 363 r#####"
379fn foo<T: Copy + Clone>() { } 364fn foo<T: Copy + Clone>() { }
@@ -388,7 +373,7 @@ fn doctest_generate_default_from_enum_variant() {
388 r#####" 373 r#####"
389enum Version { 374enum Version {
390 Undefined, 375 Undefined,
391 Minor<|>, 376 Minor$0,
392 Major, 377 Major,
393} 378}
394"#####, 379"#####,
@@ -415,7 +400,7 @@ fn doctest_generate_derive() {
415 r#####" 400 r#####"
416struct Point { 401struct Point {
417 x: u32, 402 x: u32,
418 y: u32,<|> 403 y: u32,$0
419} 404}
420"#####, 405"#####,
421 r#####" 406 r#####"
@@ -433,7 +418,7 @@ fn doctest_generate_from_impl_for_enum() {
433 check_doc_test( 418 check_doc_test(
434 "generate_from_impl_for_enum", 419 "generate_from_impl_for_enum",
435 r#####" 420 r#####"
436enum A { <|>One(u32) } 421enum A { $0One(u32) }
437"#####, 422"#####,
438 r#####" 423 r#####"
439enum A { One(u32) } 424enum A { One(u32) }
@@ -455,7 +440,7 @@ fn doctest_generate_function() {
455struct Baz; 440struct Baz;
456fn baz() -> Baz { Baz } 441fn baz() -> Baz { Baz }
457fn foo() { 442fn foo() {
458 bar<|>("", baz()); 443 bar$0("", baz());
459} 444}
460 445
461"#####, 446"#####,
@@ -480,7 +465,7 @@ fn doctest_generate_impl() {
480 "generate_impl", 465 "generate_impl",
481 r#####" 466 r#####"
482struct Ctx<T: Clone> { 467struct Ctx<T: Clone> {
483 data: T,<|> 468 data: T,$0
484} 469}
485"#####, 470"#####,
486 r#####" 471 r#####"
@@ -501,7 +486,7 @@ fn doctest_generate_new() {
501 "generate_new", 486 "generate_new",
502 r#####" 487 r#####"
503struct Ctx<T: Clone> { 488struct Ctx<T: Clone> {
504 data: T,<|> 489 data: T,$0
505} 490}
506"#####, 491"#####,
507 r#####" 492 r#####"
@@ -522,7 +507,7 @@ fn doctest_infer_function_return_type() {
522 check_doc_test( 507 check_doc_test(
523 "infer_function_return_type", 508 "infer_function_return_type",
524 r#####" 509 r#####"
525fn foo() { 4<|>2i32 } 510fn foo() { 4$02i32 }
526"#####, 511"#####,
527 r#####" 512 r#####"
528fn foo() -> i32 { 42i32 } 513fn foo() -> i32 { 42i32 }
@@ -531,12 +516,35 @@ fn foo() -> i32 { 42i32 }
531} 516}
532 517
533#[test] 518#[test]
519fn doctest_inline_function() {
520 check_doc_test(
521 "inline_function",
522 r#####"
523fn add(a: u32, b: u32) -> u32 { a + b }
524fn main() {
525 let x = add$0(1, 2);
526}
527"#####,
528 r#####"
529fn add(a: u32, b: u32) -> u32 { a + b }
530fn main() {
531 let x = {
532 let a = 1;
533 let b = 2;
534 a + b
535 };
536}
537"#####,
538 )
539}
540
541#[test]
534fn doctest_inline_local_variable() { 542fn doctest_inline_local_variable() {
535 check_doc_test( 543 check_doc_test(
536 "inline_local_variable", 544 "inline_local_variable",
537 r#####" 545 r#####"
538fn main() { 546fn main() {
539 let x<|> = 1 + 2; 547 let x$0 = 1 + 2;
540 x * 4; 548 x * 4;
541} 549}
542"#####, 550"#####,
@@ -553,7 +561,7 @@ fn doctest_introduce_named_lifetime() {
553 check_doc_test( 561 check_doc_test(
554 "introduce_named_lifetime", 562 "introduce_named_lifetime",
555 r#####" 563 r#####"
556impl Cursor<'_<|>> { 564impl Cursor<'_$0> {
557 fn node(self) -> &SyntaxNode { 565 fn node(self) -> &SyntaxNode {
558 match self { 566 match self {
559 Cursor::Replace(node) | Cursor::Before(node) => node, 567 Cursor::Replace(node) | Cursor::Before(node) => node,
@@ -579,7 +587,7 @@ fn doctest_invert_if() {
579 "invert_if", 587 "invert_if",
580 r#####" 588 r#####"
581fn main() { 589fn main() {
582 if<|> !y { A } else { B } 590 if$0 !y { A } else { B }
583} 591}
584"#####, 592"#####,
585 r#####" 593 r#####"
@@ -596,7 +604,7 @@ fn doctest_make_raw_string() {
596 "make_raw_string", 604 "make_raw_string",
597 r#####" 605 r#####"
598fn main() { 606fn main() {
599 "Hello,<|> World!"; 607 "Hello,$0 World!";
600} 608}
601"#####, 609"#####,
602 r#####" 610 r#####"
@@ -613,7 +621,7 @@ fn doctest_make_usual_string() {
613 "make_usual_string", 621 "make_usual_string",
614 r#####" 622 r#####"
615fn main() { 623fn main() {
616 r#"Hello,<|> "World!""#; 624 r#"Hello,$0 "World!""#;
617} 625}
618"#####, 626"#####,
619 r#####" 627 r#####"
@@ -629,7 +637,7 @@ fn doctest_merge_imports() {
629 check_doc_test( 637 check_doc_test(
630 "merge_imports", 638 "merge_imports",
631 r#####" 639 r#####"
632use std::<|>fmt::Formatter; 640use std::$0fmt::Formatter;
633use std::io; 641use std::io;
634"#####, 642"#####,
635 r#####" 643 r#####"
@@ -647,7 +655,7 @@ enum Action { Move { distance: u32 }, Stop }
647 655
648fn handle(action: Action) { 656fn handle(action: Action) {
649 match action { 657 match action {
650 <|>Action::Move(..) => foo(), 658 $0Action::Move(..) => foo(),
651 Action::Stop => foo(), 659 Action::Stop => foo(),
652 } 660 }
653} 661}
@@ -673,7 +681,7 @@ enum Action { Move { distance: u32 }, Stop }
673 681
674fn handle(action: Action) { 682fn handle(action: Action) {
675 match action { 683 match action {
676 Action::Move { distance } => <|>if distance > 10 { foo() }, 684 Action::Move { distance } => $0if distance > 10 { foo() },
677 _ => (), 685 _ => (),
678 } 686 }
679} 687}
@@ -696,7 +704,7 @@ fn doctest_move_bounds_to_where_clause() {
696 check_doc_test( 704 check_doc_test(
697 "move_bounds_to_where_clause", 705 "move_bounds_to_where_clause",
698 r#####" 706 r#####"
699fn apply<T, U, <|>F: FnOnce(T) -> U>(f: F, x: T) -> U { 707fn apply<T, U, $0F: FnOnce(T) -> U>(f: F, x: T) -> U {
700 f(x) 708 f(x)
701} 709}
702"#####, 710"#####,
@@ -717,7 +725,7 @@ enum Action { Move { distance: u32 }, Stop }
717 725
718fn handle(action: Action) { 726fn handle(action: Action) {
719 match action { 727 match action {
720 Action::Move { distance } <|>if distance > 10 => foo(), 728 Action::Move { distance } $0if distance > 10 => foo(),
721 _ => (), 729 _ => (),
722 } 730 }
723} 731}
@@ -738,12 +746,56 @@ fn handle(action: Action) {
738} 746}
739 747
740#[test] 748#[test]
749fn doctest_move_module_to_file() {
750 check_doc_test(
751 "move_module_to_file",
752 r#####"
753mod $0foo {
754 fn t() {}
755}
756"#####,
757 r#####"
758mod foo;
759"#####,
760 )
761}
762
763#[test]
764fn doctest_pull_assignment_up() {
765 check_doc_test(
766 "pull_assignment_up",
767 r#####"
768fn main() {
769 let mut foo = 6;
770
771 if true {
772 $0foo = 5;
773 } else {
774 foo = 4;
775 }
776}
777"#####,
778 r#####"
779fn main() {
780 let mut foo = 6;
781
782 foo = if true {
783 5
784 } else {
785 4
786 };
787}
788"#####,
789 )
790}
791
792#[test]
741fn doctest_qualify_path() { 793fn doctest_qualify_path() {
742 check_doc_test( 794 check_doc_test(
743 "qualify_path", 795 "qualify_path",
744 r#####" 796 r#####"
745fn main() { 797fn main() {
746 let map = HashMap<|>::new(); 798 let map = HashMap$0::new();
747} 799}
748pub mod std { pub mod collections { pub struct HashMap { } } } 800pub mod std { pub mod collections { pub struct HashMap { } } }
749"#####, 801"#####,
@@ -762,7 +814,7 @@ fn doctest_remove_dbg() {
762 "remove_dbg", 814 "remove_dbg",
763 r#####" 815 r#####"
764fn main() { 816fn main() {
765 <|>dbg!(92); 817 $0dbg!(92);
766} 818}
767"#####, 819"#####,
768 r#####" 820 r#####"
@@ -779,7 +831,7 @@ fn doctest_remove_hash() {
779 "remove_hash", 831 "remove_hash",
780 r#####" 832 r#####"
781fn main() { 833fn main() {
782 r#"Hello,<|> World!"#; 834 r#"Hello,$0 World!"#;
783} 835}
784"#####, 836"#####,
785 r#####" 837 r#####"
@@ -796,7 +848,7 @@ fn doctest_remove_mut() {
796 "remove_mut", 848 "remove_mut",
797 r#####" 849 r#####"
798impl Walrus { 850impl Walrus {
799 fn feed(&mut<|> self, amount: u32) {} 851 fn feed(&mut$0 self, amount: u32) {}
800} 852}
801"#####, 853"#####,
802 r#####" 854 r#####"
@@ -812,7 +864,7 @@ fn doctest_remove_unused_param() {
812 check_doc_test( 864 check_doc_test(
813 "remove_unused_param", 865 "remove_unused_param",
814 r#####" 866 r#####"
815fn frobnicate(x: i32<|>) {} 867fn frobnicate(x: i32$0) {}
816 868
817fn main() { 869fn main() {
818 frobnicate(92); 870 frobnicate(92);
@@ -834,7 +886,7 @@ fn doctest_reorder_fields() {
834 "reorder_fields", 886 "reorder_fields",
835 r#####" 887 r#####"
836struct Foo {foo: i32, bar: i32}; 888struct Foo {foo: i32, bar: i32};
837const test: Foo = <|>Foo {bar: 0, foo: 1} 889const test: Foo = $0Foo {bar: 0, foo: 1}
838"#####, 890"#####,
839 r#####" 891 r#####"
840struct Foo {foo: i32, bar: i32}; 892struct Foo {foo: i32, bar: i32};
@@ -844,12 +896,47 @@ const test: Foo = Foo {foo: 1, bar: 0}
844} 896}
845 897
846#[test] 898#[test]
899fn doctest_reorder_impl() {
900 check_doc_test(
901 "reorder_impl",
902 r#####"
903trait Foo {
904 fn a() {}
905 fn b() {}
906 fn c() {}
907}
908
909struct Bar;
910$0impl Foo for Bar {
911 fn b() {}
912 fn c() {}
913 fn a() {}
914}
915"#####,
916 r#####"
917trait Foo {
918 fn a() {}
919 fn b() {}
920 fn c() {}
921}
922
923struct Bar;
924impl Foo for Bar {
925 fn a() {}
926 fn b() {}
927 fn c() {}
928}
929"#####,
930 )
931}
932
933#[test]
847fn doctest_replace_derive_with_manual_impl() { 934fn doctest_replace_derive_with_manual_impl() {
848 check_doc_test( 935 check_doc_test(
849 "replace_derive_with_manual_impl", 936 "replace_derive_with_manual_impl",
850 r#####" 937 r#####"
851trait Debug { fn fmt(&self, f: &mut Formatter) -> Result<()>; } 938trait Debug { fn fmt(&self, f: &mut Formatter) -> Result<()>; }
852#[derive(Deb<|>ug, Display)] 939#[derive(Deb$0ug, Display)]
853struct S; 940struct S;
854"#####, 941"#####,
855 r#####" 942 r#####"
@@ -874,7 +961,7 @@ fn doctest_replace_if_let_with_match() {
874enum Action { Move { distance: u32 }, Stop } 961enum Action { Move { distance: u32 }, Stop }
875 962
876fn handle(action: Action) { 963fn handle(action: Action) {
877 <|>if let Action::Move { distance } = action { 964 $0if let Action::Move { distance } = action {
878 foo(distance) 965 foo(distance)
879 } else { 966 } else {
880 bar() 967 bar()
@@ -899,7 +986,7 @@ fn doctest_replace_impl_trait_with_generic() {
899 check_doc_test( 986 check_doc_test(
900 "replace_impl_trait_with_generic", 987 "replace_impl_trait_with_generic",
901 r#####" 988 r#####"
902fn foo(bar: <|>impl Bar) {} 989fn foo(bar: $0impl Bar) {}
903"#####, 990"#####,
904 r#####" 991 r#####"
905fn foo<B: Bar>(bar: B) {} 992fn foo<B: Bar>(bar: B) {}
@@ -915,7 +1002,7 @@ fn doctest_replace_let_with_if_let() {
915enum Option<T> { Some(T), None } 1002enum Option<T> { Some(T), None }
916 1003
917fn main(action: Action) { 1004fn main(action: Action) {
918 <|>let x = compute(); 1005 $0let x = compute();
919} 1006}
920 1007
921fn compute() -> Option<i32> { None } 1008fn compute() -> Option<i32> { None }
@@ -941,7 +1028,7 @@ fn doctest_replace_match_with_if_let() {
941enum Action { Move { distance: u32 }, Stop } 1028enum Action { Move { distance: u32 }, Stop }
942 1029
943fn handle(action: Action) { 1030fn handle(action: Action) {
944 <|>match action { 1031 $0match action {
945 Action::Move { distance } => foo(distance), 1032 Action::Move { distance } => foo(distance),
946 _ => bar(), 1033 _ => bar(),
947 } 1034 }
@@ -966,7 +1053,7 @@ fn doctest_replace_qualified_name_with_use() {
966 check_doc_test( 1053 check_doc_test(
967 "replace_qualified_name_with_use", 1054 "replace_qualified_name_with_use",
968 r#####" 1055 r#####"
969fn process(map: std::collections::<|>HashMap<String, String>) {} 1056fn process(map: std::collections::$0HashMap<String, String>) {}
970"#####, 1057"#####,
971 r#####" 1058 r#####"
972use std::collections::HashMap; 1059use std::collections::HashMap;
@@ -982,7 +1069,7 @@ fn doctest_replace_string_with_char() {
982 "replace_string_with_char", 1069 "replace_string_with_char",
983 r#####" 1070 r#####"
984fn main() { 1071fn main() {
985 find("{<|>"); 1072 find("{$0");
986} 1073}
987"#####, 1074"#####,
988 r#####" 1075 r#####"
@@ -1001,7 +1088,7 @@ fn doctest_replace_unwrap_with_match() {
1001enum Result<T, E> { Ok(T), Err(E) } 1088enum Result<T, E> { Ok(T), Err(E) }
1002fn main() { 1089fn main() {
1003 let x: Result<i32, i32> = Result::Ok(92); 1090 let x: Result<i32, i32> = Result::Ok(92);
1004 let y = x.<|>unwrap(); 1091 let y = x.$0unwrap();
1005} 1092}
1006"#####, 1093"#####,
1007 r#####" 1094 r#####"
@@ -1022,7 +1109,7 @@ fn doctest_split_import() {
1022 check_doc_test( 1109 check_doc_test(
1023 "split_import", 1110 "split_import",
1024 r#####" 1111 r#####"
1025use std::<|>collections::HashMap; 1112use std::$0collections::HashMap;
1026"#####, 1113"#####,
1027 r#####" 1114 r#####"
1028use std::{collections::HashMap}; 1115use std::{collections::HashMap};
@@ -1035,7 +1122,7 @@ fn doctest_toggle_ignore() {
1035 check_doc_test( 1122 check_doc_test(
1036 "toggle_ignore", 1123 "toggle_ignore",
1037 r#####" 1124 r#####"
1038<|>#[test] 1125$0#[test]
1039fn arithmetics { 1126fn arithmetics {
1040 assert_eq!(2 + 2, 5); 1127 assert_eq!(2 + 2, 5);
1041} 1128}
@@ -1056,7 +1143,7 @@ fn doctest_unwrap_block() {
1056 "unwrap_block", 1143 "unwrap_block",
1057 r#####" 1144 r#####"
1058fn foo() { 1145fn foo() {
1059 if true {<|> 1146 if true {$0
1060 println!("foo"); 1147 println!("foo");
1061 } 1148 }
1062} 1149}
@@ -1074,7 +1161,7 @@ fn doctest_wrap_return_type_in_result() {
1074 check_doc_test( 1161 check_doc_test(
1075 "wrap_return_type_in_result", 1162 "wrap_return_type_in_result",
1076 r#####" 1163 r#####"
1077fn foo() -> i32<|> { 42i32 } 1164fn foo() -> i32$0 { 42i32 }
1078"#####, 1165"#####,
1079 r#####" 1166 r#####"
1080fn foo() -> Result<i32, ${0:_}> { Ok(42i32) } 1167fn foo() -> Result<i32, ${0:_}> { Ok(42i32) }
diff --git a/crates/assists/src/utils.rs b/crates/assists/src/utils.rs
index d41084b59..9ea96eb73 100644
--- a/crates/assists/src/utils.rs
+++ b/crates/assists/src/utils.rs
@@ -4,7 +4,7 @@ pub(crate) mod import_assets;
4use std::ops; 4use std::ops;
5 5
6use hir::HasSource; 6use hir::HasSource;
7use ide_db::RootDatabase; 7use ide_db::{helpers::SnippetCap, RootDatabase};
8use itertools::Itertools; 8use itertools::Itertools;
9use syntax::{ 9use syntax::{
10 ast::edit::AstNodeEdit, 10 ast::edit::AstNodeEdit,
@@ -16,10 +16,7 @@ use syntax::{
16 SyntaxNode, TextSize, T, 16 SyntaxNode, TextSize, T,
17}; 17};
18 18
19use crate::{ 19use crate::ast_transform::{self, AstTransform, QualifyPaths, SubstituteTypeParams};
20 assist_config::SnippetCap,
21 ast_transform::{self, AstTransform, QualifyPaths, SubstituteTypeParams},
22};
23 20
24pub(crate) fn unwrap_trivial_block(block: ast::BlockExpr) -> ast::Expr { 21pub(crate) fn unwrap_trivial_block(block: ast::BlockExpr) -> ast::Expr {
25 extract_trivial_expression(&block) 22 extract_trivial_expression(&block)
@@ -37,7 +34,7 @@ pub fn extract_trivial_expression(block: &ast::BlockExpr) -> Option<ast::Expr> {
37 non_trivial_children.next().is_some() 34 non_trivial_children.next().is_some()
38 }; 35 };
39 36
40 if let Some(expr) = block.expr() { 37 if let Some(expr) = block.tail_expr() {
41 if has_anything_else(expr.syntax()) { 38 if has_anything_else(expr.syntax()) {
42 return None; 39 return None;
43 } 40 }
@@ -94,14 +91,18 @@ pub fn filter_assoc_items(
94 ast::AssocItem::MacroCall(_) => None, 91 ast::AssocItem::MacroCall(_) => None,
95 } 92 }
96 .is_some() 93 .is_some()
97 }; 94 }
98 95
99 items 96 items
100 .iter() 97 .iter()
101 .map(|i| match i { 98 // Note: This throws away items with no source.
102 hir::AssocItem::Function(i) => ast::AssocItem::Fn(i.source(db).value), 99 .filter_map(|i| {
103 hir::AssocItem::TypeAlias(i) => ast::AssocItem::TypeAlias(i.source(db).value), 100 let item = match i {
104 hir::AssocItem::Const(i) => ast::AssocItem::Const(i.source(db).value), 101 hir::AssocItem::Function(i) => ast::AssocItem::Fn(i.source(db)?.value),
102 hir::AssocItem::TypeAlias(i) => ast::AssocItem::TypeAlias(i.source(db)?.value),
103 hir::AssocItem::Const(i) => ast::AssocItem::Const(i.source(db)?.value),
104 };
105 Some(item)
105 }) 106 })
106 .filter(has_def_name) 107 .filter(has_def_name)
107 .filter(|it| match it { 108 .filter(|it| match it {