aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r--crates/ra_ide/src/diagnostics.rs31
1 files changed, 17 insertions, 14 deletions
diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs
index e847df6ea..0d2ff17e1 100644
--- a/crates/ra_ide/src/diagnostics.rs
+++ b/crates/ra_ide/src/diagnostics.rs
@@ -54,18 +54,19 @@ pub(crate) fn diagnostics(
54 let res = RefCell::new(res); 54 let res = RefCell::new(res);
55 let mut sink = DiagnosticSinkBuilder::new() 55 let mut sink = DiagnosticSinkBuilder::new()
56 .on::<hir::diagnostics::UnresolvedModule, _>(|d| { 56 .on::<hir::diagnostics::UnresolvedModule, _>(|d| {
57 let original_file = d.source().file_id.original_file(db);
58 let fix = Fix::new( 57 let fix = Fix::new(
59 "Create module", 58 "Create module",
60 FileSystemEdit::CreateFile { anchor: original_file, dst: d.candidate.clone() } 59 FileSystemEdit::CreateFile {
61 .into(), 60 anchor: d.file.original_file(db),
61 dst: d.candidate.clone(),
62 }
63 .into(),
62 ); 64 );
63 let range = sema.diagnostics_range(d).range;
64 res.borrow_mut().push(Diagnostic { 65 res.borrow_mut().push(Diagnostic {
65 range, 66 range: sema.diagnostics_range(d).range,
66 message: d.message(), 67 message: d.message(),
67 severity: Severity::Error, 68 severity: Severity::Error,
68 fix: Some((fix, range)), 69 fix: Some((fix, sema.diagnostics_fix_range(d).range)),
69 }) 70 })
70 }) 71 })
71 .on::<hir::diagnostics::MissingFields, _>(|d| { 72 .on::<hir::diagnostics::MissingFields, _>(|d| {
@@ -94,12 +95,12 @@ pub(crate) fn diagnostics(
94 }; 95 };
95 Some(( 96 Some((
96 Fix::new("Fill struct fields", SourceFileEdit { file_id, edit }.into()), 97 Fix::new("Fill struct fields", SourceFileEdit { file_id, edit }.into()),
97 sema.diagnostics_range(d).range, 98 sema.diagnostics_fix_range(d).range,
98 )) 99 ))
99 }; 100 };
100 101
101 res.borrow_mut().push(Diagnostic { 102 res.borrow_mut().push(Diagnostic {
102 range: d.highlighting_source().file_syntax(db).text_range(), 103 range: sema.diagnostics_range(d).range,
103 message: d.message(), 104 message: d.message(),
104 severity: Severity::Error, 105 severity: Severity::Error,
105 fix, 106 fix,
@@ -110,21 +111,23 @@ pub(crate) fn diagnostics(
110 let replacement = format!("Ok({})", node.syntax()); 111 let replacement = format!("Ok({})", node.syntax());
111 let edit = TextEdit::replace(node.syntax().text_range(), replacement); 112 let edit = TextEdit::replace(node.syntax().text_range(), replacement);
112 let source_change = SourceFileEdit { file_id, edit }.into(); 113 let source_change = SourceFileEdit { file_id, edit }.into();
113 let range = sema.diagnostics_range(d).range;
114 res.borrow_mut().push(Diagnostic { 114 res.borrow_mut().push(Diagnostic {
115 range, 115 range: sema.diagnostics_range(d).range,
116 message: d.message(), 116 message: d.message(),
117 severity: Severity::Error, 117 severity: Severity::Error,
118 fix: Some((Fix::new("Wrap with ok", source_change), range)), 118 fix: Some((
119 Fix::new("Wrap with ok", source_change),
120 sema.diagnostics_fix_range(d).range,
121 )),
119 }) 122 })
120 }) 123 })
121 .on::<hir::diagnostics::NoSuchField, _>(|d| { 124 .on::<hir::diagnostics::NoSuchField, _>(|d| {
122 let range = sema.diagnostics_range(d).range;
123 res.borrow_mut().push(Diagnostic { 125 res.borrow_mut().push(Diagnostic {
124 range, 126 range: sema.diagnostics_range(d).range,
125 message: d.message(), 127 message: d.message(),
126 severity: Severity::Error, 128 severity: Severity::Error,
127 fix: missing_struct_field_fix(&sema, file_id, d).map(|fix| (fix, range)), 129 fix: missing_struct_field_fix(&sema, file_id, d)
130 .map(|fix| (fix, sema.diagnostics_fix_range(d).range)),
128 }) 131 })
129 }) 132 })
130 // Only collect experimental diagnostics when they're enabled. 133 // Only collect experimental diagnostics when they're enabled.