@@ -54,6 +54,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::MissingFields) -> Option<Vec<Ass
54
54
Either :: Right ( _) => return None ,
55
55
} ;
56
56
let old_field_list = field_list_parent. record_expr_field_list ( ) ?;
57
+
57
58
let new_field_list = old_field_list. clone_for_update ( ) ;
58
59
let mut locals = FxHashMap :: default ( ) ;
59
60
ctx. sema . scope ( field_list_parent. syntax ( ) ) . process_all_names ( & mut |name, def| {
@@ -80,11 +81,19 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::MissingFields) -> Option<Vec<Ass
80
81
new_field_list. add_field ( field) ;
81
82
}
82
83
83
- let edit = {
84
- let mut builder = TextEdit :: builder ( ) ;
84
+ let mut builder = TextEdit :: builder ( ) ;
85
+ if d. file . is_macro ( ) {
86
+ // we can't map the diff up into the macro input unfortunately, as the macro loses all
87
+ // whitespace information so the diff wouldn't be applicable no matter what
88
+ // This has the downside that the cursor will be moved in macros by doing it without a diff
89
+ // but that is a trade off we can make.
90
+ // FIXE: this also currently discards a lot of whitespace in the input... we really need a formatter here
91
+ let range = ctx. sema . original_range_opt ( old_field_list. syntax ( ) ) ?;
92
+ builder. replace ( range. range , new_field_list. to_string ( ) ) ;
93
+ } else {
85
94
algo:: diff ( old_field_list. syntax ( ) , new_field_list. syntax ( ) ) . into_text_edit ( & mut builder) ;
86
- builder . finish ( )
87
- } ;
95
+ }
96
+ let edit = builder . finish ( ) ;
88
97
Some ( vec ! [ fix(
89
98
"fill_missing_fields" ,
90
99
"Fill struct fields" ,
@@ -151,7 +160,6 @@ fn x(a: S) {
151
160
152
161
#[ test]
153
162
fn range_mapping_out_of_macros ( ) {
154
- // FIXME: this is very wrong, but somewhat tricky to fix.
155
163
check_fix (
156
164
r#"
157
165
fn some() {}
@@ -167,14 +175,14 @@ fn main() {
167
175
pub struct Foo { pub a: i32, pub b: i32 }
168
176
"# ,
169
177
r#"
170
- fn some(, b: todo!() ) {}
178
+ fn some() {}
171
179
fn items() {}
172
180
fn here() {}
173
181
174
182
macro_rules! id { ($($tt:tt)*) => { $($tt)*}; }
175
183
176
184
fn main() {
177
- let _x = id![Foo { a: 42 }];
185
+ let _x = id![Foo {a:42, b: todo!() }];
178
186
}
179
187
180
188
pub struct Foo { pub a: i32, pub b: i32 }
0 commit comments