aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/lib.rs')
-rw-r--r--crates/ra_syntax/src/lib.rs22
1 files changed, 11 insertions, 11 deletions
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs
index ceeb2bde9..61e686da5 100644
--- a/crates/ra_syntax/src/lib.rs
+++ b/crates/ra_syntax/src/lib.rs
@@ -39,7 +39,7 @@ pub mod fuzz;
39 39
40use std::{marker::PhantomData, sync::Arc}; 40use std::{marker::PhantomData, sync::Arc};
41 41
42use ra_text_edit::AtomTextEdit; 42use ra_text_edit::Indel;
43use stdx::format_to; 43use stdx::format_to;
44 44
45use crate::syntax_node::GreenNode; 45use crate::syntax_node::GreenNode;
@@ -126,13 +126,13 @@ impl Parse<SourceFile> {
126 buf 126 buf
127 } 127 }
128 128
129 pub fn reparse(&self, edit: &AtomTextEdit) -> Parse<SourceFile> { 129 pub fn reparse(&self, indel: &Indel) -> Parse<SourceFile> {
130 self.incremental_reparse(edit).unwrap_or_else(|| self.full_reparse(edit)) 130 self.incremental_reparse(indel).unwrap_or_else(|| self.full_reparse(indel))
131 } 131 }
132 132
133 fn incremental_reparse(&self, edit: &AtomTextEdit) -> Option<Parse<SourceFile>> { 133 fn incremental_reparse(&self, indel: &Indel) -> Option<Parse<SourceFile>> {
134 // FIXME: validation errors are not handled here 134 // FIXME: validation errors are not handled here
135 parsing::incremental_reparse(self.tree().syntax(), edit, self.errors.to_vec()).map( 135 parsing::incremental_reparse(self.tree().syntax(), indel, self.errors.to_vec()).map(
136 |(green_node, errors, _reparsed_range)| Parse { 136 |(green_node, errors, _reparsed_range)| Parse {
137 green: green_node, 137 green: green_node,
138 errors: Arc::new(errors), 138 errors: Arc::new(errors),
@@ -141,8 +141,9 @@ impl Parse<SourceFile> {
141 ) 141 )
142 } 142 }
143 143
144 fn full_reparse(&self, edit: &AtomTextEdit) -> Parse<SourceFile> { 144 fn full_reparse(&self, indel: &Indel) -> Parse<SourceFile> {
145 let text = edit.apply(self.tree().syntax().text().to_string()); 145 let mut text = self.tree().syntax().text().to_string();
146 indel.apply(&mut text);
146 SourceFile::parse(&text) 147 SourceFile::parse(&text)
147 } 148 }
148} 149}
@@ -237,8 +238,7 @@ fn api_walkthrough() {
237 238
238 // Let's get the `1 + 1` expression! 239 // Let's get the `1 + 1` expression!
239 let body: ast::BlockExpr = func.body().unwrap(); 240 let body: ast::BlockExpr = func.body().unwrap();
240 let block = body.block().unwrap(); 241 let expr: ast::Expr = body.expr().unwrap();
241 let expr: ast::Expr = block.expr().unwrap();
242 242
243 // Enums are used to group related ast nodes together, and can be used for 243 // Enums are used to group related ast nodes together, and can be used for
244 // matching. However, because there are no public fields, it's possible to 244 // matching. However, because there are no public fields, it's possible to
@@ -274,8 +274,8 @@ fn api_walkthrough() {
274 assert_eq!(text.to_string(), "1 + 1"); 274 assert_eq!(text.to_string(), "1 + 1");
275 275
276 // There's a bunch of traversal methods on `SyntaxNode`: 276 // There's a bunch of traversal methods on `SyntaxNode`:
277 assert_eq!(expr_syntax.parent().as_ref(), Some(block.syntax())); 277 assert_eq!(expr_syntax.parent().as_ref(), Some(body.syntax()));
278 assert_eq!(block.syntax().first_child_or_token().map(|it| it.kind()), Some(T!['{'])); 278 assert_eq!(body.syntax().first_child_or_token().map(|it| it.kind()), Some(T!['{']));
279 assert_eq!( 279 assert_eq!(
280 expr_syntax.next_sibling_or_token().map(|it| it.kind()), 280 expr_syntax.next_sibling_or_token().map(|it| it.kind()),
281 Some(SyntaxKind::WHITESPACE) 281 Some(SyntaxKind::WHITESPACE)