aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-02-04 12:23:37 +0000
committerGitHub <[email protected]>2020-02-04 12:23:37 +0000
commit1f7a54cfa71a0b81f3f35cde1a529f19f6816a10 (patch)
treeedd9e8254a4223d719940f44f99addc0a2920fba /crates
parentc1a06499fa5f9a40750cbfc30a7d399228a5fab0 (diff)
parent4ea0c12cf1520bc7d0f5def211a7cacadb45b7af (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')
-rw-r--r--crates/ra_syntax/src/ast/make.rs13
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.
3use itertools::Itertools; 3use itertools::Itertools;
4 4
5use crate::{ast, AstNode, SourceFile, SyntaxKind, SyntaxToken}; 5use crate::{ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, SyntaxToken};
6 6
7pub fn name(text: &str) -> ast::Name { 7pub 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
180fn ast_from_text<N: AstNode>(text: &str) -> N { 180fn 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
190fn unroot(n: SyntaxNode) -> SyntaxNode {
191 SyntaxNode::new_root(n.green().clone())
183} 192}
184 193
185pub mod tokens { 194pub mod tokens {