diff options
author | Aleksey Kladov <[email protected]> | 2018-08-25 12:45:17 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-25 12:45:17 +0100 |
commit | c3e5987c433cdd0ea95a6b1057b442f4f0fe1ffc (patch) | |
tree | 1ef2814a3ddc800ef6976aa0459c6b5cf0c3b621 /crates/libsyntax2/src/yellow | |
parent | 5211e7d97771aa7f8d7cc99e5131fb3cc71a1627 (diff) |
incremental reparse
Diffstat (limited to 'crates/libsyntax2/src/yellow')
-rw-r--r-- | crates/libsyntax2/src/yellow/syntax.rs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/crates/libsyntax2/src/yellow/syntax.rs b/crates/libsyntax2/src/yellow/syntax.rs index 8f1b1d79a..0045598d4 100644 --- a/crates/libsyntax2/src/yellow/syntax.rs +++ b/crates/libsyntax2/src/yellow/syntax.rs | |||
@@ -3,7 +3,7 @@ use std::{fmt, sync::Arc}; | |||
3 | use smol_str::SmolStr; | 3 | use smol_str::SmolStr; |
4 | 4 | ||
5 | use { | 5 | use { |
6 | yellow::{RedNode, TreeRoot, SyntaxRoot, RedPtr, RefRoot, OwnedRoot}, | 6 | yellow::{GreenNode, RedNode, TreeRoot, SyntaxRoot, RedPtr, RefRoot, OwnedRoot}, |
7 | SyntaxKind::{self, *}, | 7 | SyntaxKind::{self, *}, |
8 | TextRange, TextUnit, | 8 | TextRange, TextUnit, |
9 | }; | 9 | }; |
@@ -141,6 +141,27 @@ impl<R: TreeRoot> SyntaxNode<R> { | |||
141 | self.red().green().leaf_text() | 141 | self.red().green().leaf_text() |
142 | } | 142 | } |
143 | 143 | ||
144 | pub(crate) fn replace_with(&self, green: GreenNode) -> GreenNode { | ||
145 | assert_eq!(self.kind(), green.kind()); | ||
146 | match self.parent() { | ||
147 | None => green, | ||
148 | Some(parent) => { | ||
149 | let children: Vec<_> = parent.children().map(|child| { | ||
150 | if child == *self { | ||
151 | green.clone() | ||
152 | } else { | ||
153 | child.red().green().clone() | ||
154 | } | ||
155 | }).collect(); | ||
156 | let new_parent = GreenNode::new_branch( | ||
157 | parent.kind(), | ||
158 | children.into_boxed_slice(), | ||
159 | ); | ||
160 | parent.replace_with(new_parent) | ||
161 | }, | ||
162 | } | ||
163 | } | ||
164 | |||
144 | fn red(&self) -> &RedNode { | 165 | fn red(&self) -> &RedNode { |
145 | unsafe { self.red.get(&self.root) } | 166 | unsafe { self.red.get(&self.root) } |
146 | } | 167 | } |