diff options
-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 { |