aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/src/diagnostics.rs36
1 files changed, 25 insertions, 11 deletions
diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs
index c50a70d99..478368529 100644
--- a/crates/ra_ide/src/diagnostics.rs
+++ b/crates/ra_ide/src/diagnostics.rs
@@ -64,22 +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 let field = make::record_field(make::name_ref(&f.to_string()), Some(make::expr_unit())); 69 // `struct A(usize);`
70 field_list = field_list.append_field(&field); 70 // `let a = A { 0: () }`
71 } 71 // but it is uncommon usage and it should not be encouraged.
72 72 let fix = if d.missed_fields.iter().any(|it| it.as_tuple_index().is_some()) {
73 let mut builder = TextEditBuilder::default(); 73 None
74 algo::diff(&d.ast(db).syntax(), &field_list.syntax()).into_text_edit(&mut builder); 74 } else {
75 let mut field_list = d.ast(db);
76 for f in d.missed_fields.iter() {
77 let field =
78 make::record_field(make::name_ref(&f.to_string()), Some(make::expr_unit()));
79 field_list = field_list.append_field(&field);
80 }
81
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 };
75 91
76 let fix =
77 SourceChange::source_file_edit_from("fill struct fields", file_id, builder.finish());
78 res.borrow_mut().push(Diagnostic { 92 res.borrow_mut().push(Diagnostic {
79 range: d.highlight_range(), 93 range: d.highlight_range(),
80 message: d.message(), 94 message: d.message(),
81 severity: Severity::Error, 95 severity: Severity::Error,
82 fix: Some(fix), 96 fix,
83 }) 97 })
84 }) 98 })
85 .on::<hir::diagnostics::MissingOkInTailExpr, _>(|d| { 99 .on::<hir::diagnostics::MissingOkInTailExpr, _>(|d| {