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_syntax/src/lib.rs | 3 ++- crates/ra_syntax/src/parsing/reparsing.rs | 14 +++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index 1a7348dac..61e686da5 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs @@ -142,7 +142,8 @@ impl Parse { } fn full_reparse(&self, indel: &Indel) -> Parse { - let text = indel.apply(self.tree().syntax().text().to_string()); + let mut text = self.tree().syntax().text().to_string(); + indel.apply(&mut text); SourceFile::parse(&text) } } diff --git a/crates/ra_syntax/src/parsing/reparsing.rs b/crates/ra_syntax/src/parsing/reparsing.rs index 6257e3f33..edbc190f8 100644 --- a/crates/ra_syntax/src/parsing/reparsing.rs +++ b/crates/ra_syntax/src/parsing/reparsing.rs @@ -109,14 +109,14 @@ fn reparse_block<'node>( } fn get_text_after_edit(element: SyntaxElement, edit: &Indel) -> String { - let edit = - Indel::replace(edit.delete - element.text_range().start(), edit.insert.clone()); + let edit = Indel::replace(edit.delete - element.text_range().start(), edit.insert.clone()); - let text = match element { + let mut text = match element { NodeOrToken::Token(token) => token.text().to_string(), NodeOrToken::Node(node) => node.text().to_string(), }; - edit.apply(text) + edit.apply(&mut text); + text } fn is_contextual_kw(text: &str) -> bool { @@ -199,7 +199,11 @@ mod tests { fn do_check(before: &str, replace_with: &str, reparsed_len: u32) { let (range, before) = extract_range(before); let edit = Indel::replace(range, replace_with.to_owned()); - let after = edit.apply(before.clone()); + let after = { + let mut after = before.clone(); + edit.apply(&mut after); + after + }; let fully_reparsed = SourceFile::parse(&after); let incrementally_reparsed: Parse = { -- cgit v1.2.3