Skip to content

Commit 5d91483

Browse files
committed
Simplify more
1 parent f43182e commit 5d91483

File tree

1 file changed

+22
-43
lines changed

1 file changed

+22
-43
lines changed

crates/ide/src/diagnostics.rs

Lines changed: 22 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,12 @@ mod tests {
258258
.pop()
259259
.unwrap();
260260
let fix = diagnostic.fix.unwrap();
261-
let target_file_contents = analysis.file_text(file_position.file_id).unwrap();
262261
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+
264265
// 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
265267
for edit in fix.source_change.source_file_edits.iter().rev() {
266268
edit.edit.apply(&mut actual);
267269
}
@@ -277,29 +279,6 @@ mod tests {
277279
);
278280
}
279281

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-
303282
/// Takes a multi-file input fixture with annotated cursor position and checks that no diagnostics
304283
/// apply to the file containing the cursor.
305284
pub(crate) fn check_no_diagnostics(ra_fixture: &str) {
@@ -736,25 +715,25 @@ struct Foo {
736715

737716
#[test]
738717
fn test_add_field_in_other_file_from_usage() {
739-
check_apply_diagnostic_fix_in_other_file(
740-
r"
741-
//- /main.rs
742-
mod foo;
718+
check_fix(
719+
r#"
720+
//- /main.rs
721+
mod foo;
743722
744-
fn main() {
745-
<|>foo::Foo { bar: 3, baz: false};
746-
}
747-
//- /foo.rs
748-
struct Foo {
749-
bar: i32
750-
}
751-
",
752-
r"
753-
struct Foo {
754-
bar: i32,
755-
pub(crate) baz: bool
756-
}
757-
",
723+
fn main() {
724+
foo::Foo { bar: 3, <|>baz: false};
725+
}
726+
//- /foo.rs
727+
struct Foo {
728+
bar: i32
729+
}
730+
"#,
731+
r#"
732+
struct Foo {
733+
bar: i32,
734+
pub(crate) baz: bool
735+
}
736+
"#,
758737
)
759738
}
760739

0 commit comments

Comments
 (0)