aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src')
-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 {