diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-02-04 12:23:37 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-02-04 12:23:37 +0000 |
commit | 1f7a54cfa71a0b81f3f35cde1a529f19f6816a10 (patch) | |
tree | edd9e8254a4223d719940f44f99addc0a2920fba /crates/ra_syntax/src | |
parent | c1a06499fa5f9a40750cbfc30a7d399228a5fab0 (diff) | |
parent | 4ea0c12cf1520bc7d0f5def211a7cacadb45b7af (diff) |
Merge #3009
3009: Make sure that newly created nodes are the root of the tree r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/ast/make.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 36e648180..38c0e9a66 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | //! of smaller pieces. | 2 | //! of smaller pieces. |
3 | use itertools::Itertools; | 3 | use itertools::Itertools; |
4 | 4 | ||
5 | use crate::{ast, AstNode, SourceFile, SyntaxKind, SyntaxToken}; | 5 | use crate::{ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, SyntaxToken}; |
6 | 6 | ||
7 | pub fn name(text: &str) -> ast::Name { | 7 | pub fn name(text: &str) -> ast::Name { |
8 | ast_from_text(&format!("mod {};", text)) | 8 | ast_from_text(&format!("mod {};", text)) |
@@ -179,7 +179,16 @@ pub fn token(kind: SyntaxKind) -> SyntaxToken { | |||
179 | 179 | ||
180 | fn ast_from_text<N: AstNode>(text: &str) -> N { | 180 | fn ast_from_text<N: AstNode>(text: &str) -> N { |
181 | let parse = SourceFile::parse(text); | 181 | let parse = SourceFile::parse(text); |
182 | parse.tree().syntax().descendants().find_map(N::cast).unwrap() | 182 | let node = parse.tree().syntax().descendants().find_map(N::cast).unwrap(); |
183 | let node = node.syntax().clone(); | ||
184 | let node = unroot(node); | ||
185 | let node = N::cast(node).unwrap(); | ||
186 | assert_eq!(node.syntax().text_range().start(), 0.into()); | ||
187 | node | ||
188 | } | ||
189 | |||
190 | fn unroot(n: SyntaxNode) -> SyntaxNode { | ||
191 | SyntaxNode::new_root(n.green().clone()) | ||
183 | } | 192 | } |
184 | 193 | ||
185 | pub mod tokens { | 194 | pub mod tokens { |