From 5f57491c981530103e1e26dcd280e1a2df10f853 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 21 May 2020 15:56:18 +0200 Subject: Cleanup TextEdit --- crates/ra_ide/src/completion/completion_item.rs | 4 ++-- crates/ra_ide/src/references/rename.rs | 4 ++-- crates/ra_ide/src/test_utils.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/completion/completion_item.rs b/crates/ra_ide/src/completion/completion_item.rs index 6021f7279..cfb7c1e38 100644 --- a/crates/ra_ide/src/completion/completion_item.rs +++ b/crates/ra_ide/src/completion/completion_item.rs @@ -63,8 +63,8 @@ impl fmt::Debug for CompletionItem { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let mut s = f.debug_struct("CompletionItem"); s.field("label", &self.label()).field("source_range", &self.source_range()); - if self.text_edit().as_indels().len() == 1 { - let atom = &self.text_edit().as_indels()[0]; + if self.text_edit().len() == 1 { + let atom = &self.text_edit().iter().next().unwrap(); s.field("delete", &atom.delete); s.field("insert", &atom.insert); } else { diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index 55c3319cb..fd2163dad 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs @@ -983,8 +983,8 @@ mod tests { if let Some(change) = source_change { for edit in change.info.source_file_edits { file_id = Some(edit.file_id); - for indel in edit.edit.as_indels() { - text_edit_builder.replace(indel.delete, indel.insert.clone()); + for indel in edit.edit.into_iter() { + text_edit_builder.replace(indel.delete, indel.insert); } } } diff --git a/crates/ra_ide/src/test_utils.rs b/crates/ra_ide/src/test_utils.rs index 48c8fd1f4..b335582a3 100644 --- a/crates/ra_ide/src/test_utils.rs +++ b/crates/ra_ide/src/test_utils.rs @@ -3,9 +3,9 @@ use ra_syntax::{SourceFile, TextSize}; use ra_text_edit::TextEdit; -pub use test_utils::*; +pub(crate) use test_utils::*; -pub fn check_action Option>( +pub(crate) fn check_action Option>( before: &str, after: &str, f: F, -- cgit v1.2.3 From ef0da3bbeccdaab3813a1f6a17c566ca9087615f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 21 May 2020 16:11:37 +0200 Subject: Cleanup --- crates/ra_ide/src/join_lines.rs | 24 ++++++++++++++++++------ crates/ra_ide/src/lib.rs | 3 --- crates/ra_ide/src/test_utils.rs | 25 ------------------------- 3 files changed, 18 insertions(+), 34 deletions(-) delete mode 100644 crates/ra_ide/src/test_utils.rs (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/join_lines.rs b/crates/ra_ide/src/join_lines.rs index d3af780c4..af1ade8a1 100644 --- a/crates/ra_ide/src/join_lines.rs +++ b/crates/ra_ide/src/join_lines.rs @@ -166,16 +166,28 @@ fn is_trailing_comma(left: SyntaxKind, right: SyntaxKind) -> bool { #[cfg(test)] mod tests { - use crate::test_utils::{assert_eq_text, check_action, extract_range}; + use ra_syntax::SourceFile; + use test_utils::{add_cursor, assert_eq_text, extract_offset, extract_range}; use super::*; fn check_join_lines(before: &str, after: &str) { - check_action(before, after, |file, offset| { - let range = TextRange::empty(offset); - let res = join_lines(file, range); - Some(res) - }) + let (before_cursor_pos, before) = extract_offset(before); + let file = SourceFile::parse(&before).ok().unwrap(); + + let range = TextRange::empty(before_cursor_pos); + let result = join_lines(&file, range); + + let actual = { + let mut actual = before.to_string(); + result.apply(&mut actual); + actual + }; + let actual_cursor_pos = result + .apply_to_offset(before_cursor_pos) + .expect("cursor position is affected by the edit"); + let actual = add_cursor(&actual, actual_cursor_pos); + assert_eq_text!(after, &actual); } #[test] diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 1d7bacbf6..d0aeb3ba7 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs @@ -42,9 +42,6 @@ mod inlay_hints; mod expand_macro; mod ssr; -#[cfg(test)] -mod test_utils; - use std::sync::Arc; use ra_cfg::CfgOptions; diff --git a/crates/ra_ide/src/test_utils.rs b/crates/ra_ide/src/test_utils.rs deleted file mode 100644 index b335582a3..000000000 --- a/crates/ra_ide/src/test_utils.rs +++ /dev/null @@ -1,25 +0,0 @@ -//! FIXME: write short doc here - -use ra_syntax::{SourceFile, TextSize}; -use ra_text_edit::TextEdit; - -pub(crate) use test_utils::*; - -pub(crate) fn check_action Option>( - before: &str, - after: &str, - f: F, -) { - let (before_cursor_pos, before) = extract_offset(before); - let file = SourceFile::parse(&before).ok().unwrap(); - let result = f(&file, before_cursor_pos).expect("code action is not applicable"); - let actual = { - let mut actual = before.to_string(); - result.apply(&mut actual); - actual - }; - let actual_cursor_pos = - result.apply_to_offset(before_cursor_pos).expect("cursor position is affected by the edit"); - let actual = add_cursor(&actual, actual_cursor_pos); - assert_eq_text!(after, &actual); -} -- cgit v1.2.3