diff options
Diffstat (limited to 'crates/ra_ide/src/diagnostics.rs')
-rw-r--r-- | crates/ra_ide/src/diagnostics.rs | 68 |
1 files changed, 30 insertions, 38 deletions
diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs index 165ff5249..757b76fd4 100644 --- a/crates/ra_ide/src/diagnostics.rs +++ b/crates/ra_ide/src/diagnostics.rs | |||
@@ -6,10 +6,7 @@ | |||
6 | 6 | ||
7 | use std::cell::RefCell; | 7 | use std::cell::RefCell; |
8 | 8 | ||
9 | use hir::{ | 9 | use hir::{diagnostics::DiagnosticSinkBuilder, Semantics}; |
10 | diagnostics::{Diagnostic as HirDiagnostics, DiagnosticSinkBuilder}, | ||
11 | Semantics, | ||
12 | }; | ||
13 | use itertools::Itertools; | 10 | use itertools::Itertools; |
14 | use ra_db::SourceDatabase; | 11 | use ra_db::SourceDatabase; |
15 | use ra_ide_db::RootDatabase; | 12 | use ra_ide_db::RootDatabase; |
@@ -73,7 +70,7 @@ pub(crate) fn diagnostics( | |||
73 | .build(|d| { | 70 | .build(|d| { |
74 | res.borrow_mut().push(Diagnostic { | 71 | res.borrow_mut().push(Diagnostic { |
75 | message: d.message(), | 72 | message: d.message(), |
76 | range: sema.diagnostics_presentation_range(d).range, | 73 | range: sema.diagnostics_display_range(d).range, |
77 | severity: Severity::Error, | 74 | severity: Severity::Error, |
78 | fix: None, | 75 | fix: None, |
79 | }) | 76 | }) |
@@ -86,12 +83,9 @@ pub(crate) fn diagnostics( | |||
86 | res.into_inner() | 83 | res.into_inner() |
87 | } | 84 | } |
88 | 85 | ||
89 | fn diagnostic_with_fix<D: HirDiagnostics + DiagnosticWithFix>( | 86 | fn diagnostic_with_fix<D: DiagnosticWithFix>(d: &D, sema: &Semantics<RootDatabase>) -> Diagnostic { |
90 | d: &D, | ||
91 | sema: &Semantics<RootDatabase>, | ||
92 | ) -> Diagnostic { | ||
93 | Diagnostic { | 87 | Diagnostic { |
94 | range: sema.diagnostics_presentation_range(d).range, | 88 | range: sema.diagnostics_display_range(d).range, |
95 | message: d.message(), | 89 | message: d.message(), |
96 | severity: Severity::Error, | 90 | severity: Severity::Error, |
97 | fix: d.fix(&sema), | 91 | fix: d.fix(&sema), |
@@ -120,8 +114,9 @@ fn check_unnecessary_braces_in_use_statement( | |||
120 | range: use_range, | 114 | range: use_range, |
121 | message: "Unnecessary braces in use statement".to_string(), | 115 | message: "Unnecessary braces in use statement".to_string(), |
122 | severity: Severity::WeakWarning, | 116 | severity: Severity::WeakWarning, |
123 | fix: Some(( | 117 | fix: Some(Fix::new( |
124 | Fix::new("Remove unnecessary braces", SourceFileEdit { file_id, edit }.into()), | 118 | "Remove unnecessary braces", |
119 | SourceFileEdit { file_id, edit }.into(), | ||
125 | use_range, | 120 | use_range, |
126 | )), | 121 | )), |
127 | }); | 122 | }); |
@@ -165,11 +160,9 @@ fn check_struct_shorthand_initialization( | |||
165 | range: field_range, | 160 | range: field_range, |
166 | message: "Shorthand struct initialization".to_string(), | 161 | message: "Shorthand struct initialization".to_string(), |
167 | severity: Severity::WeakWarning, | 162 | severity: Severity::WeakWarning, |
168 | fix: Some(( | 163 | fix: Some(Fix::new( |
169 | Fix::new( | 164 | "Use struct shorthand initialization", |
170 | "Use struct shorthand initialization", | 165 | SourceFileEdit { file_id, edit }.into(), |
171 | SourceFileEdit { file_id, edit }.into(), | ||
172 | ), | ||
173 | field_range, | 166 | field_range, |
174 | )), | 167 | )), |
175 | }); | 168 | }); |
@@ -197,7 +190,7 @@ mod tests { | |||
197 | 190 | ||
198 | let (analysis, file_position) = analysis_and_position(ra_fixture_before); | 191 | let (analysis, file_position) = analysis_and_position(ra_fixture_before); |
199 | let diagnostic = analysis.diagnostics(file_position.file_id, true).unwrap().pop().unwrap(); | 192 | let diagnostic = analysis.diagnostics(file_position.file_id, true).unwrap().pop().unwrap(); |
200 | let (mut fix, fix_range) = diagnostic.fix.unwrap(); | 193 | let mut fix = diagnostic.fix.unwrap(); |
201 | let edit = fix.source_change.source_file_edits.pop().unwrap().edit; | 194 | let edit = fix.source_change.source_file_edits.pop().unwrap().edit; |
202 | let target_file_contents = analysis.file_text(file_position.file_id).unwrap(); | 195 | let target_file_contents = analysis.file_text(file_position.file_id).unwrap(); |
203 | let actual = { | 196 | let actual = { |
@@ -208,9 +201,10 @@ mod tests { | |||
208 | 201 | ||
209 | assert_eq_text!(&after, &actual); | 202 | assert_eq_text!(&after, &actual); |
210 | assert!( | 203 | assert!( |
211 | fix_range.start() <= file_position.offset && fix_range.end() >= file_position.offset, | 204 | fix.fix_trigger_range.start() <= file_position.offset |
205 | && fix.fix_trigger_range.end() >= file_position.offset, | ||
212 | "diagnostic fix range {:?} does not touch cursor position {:?}", | 206 | "diagnostic fix range {:?} does not touch cursor position {:?}", |
213 | fix_range, | 207 | fix.fix_trigger_range, |
214 | file_position.offset | 208 | file_position.offset |
215 | ); | 209 | ); |
216 | } | 210 | } |
@@ -222,7 +216,7 @@ mod tests { | |||
222 | let (analysis, file_pos) = analysis_and_position(ra_fixture_before); | 216 | let (analysis, file_pos) = analysis_and_position(ra_fixture_before); |
223 | let current_file_id = file_pos.file_id; | 217 | let current_file_id = file_pos.file_id; |
224 | let diagnostic = analysis.diagnostics(current_file_id, true).unwrap().pop().unwrap(); | 218 | let diagnostic = analysis.diagnostics(current_file_id, true).unwrap().pop().unwrap(); |
225 | let mut fix = diagnostic.fix.unwrap().0; | 219 | let mut fix = diagnostic.fix.unwrap(); |
226 | let edit = fix.source_change.source_file_edits.pop().unwrap(); | 220 | let edit = fix.source_change.source_file_edits.pop().unwrap(); |
227 | let changed_file_id = edit.file_id; | 221 | let changed_file_id = edit.file_id; |
228 | let before = analysis.file_text(changed_file_id).unwrap(); | 222 | let before = analysis.file_text(changed_file_id).unwrap(); |
@@ -513,24 +507,22 @@ fn test_fn() { | |||
513 | range: 0..8, | 507 | range: 0..8, |
514 | severity: Error, | 508 | severity: Error, |
515 | fix: Some( | 509 | fix: Some( |
516 | ( | 510 | Fix { |
517 | Fix { | 511 | label: "Create module", |
518 | label: "Create module", | 512 | source_change: SourceChange { |
519 | source_change: SourceChange { | 513 | source_file_edits: [], |
520 | source_file_edits: [], | 514 | file_system_edits: [ |
521 | file_system_edits: [ | 515 | CreateFile { |
522 | CreateFile { | 516 | anchor: FileId( |
523 | anchor: FileId( | 517 | 1, |
524 | 1, | 518 | ), |
525 | ), | 519 | dst: "foo.rs", |
526 | dst: "foo.rs", | 520 | }, |
527 | }, | 521 | ], |
528 | ], | 522 | is_snippet: false, |
529 | is_snippet: false, | ||
530 | }, | ||
531 | }, | 523 | }, |
532 | 0..8, | 524 | fix_trigger_range: 0..8, |
533 | ), | 525 | }, |
534 | ), | 526 | ), |
535 | }, | 527 | }, |
536 | ] | 528 | ] |