aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/src/diagnostics.rs44
1 files changed, 25 insertions, 19 deletions
diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs
index 3264f8f80..478368529 100644
--- a/crates/ra_ide/src/diagnostics.rs
+++ b/crates/ra_ide/src/diagnostics.rs
@@ -64,30 +64,36 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
64 }) 64 })
65 }) 65 })
66 .on::<hir::diagnostics::MissingFields, _>(|d| { 66 .on::<hir::diagnostics::MissingFields, _>(|d| {
67 let mut field_list = d.ast(db); 67 // Note that although we could add a diagnostics to
68 for f in d.missed_fields.iter() { 68 // fill the missing tuple field, e.g :
69 // Note that although we could add a diagnostics to 69 // `struct A(usize);`
70 // fill the missing tuple field, e.g : 70 // `let a = A { 0: () }`
71 // `struct A(usize);` 71 // but it is uncommon usage and it should not be encouraged.
72 // `let a = A { 0: () }` 72 let fix = if d.missed_fields.iter().any(|it| it.as_tuple_index().is_some()) {
73 // but it is uncommon usage and it should not be encouraged. 73 None
74 if f.as_tuple_index().is_some() { 74 } else {
75 continue; 75 let mut field_list = d.ast(db);
76 } 76 for f in d.missed_fields.iter() {
77 let field = make::record_field(make::name_ref(&f.to_string()), Some(make::expr_unit())); 77 let field =
78 field_list = field_list.append_field(&field); 78 make::record_field(make::name_ref(&f.to_string()), Some(make::expr_unit()));
79 } 79 field_list = field_list.append_field(&field);
80 80 }
81 let mut builder = TextEditBuilder::default(); 81
82 algo::diff(&d.ast(db).syntax(), &field_list.syntax()).into_text_edit(&mut builder); 82 let mut builder = TextEditBuilder::default();
83 algo::diff(&d.ast(db).syntax(), &field_list.syntax()).into_text_edit(&mut builder);
84
85 Some(SourceChange::source_file_edit_from(
86 "fill struct fields",
87 file_id,
88 builder.finish(),
89 ))
90 };
83 91
84 let fix =
85 SourceChange::source_file_edit_from("fill struct fields", file_id, builder.finish());
86 res.borrow_mut().push(Diagnostic { 92 res.borrow_mut().push(Diagnostic {
87 range: d.highlight_range(), 93 range: d.highlight_range(),
88 message: d.message(), 94 message: d.message(),
89 severity: Severity::Error, 95 severity: Severity::Error,
90 fix: Some(fix), 96 fix,
91 }) 97 })
92 }) 98 })
93 .on::<hir::diagnostics::MissingOkInTailExpr, _>(|d| { 99 .on::<hir::diagnostics::MissingOkInTailExpr, _>(|d| {