diff options
Diffstat (limited to 'crates/ra_syntax/src/parsing')
-rw-r--r-- | crates/ra_syntax/src/parsing/reparsing.rs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/crates/ra_syntax/src/parsing/reparsing.rs b/crates/ra_syntax/src/parsing/reparsing.rs index c7183299b..2f388bdfe 100644 --- a/crates/ra_syntax/src/parsing/reparsing.rs +++ b/crates/ra_syntax/src/parsing/reparsing.rs | |||
@@ -46,7 +46,8 @@ fn reparse_token<'node>( | |||
46 | WHITESPACE | COMMENT | IDENT | STRING | RAW_STRING => { | 46 | WHITESPACE | COMMENT | IDENT | STRING | RAW_STRING => { |
47 | if token.kind() == WHITESPACE || token.kind() == COMMENT { | 47 | if token.kind() == WHITESPACE || token.kind() == COMMENT { |
48 | // removing a new line may extends previous token | 48 | // removing a new line may extends previous token |
49 | if token.text().to_string()[edit.delete - token.range().start()].contains('\n') { | 49 | if token.text().to_string()[edit.delete - token.text_range().start()].contains('\n') |
50 | { | ||
50 | return None; | 51 | return None; |
51 | } | 52 | } |
52 | } | 53 | } |
@@ -62,7 +63,7 @@ fn reparse_token<'node>( | |||
62 | return None; | 63 | return None; |
63 | } | 64 | } |
64 | 65 | ||
65 | if let Some(next_char) = root.text().char_at(token.range().end()) { | 66 | if let Some(next_char) = root.text().char_at(token.text_range().end()) { |
66 | let tokens_with_next_char = tokenize(&format!("{}{}", text, next_char)); | 67 | let tokens_with_next_char = tokenize(&format!("{}{}", text, next_char)); |
67 | if tokens_with_next_char.len() == 1 { | 68 | if tokens_with_next_char.len() == 1 { |
68 | return None; | 69 | return None; |
@@ -70,7 +71,7 @@ fn reparse_token<'node>( | |||
70 | } | 71 | } |
71 | 72 | ||
72 | let new_token = GreenToken::new(rowan::SyntaxKind(token.kind().into()), text.into()); | 73 | let new_token = GreenToken::new(rowan::SyntaxKind(token.kind().into()), text.into()); |
73 | Some((token.replace_with(new_token), token.range())) | 74 | Some((token.replace_with(new_token), token.text_range())) |
74 | } | 75 | } |
75 | _ => None, | 76 | _ => None, |
76 | } | 77 | } |
@@ -90,11 +91,12 @@ fn reparse_block<'node>( | |||
90 | let mut tree_sink = TextTreeSink::new(&text, &tokens); | 91 | let mut tree_sink = TextTreeSink::new(&text, &tokens); |
91 | reparser.parse(&mut token_source, &mut tree_sink); | 92 | reparser.parse(&mut token_source, &mut tree_sink); |
92 | let (green, new_errors) = tree_sink.finish(); | 93 | let (green, new_errors) = tree_sink.finish(); |
93 | Some((node.replace_with(green), new_errors, node.range())) | 94 | Some((node.replace_with(green), new_errors, node.text_range())) |
94 | } | 95 | } |
95 | 96 | ||
96 | fn get_text_after_edit(element: SyntaxElement, edit: &AtomTextEdit) -> String { | 97 | fn get_text_after_edit(element: SyntaxElement, edit: &AtomTextEdit) -> String { |
97 | let edit = AtomTextEdit::replace(edit.delete - element.range().start(), edit.insert.clone()); | 98 | let edit = |
99 | AtomTextEdit::replace(edit.delete - element.text_range().start(), edit.insert.clone()); | ||
98 | let text = match element { | 100 | let text = match element { |
99 | SyntaxElement::Token(token) => token.text().to_string(), | 101 | SyntaxElement::Token(token) => token.text().to_string(), |
100 | SyntaxElement::Node(node) => node.text().to_string(), | 102 | SyntaxElement::Node(node) => node.text().to_string(), |