From 4a6fa8f0dfcebbb4ea80394e5e4ca21f076f58f2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 5 May 2020 23:15:49 +0200 Subject: Rename AtomTextEdit -> Indel --- crates/ra_ide/src/completion/completion_context.rs | 4 ++-- crates/ra_ide/src/completion/completion_item.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index dd87bd119..b6b9627de 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -9,7 +9,7 @@ use ra_syntax::{ SyntaxKind::*, SyntaxNode, SyntaxToken, TextRange, TextSize, }; -use ra_text_edit::AtomTextEdit; +use ra_text_edit::Indel; use crate::{call_info::ActiveParameter, completion::CompletionConfig, FilePosition}; @@ -76,7 +76,7 @@ impl<'a> CompletionContext<'a> { // actual completion. let file_with_fake_ident = { let parse = db.parse(position.file_id); - let edit = AtomTextEdit::insert(position.offset, "intellijRulezz".to_string()); + let edit = Indel::insert(position.offset, "intellijRulezz".to_string()); parse.reparse(&edit).tree() }; let fake_ident_token = diff --git a/crates/ra_ide/src/completion/completion_item.rs b/crates/ra_ide/src/completion/completion_item.rs index 5936fb8f7..383b23ac4 100644 --- a/crates/ra_ide/src/completion/completion_item.rs +++ b/crates/ra_ide/src/completion/completion_item.rs @@ -62,8 +62,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_atoms().len() == 1 { - let atom = &self.text_edit().as_atoms()[0]; + if self.text_edit().as_indels().len() == 1 { + let atom = &self.text_edit().as_indels()[0]; s.field("delete", &atom.delete); s.field("insert", &atom.insert); } else { -- cgit v1.2.3 From 27c7ef6d65ffa6a642768377d3f0ba85ac8564bf Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 5 May 2020 23:23:29 +0200 Subject: Use more natural signature for Edit::apply --- crates/ra_ide/src/ssr.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/ssr.rs b/crates/ra_ide/src/ssr.rs index 7b93ff2d2..e213da606 100644 --- a/crates/ra_ide/src/ssr.rs +++ b/crates/ra_ide/src/ssr.rs @@ -401,16 +401,22 @@ fn render_replace( ignored_comments: &Vec, template: &SsrTemplate, ) -> String { - let mut builder = TextEditBuilder::default(); - for element in template.template.descendants() { - if let Some(var) = template.placeholders.get(&element) { - builder.replace(element.text_range(), binding[var].to_string()) + let edit = { + let mut builder = TextEditBuilder::default(); + for element in template.template.descendants() { + if let Some(var) = template.placeholders.get(&element) { + builder.replace(element.text_range(), binding[var].to_string()) + } } - } - for comment in ignored_comments { - builder.insert(template.template.text_range().end(), comment.syntax().to_string()) - } - builder.finish().apply(&template.template.text().to_string()) + for comment in ignored_comments { + builder.insert(template.template.text_range().end(), comment.syntax().to_string()) + } + builder.finish() + }; + + let mut text = template.template.text().to_string(); + edit.apply(&mut text); + text } #[cfg(test)] -- cgit v1.2.3 From ca9e0f5fe9ad29ab0c5a0771a0d0eaec97e4104b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 5 May 2020 23:48:26 +0200 Subject: Fixup tests --- crates/ra_ide/src/diagnostics.rs | 24 ++++++++++++++++++------ crates/ra_ide/src/join_lines.rs | 6 +++++- crates/ra_ide/src/references/rename.rs | 32 ++++++++++++++++---------------- crates/ra_ide/src/ssr.rs | 8 ++++++-- crates/ra_ide/src/test_utils.rs | 6 +++++- crates/ra_ide/src/typing.rs | 9 ++++++--- crates/ra_ide/src/typing/on_enter.rs | 3 ++- 7 files changed, 58 insertions(+), 30 deletions(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs index 4c04cee07..87a0b80f1 100644 --- a/crates/ra_ide/src/diagnostics.rs +++ b/crates/ra_ide/src/diagnostics.rs @@ -241,7 +241,11 @@ mod tests { diagnostics.pop().unwrap_or_else(|| panic!("no diagnostics for:\n{}\n", before)); let mut fix = diagnostic.fix.unwrap(); let edit = fix.source_file_edits.pop().unwrap().edit; - let actual = edit.apply(&before); + let actual = { + let mut actual = before.to_string(); + edit.apply(&mut actual); + actual + }; assert_eq_text!(after, &actual); } @@ -256,7 +260,11 @@ mod tests { let mut fix = diagnostic.fix.unwrap(); let edit = fix.source_file_edits.pop().unwrap().edit; let target_file_contents = analysis.file_text(file_position.file_id).unwrap(); - let actual = edit.apply(&target_file_contents); + let actual = { + let mut actual = target_file_contents.to_string(); + edit.apply(&mut actual); + actual + }; // Strip indent and empty lines from `after`, to match the behaviour of // `parse_fixture` called from `analysis_and_position`. @@ -288,7 +296,11 @@ mod tests { let diagnostic = analysis.diagnostics(file_id).unwrap().pop().unwrap(); let mut fix = diagnostic.fix.unwrap(); let edit = fix.source_file_edits.pop().unwrap().edit; - let actual = edit.apply(&before); + let actual = { + let mut actual = before.to_string(); + edit.apply(&mut actual); + actual + }; assert_eq_text!(after, &actual); } @@ -662,10 +674,10 @@ mod tests { 1, ), edit: TextEdit { - atoms: [ - AtomTextEdit { - delete: 3..9, + indels: [ + Indel { insert: "{a:42, b: ()}", + delete: 3..9, }, ], }, diff --git a/crates/ra_ide/src/join_lines.rs b/crates/ra_ide/src/join_lines.rs index 63fd6b3e4..d3af780c4 100644 --- a/crates/ra_ide/src/join_lines.rs +++ b/crates/ra_ide/src/join_lines.rs @@ -569,7 +569,11 @@ fn foo() { let (sel, before) = extract_range(before); let parse = SourceFile::parse(&before); let result = join_lines(&parse.tree(), sel); - let actual = result.apply(&before); + let actual = { + let mut actual = before.to_string(); + result.apply(&mut actual); + actual + }; assert_eq_text!(after, &actual); } diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index 52e55b0a0..0398d53bc 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs @@ -537,10 +537,10 @@ mod tests { 2, ), edit: TextEdit { - atoms: [ - AtomTextEdit { - delete: 4..7, + indels: [ + Indel { insert: "foo2", + delete: 4..7, }, ], }, @@ -589,10 +589,10 @@ mod tests { 1, ), edit: TextEdit { - atoms: [ - AtomTextEdit { - delete: 4..7, + indels: [ + Indel { insert: "foo2", + delete: 4..7, }, ], }, @@ -672,10 +672,10 @@ mod tests { 2, ), edit: TextEdit { - atoms: [ - AtomTextEdit { - delete: 8..11, + indels: [ + Indel { insert: "foo2", + delete: 8..11, }, ], }, @@ -685,10 +685,10 @@ mod tests { 1, ), edit: TextEdit { - atoms: [ - AtomTextEdit { - delete: 27..30, + indels: [ + Indel { insert: "foo2", + delete: 27..30, }, ], }, @@ -720,13 +720,13 @@ mod tests { if let Some(change) = source_change { for edit in change.info.source_file_edits { file_id = Some(edit.file_id); - for atom in edit.edit.as_atoms() { - text_edit_builder.replace(atom.delete, atom.insert.clone()); + for indel in edit.edit.as_indels() { + text_edit_builder.replace(indel.delete, indel.insert.clone()); } } } - let result = - text_edit_builder.finish().apply(&*analysis.file_text(file_id.unwrap()).unwrap()); + let mut result = analysis.file_text(file_id.unwrap()).unwrap().to_string(); + text_edit_builder.finish().apply(&mut result); assert_eq_text!(expected, &*result); } } diff --git a/crates/ra_ide/src/ssr.rs b/crates/ra_ide/src/ssr.rs index e213da606..8bf52d0fa 100644 --- a/crates/ra_ide/src/ssr.rs +++ b/crates/ra_ide/src/ssr.rs @@ -511,7 +511,9 @@ mod tests { ); let edit = replace(&matches, &query.template); - assert_eq!(edit.apply(input), "fn main() { bar(1+2); }"); + let mut after = input.to_string(); + edit.apply(&mut after); + assert_eq!(after, "fn main() { bar(1+2); }"); } fn assert_ssr_transform(query: &str, input: &str, result: &str) { @@ -519,7 +521,9 @@ mod tests { let code = SourceFile::parse(input).tree(); let matches = find(&query.pattern, code.syntax()); let edit = replace(&matches, &query.template); - assert_eq!(edit.apply(input), result); + let mut after = input.to_string(); + edit.apply(&mut after); + assert_eq!(after, result); } #[test] diff --git a/crates/ra_ide/src/test_utils.rs b/crates/ra_ide/src/test_utils.rs index f14533e14..48c8fd1f4 100644 --- a/crates/ra_ide/src/test_utils.rs +++ b/crates/ra_ide/src/test_utils.rs @@ -13,7 +13,11 @@ pub fn check_action Option>( 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 = result.apply(&before); + 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); diff --git a/crates/ra_ide/src/typing.rs b/crates/ra_ide/src/typing.rs index 2a8b4327f..a03da4693 100644 --- a/crates/ra_ide/src/typing.rs +++ b/crates/ra_ide/src/typing.rs @@ -142,10 +142,13 @@ mod tests { fn do_type_char(char_typed: char, before: &str) -> Option<(String, SingleFileChange)> { let (offset, before) = extract_offset(before); let edit = TextEdit::insert(offset, char_typed.to_string()); - let before = edit.apply(&before); + let mut before = before.to_string(); + edit.apply(&mut before); let parse = SourceFile::parse(&before); - on_char_typed_inner(&parse.tree(), offset, char_typed) - .map(|it| (it.edit.apply(&before), it)) + on_char_typed_inner(&parse.tree(), offset, char_typed).map(|it| { + it.edit.apply(&mut before); + (before.to_string(), it) + }) } fn type_char(char_typed: char, before: &str, after: &str) { diff --git a/crates/ra_ide/src/typing/on_enter.rs b/crates/ra_ide/src/typing/on_enter.rs index 725237464..78a40cc94 100644 --- a/crates/ra_ide/src/typing/on_enter.rs +++ b/crates/ra_ide/src/typing/on_enter.rs @@ -96,7 +96,8 @@ mod tests { let result = analysis.on_enter(FilePosition { offset, file_id }).unwrap()?; assert_eq!(result.source_file_edits.len(), 1); - let actual = result.source_file_edits[0].edit.apply(&before); + let mut actual = before.to_string(); + result.source_file_edits[0].edit.apply(&mut actual); let actual = add_cursor(&actual, result.cursor_position.unwrap().offset); Some(actual) } -- cgit v1.2.3