diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-19 18:14:00 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-19 18:14:00 +0000 |
commit | 0e61ba3750df7e3e19eda21b6486bf70d6dffc72 (patch) | |
tree | 8a20a180f32e1fd9f1f48f1c92a1146c5bd7efcf /crates/ra_syntax | |
parent | 545c21923e2bc8daee889b26919256bb2ba55282 (diff) | |
parent | 83a8430e0a4f4c88e45a017a2212c981b42a4a7a (diff) |
Merge #2314
2314: :arrow_up: rowan r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r-- | crates/ra_syntax/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_syntax/src/algo.rs | 33 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/extensions.rs | 2 |
3 files changed, 18 insertions, 19 deletions
diff --git a/crates/ra_syntax/Cargo.toml b/crates/ra_syntax/Cargo.toml index 45a18a73f..5db2b58c0 100644 --- a/crates/ra_syntax/Cargo.toml +++ b/crates/ra_syntax/Cargo.toml | |||
@@ -12,7 +12,7 @@ doctest = false | |||
12 | 12 | ||
13 | [dependencies] | 13 | [dependencies] |
14 | itertools = "0.8.0" | 14 | itertools = "0.8.0" |
15 | rowan = "0.6.1" | 15 | rowan = "0.7.0" |
16 | rustc_lexer = "0.1.0" | 16 | rustc_lexer = "0.1.0" |
17 | rustc-hash = "1.0.1" | 17 | rustc-hash = "1.0.1" |
18 | arrayvec = "0.5.1" | 18 | arrayvec = "0.5.1" |
diff --git a/crates/ra_syntax/src/algo.rs b/crates/ra_syntax/src/algo.rs index 7cfea70f9..1c075082a 100644 --- a/crates/ra_syntax/src/algo.rs +++ b/crates/ra_syntax/src/algo.rs | |||
@@ -134,23 +134,19 @@ pub fn insert_children( | |||
134 | to_green_element(element) | 134 | to_green_element(element) |
135 | }); | 135 | }); |
136 | 136 | ||
137 | let old_children = parent.green().children(); | 137 | let mut old_children = parent.green().children().map(|it| match it { |
138 | NodeOrToken::Token(it) => NodeOrToken::Token(it.clone()), | ||
139 | NodeOrToken::Node(it) => NodeOrToken::Node(it.clone()), | ||
140 | }); | ||
138 | 141 | ||
139 | let new_children = match &position { | 142 | let new_children = match &position { |
140 | InsertPosition::First => { | 143 | InsertPosition::First => to_insert.chain(old_children).collect::<Box<[_]>>(), |
141 | to_insert.chain(old_children.iter().cloned()).collect::<Box<[_]>>() | 144 | InsertPosition::Last => old_children.chain(to_insert).collect::<Box<[_]>>(), |
142 | } | ||
143 | InsertPosition::Last => old_children.iter().cloned().chain(to_insert).collect::<Box<[_]>>(), | ||
144 | InsertPosition::Before(anchor) | InsertPosition::After(anchor) => { | 145 | InsertPosition::Before(anchor) | InsertPosition::After(anchor) => { |
145 | let take_anchor = if let InsertPosition::After(_) = position { 1 } else { 0 }; | 146 | let take_anchor = if let InsertPosition::After(_) = position { 1 } else { 0 }; |
146 | let split_at = position_of_child(parent, anchor.clone()) + take_anchor; | 147 | let split_at = position_of_child(parent, anchor.clone()) + take_anchor; |
147 | let (before, after) = old_children.split_at(split_at); | 148 | let before = old_children.by_ref().take(split_at).collect::<Vec<_>>(); |
148 | before | 149 | before.into_iter().chain(to_insert).chain(old_children).collect::<Box<[_]>>() |
149 | .iter() | ||
150 | .cloned() | ||
151 | .chain(to_insert) | ||
152 | .chain(after.iter().cloned()) | ||
153 | .collect::<Box<[_]>>() | ||
154 | } | 150 | } |
155 | }; | 151 | }; |
156 | 152 | ||
@@ -168,13 +164,16 @@ pub fn replace_children( | |||
168 | ) -> SyntaxNode { | 164 | ) -> SyntaxNode { |
169 | let start = position_of_child(parent, to_delete.start().clone()); | 165 | let start = position_of_child(parent, to_delete.start().clone()); |
170 | let end = position_of_child(parent, to_delete.end().clone()); | 166 | let end = position_of_child(parent, to_delete.end().clone()); |
171 | let old_children = parent.green().children(); | 167 | let mut old_children = parent.green().children().map(|it| match it { |
168 | NodeOrToken::Token(it) => NodeOrToken::Token(it.clone()), | ||
169 | NodeOrToken::Node(it) => NodeOrToken::Node(it.clone()), | ||
170 | }); | ||
172 | 171 | ||
173 | let new_children = old_children[..start] | 172 | let before = old_children.by_ref().take(start).collect::<Vec<_>>(); |
174 | .iter() | 173 | let new_children = before |
175 | .cloned() | 174 | .into_iter() |
176 | .chain(to_insert.map(to_green_element)) | 175 | .chain(to_insert.map(to_green_element)) |
177 | .chain(old_children[end + 1..].iter().cloned()) | 176 | .chain(old_children.skip(end + 1 - start)) |
178 | .collect::<Box<[_]>>(); | 177 | .collect::<Box<[_]>>(); |
179 | with_children(parent, new_children) | 178 | with_children(parent, new_children) |
180 | } | 179 | } |
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index 761b2435c..4851dacb2 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs | |||
@@ -32,7 +32,7 @@ impl ast::NameRef { | |||
32 | } | 32 | } |
33 | 33 | ||
34 | fn text_of_first_token(node: &SyntaxNode) -> &SmolStr { | 34 | fn text_of_first_token(node: &SyntaxNode) -> &SmolStr { |
35 | node.green().children().first().and_then(|it| it.as_token()).unwrap().text() | 35 | node.green().children().next().and_then(|it| it.into_token()).unwrap().text() |
36 | } | 36 | } |
37 | 37 | ||
38 | impl ast::Attr { | 38 | impl ast::Attr { |