aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-12-24 16:36:13 +0000
committerAleksey Kladov <[email protected]>2020-12-24 16:37:46 +0000
commit5d914834a948fd8a154904d171834edd9050205c (patch)
tree96338ebff390c6a8a7a3257badca938a18681fe7 /crates
parentf43182e621fc73e409dfd21d126d401b54bd3db3 (diff)
Simplify more
Diffstat (limited to 'crates')
-rw-r--r--crates/ide/src/diagnostics.rs65
1 files changed, 22 insertions, 43 deletions
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs
index 7e53ed361..038273750 100644
--- a/crates/ide/src/diagnostics.rs
+++ b/crates/ide/src/diagnostics.rs
@@ -258,10 +258,12 @@ mod tests {
258 .pop() 258 .pop()
259 .unwrap(); 259 .unwrap();
260 let fix = diagnostic.fix.unwrap(); 260 let fix = diagnostic.fix.unwrap();
261 let target_file_contents = analysis.file_text(file_position.file_id).unwrap();
262 let actual = { 261 let actual = {
263 let mut actual = target_file_contents.to_string(); 262 let file_id = fix.source_change.source_file_edits.first().unwrap().file_id;
263 let mut actual = analysis.file_text(file_id).unwrap().to_string();
264
264 // Go from the last one to the first one, so that ranges won't be affected by previous edits. 265 // Go from the last one to the first one, so that ranges won't be affected by previous edits.
266 // FIXME: https://github.com/rust-analyzer/rust-analyzer/issues/4901#issuecomment-644675309
265 for edit in fix.source_change.source_file_edits.iter().rev() { 267 for edit in fix.source_change.source_file_edits.iter().rev() {
266 edit.edit.apply(&mut actual); 268 edit.edit.apply(&mut actual);
267 } 269 }
@@ -277,29 +279,6 @@ mod tests {
277 ); 279 );
278 } 280 }
279 281
280 /// Checks that a diagnostic applies to the file containing the `<|>` cursor marker
281 /// which has a fix that can apply to other files.
282 fn check_apply_diagnostic_fix_in_other_file(ra_fixture_before: &str, ra_fixture_after: &str) {
283 let ra_fixture_after = &trim_indent(ra_fixture_after);
284 let (analysis, file_pos) = fixture::position(ra_fixture_before);
285 let current_file_id = file_pos.file_id;
286 let diagnostic = analysis
287 .diagnostics(&DiagnosticsConfig::default(), current_file_id)
288 .unwrap()
289 .pop()
290 .unwrap();
291 let mut fix = diagnostic.fix.unwrap();
292 let edit = fix.source_change.source_file_edits.pop().unwrap();
293 let changed_file_id = edit.file_id;
294 let before = analysis.file_text(changed_file_id).unwrap();
295 let actual = {
296 let mut actual = before.to_string();
297 edit.edit.apply(&mut actual);
298 actual
299 };
300 assert_eq_text!(ra_fixture_after, &actual);
301 }
302
303 /// Takes a multi-file input fixture with annotated cursor position and checks that no diagnostics 282 /// Takes a multi-file input fixture with annotated cursor position and checks that no diagnostics
304 /// apply to the file containing the cursor. 283 /// apply to the file containing the cursor.
305 pub(crate) fn check_no_diagnostics(ra_fixture: &str) { 284 pub(crate) fn check_no_diagnostics(ra_fixture: &str) {
@@ -736,25 +715,25 @@ struct Foo {
736 715
737 #[test] 716 #[test]
738 fn test_add_field_in_other_file_from_usage() { 717 fn test_add_field_in_other_file_from_usage() {
739 check_apply_diagnostic_fix_in_other_file( 718 check_fix(
740 r" 719 r#"
741 //- /main.rs 720//- /main.rs
742 mod foo; 721mod foo;
743 722
744 fn main() { 723fn main() {
745 <|>foo::Foo { bar: 3, baz: false}; 724 foo::Foo { bar: 3, <|>baz: false};
746 } 725}
747 //- /foo.rs 726//- /foo.rs
748 struct Foo { 727struct Foo {
749 bar: i32 728 bar: i32
750 } 729}
751 ", 730"#,
752 r" 731 r#"
753 struct Foo { 732struct Foo {
754 bar: i32, 733 bar: i32,
755 pub(crate) baz: bool 734 pub(crate) baz: bool
756 } 735}
757 ", 736"#,
758 ) 737 )
759 } 738 }
760 739