From 7a2eebde22b1013b73706a11c4a89e969c36ed2b Mon Sep 17 00:00:00 2001 From: Daiki Ihara Date: Thu, 17 Dec 2020 22:09:55 +0900 Subject: Add initial_contents field for CreateFile --- crates/assists/src/tests.rs | 52 ++++++++++++++------------------------------- 1 file changed, 16 insertions(+), 36 deletions(-) (limited to 'crates/assists/src/tests.rs') diff --git a/crates/assists/src/tests.rs b/crates/assists/src/tests.rs index 9002040ce..d18e566e6 100644 --- a/crates/assists/src/tests.rs +++ b/crates/assists/src/tests.rs @@ -107,47 +107,27 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult, assist_label: && source_change.file_system_edits.len() == 0; source_change.source_file_edits.sort_by_key(|it| it.file_id); - let mut created_file_ids = Vec::new(); let mut buf = String::new(); - for file_system_edit in source_change.file_system_edits.clone() { - match file_system_edit { - FileSystemEdit::CreateFile { dst } => { - created_file_ids.push(dst.anchor); - } - _ => (), + for source_file_edit in source_change.source_file_edits { + let mut text = db.file_text(source_file_edit.file_id).as_ref().to_owned(); + source_file_edit.edit.apply(&mut text); + if !skip_header { + let sr = db.file_source_root(source_file_edit.file_id); + let sr = db.source_root(sr); + let path = sr.path_for_file(&source_file_edit.file_id).unwrap(); + format_to!(buf, "//- {}\n", path) } + buf.push_str(&text); } - for source_file_edit in source_change.source_file_edits { - if created_file_ids.contains(&source_file_edit.file_id) { - let target_dst = source_change - .file_system_edits - .iter() - .find_map(|f| match f { - FileSystemEdit::CreateFile { dst } => { - if dst.anchor == source_file_edit.file_id { - Some(&dst.path) - } else { - None - } - } - _ => None, - }) - .unwrap(); - format_to!(buf, "//- {}\n", target_dst); - let mut text = String::new(); - source_file_edit.edit.apply(&mut text); - buf.push_str(&text); - } else { - let mut text = db.file_text(source_file_edit.file_id).as_ref().to_owned(); - source_file_edit.edit.apply(&mut text); - if !skip_header { - let sr = db.file_source_root(source_file_edit.file_id); - let sr = db.source_root(sr); - let path = sr.path_for_file(&source_file_edit.file_id).unwrap(); - format_to!(buf, "//- {}\n", path) + for file_system_edit in source_change.file_system_edits.clone() { + match file_system_edit { + FileSystemEdit::CreateFile { dst, initial_contents } => { + let target_dst = dst.path; + format_to!(buf, "//- {}\n", target_dst); + buf.push_str(&initial_contents); } - buf.push_str(&text); + _ => (), } } -- cgit v1.2.3