diff options
Diffstat (limited to 'crates/ide/src/diagnostics/field_shorthand.rs')
-rw-r--r-- | crates/ide/src/diagnostics/field_shorthand.rs | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/crates/ide/src/diagnostics/field_shorthand.rs b/crates/ide/src/diagnostics/field_shorthand.rs index f41bcd619..5c89e2170 100644 --- a/crates/ide/src/diagnostics/field_shorthand.rs +++ b/crates/ide/src/diagnostics/field_shorthand.rs | |||
@@ -1,8 +1,7 @@ | |||
1 | //! Suggests shortening `Foo { field: field }` to `Foo { field }` in both | 1 | //! Suggests shortening `Foo { field: field }` to `Foo { field }` in both |
2 | //! expressions and patterns. | 2 | //! expressions and patterns. |
3 | 3 | ||
4 | use ide_db::base_db::FileId; | 4 | use ide_db::{base_db::FileId, source_change::SourceChange}; |
5 | use ide_db::source_change::SourceFileEdit; | ||
6 | use syntax::{ast, match_ast, AstNode, SyntaxNode}; | 5 | use syntax::{ast, match_ast, AstNode, SyntaxNode}; |
7 | use text_edit::TextEdit; | 6 | use text_edit::TextEdit; |
8 | 7 | ||
@@ -50,7 +49,7 @@ fn check_expr_field_shorthand( | |||
50 | Diagnostic::hint(field_range, "Shorthand struct initialization".to_string()).with_fix( | 49 | Diagnostic::hint(field_range, "Shorthand struct initialization".to_string()).with_fix( |
51 | Some(Fix::new( | 50 | Some(Fix::new( |
52 | "Use struct shorthand initialization", | 51 | "Use struct shorthand initialization", |
53 | SourceFileEdit { file_id, edit }.into(), | 52 | SourceChange::from_text_edit(file_id, edit), |
54 | field_range, | 53 | field_range, |
55 | )), | 54 | )), |
56 | ), | 55 | ), |
@@ -89,7 +88,7 @@ fn check_pat_field_shorthand( | |||
89 | acc.push(Diagnostic::hint(field_range, "Shorthand struct pattern".to_string()).with_fix( | 88 | acc.push(Diagnostic::hint(field_range, "Shorthand struct pattern".to_string()).with_fix( |
90 | Some(Fix::new( | 89 | Some(Fix::new( |
91 | "Use struct field shorthand", | 90 | "Use struct field shorthand", |
92 | SourceFileEdit { file_id, edit }.into(), | 91 | SourceChange::from_text_edit(file_id, edit), |
93 | field_range, | 92 | field_range, |
94 | )), | 93 | )), |
95 | )); | 94 | )); |
@@ -120,7 +119,7 @@ fn main() { A { 0: 0 } } | |||
120 | struct A { a: &'static str } | 119 | struct A { a: &'static str } |
121 | fn main() { | 120 | fn main() { |
122 | let a = "haha"; | 121 | let a = "haha"; |
123 | A { a<|>: a } | 122 | A { a$0: a } |
124 | } | 123 | } |
125 | "#, | 124 | "#, |
126 | r#" | 125 | r#" |
@@ -138,7 +137,7 @@ struct A { a: &'static str, b: &'static str } | |||
138 | fn main() { | 137 | fn main() { |
139 | let a = "haha"; | 138 | let a = "haha"; |
140 | let b = "bb"; | 139 | let b = "bb"; |
141 | A { a<|>: a, b } | 140 | A { a$0: a, b } |
142 | } | 141 | } |
143 | "#, | 142 | "#, |
144 | r#" | 143 | r#" |
@@ -171,7 +170,7 @@ fn f(a: A) { let A { 0: 0 } = a; } | |||
171 | r#" | 170 | r#" |
172 | struct A { a: &'static str } | 171 | struct A { a: &'static str } |
173 | fn f(a: A) { | 172 | fn f(a: A) { |
174 | let A { a<|>: a } = a; | 173 | let A { a$0: a } = a; |
175 | } | 174 | } |
176 | "#, | 175 | "#, |
177 | r#" | 176 | r#" |
@@ -186,7 +185,7 @@ fn f(a: A) { | |||
186 | r#" | 185 | r#" |
187 | struct A { a: &'static str, b: &'static str } | 186 | struct A { a: &'static str, b: &'static str } |
188 | fn f(a: A) { | 187 | fn f(a: A) { |
189 | let A { a<|>: a, b } = a; | 188 | let A { a$0: a, b } = a; |
190 | } | 189 | } |
191 | "#, | 190 | "#, |
192 | r#" | 191 | r#" |