mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
internal: Thread edition through to parsing/tt-to-syntax-tree routines for macros
This commit is contained in:
parent
83370fe5d7
commit
a483d3bc37
39 changed files with 187 additions and 145 deletions
|
@ -1054,6 +1054,7 @@ impl<N: AstNode + Clone> Indent for N {}
|
|||
mod tests {
|
||||
use std::fmt;
|
||||
|
||||
use parser::Edition;
|
||||
use stdx::trim_indent;
|
||||
use test_utils::assert_eq_text;
|
||||
|
||||
|
@ -1062,7 +1063,7 @@ mod tests {
|
|||
use super::*;
|
||||
|
||||
fn ast_mut_from_text<N: AstNode>(text: &str) -> N {
|
||||
let parse = SourceFile::parse(text);
|
||||
let parse = SourceFile::parse(text, Edition::CURRENT);
|
||||
parse.tree().syntax().descendants().find_map(N::cast).unwrap().clone_for_update()
|
||||
}
|
||||
|
||||
|
|
|
@ -89,6 +89,7 @@ fn if_block_condition() {
|
|||
else { "else" }
|
||||
}
|
||||
"#,
|
||||
parser::Edition::CURRENT,
|
||||
);
|
||||
let if_ = parse.tree().syntax().descendants().find_map(ast::IfExpr::cast).unwrap();
|
||||
assert_eq!(if_.then_branch().unwrap().syntax().text(), r#"{ "if" }"#);
|
||||
|
@ -123,6 +124,7 @@ fn if_condition_with_if_inside() {
|
|||
else { "else" }
|
||||
}
|
||||
"#,
|
||||
parser::Edition::CURRENT,
|
||||
);
|
||||
let if_ = parse.tree().syntax().descendants().find_map(ast::IfExpr::cast).unwrap();
|
||||
assert_eq!(if_.then_branch().unwrap().syntax().text(), r#"{ "if" }"#);
|
||||
|
@ -386,7 +388,8 @@ impl ast::BlockExpr {
|
|||
|
||||
#[test]
|
||||
fn test_literal_with_attr() {
|
||||
let parse = ast::SourceFile::parse(r#"const _: &str = { #[attr] "Hello" };"#);
|
||||
let parse =
|
||||
ast::SourceFile::parse(r#"const _: &str = { #[attr] "Hello" };"#, parser::Edition::CURRENT);
|
||||
let lit = parse.tree().syntax().descendants().find_map(ast::Literal::cast).unwrap();
|
||||
assert_eq!(lit.token().text(), r#""Hello""#);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
//! term, it will be replaced with direct tree manipulation.
|
||||
|
||||
use itertools::Itertools;
|
||||
use parser::T;
|
||||
use parser::{Edition, T};
|
||||
use rowan::NodeOrToken;
|
||||
use stdx::{format_to, format_to_acc, never};
|
||||
|
||||
|
@ -1127,7 +1127,7 @@ pub fn token_tree(
|
|||
|
||||
#[track_caller]
|
||||
fn ast_from_text<N: AstNode>(text: &str) -> N {
|
||||
let parse = SourceFile::parse(text);
|
||||
let parse = SourceFile::parse(text, Edition::CURRENT);
|
||||
let node = match parse.tree().syntax().descendants().find_map(N::cast) {
|
||||
Some(it) => it,
|
||||
None => {
|
||||
|
@ -1153,12 +1153,13 @@ pub fn token(kind: SyntaxKind) -> SyntaxToken {
|
|||
|
||||
pub mod tokens {
|
||||
use once_cell::sync::Lazy;
|
||||
use parser::Edition;
|
||||
|
||||
use crate::{ast, AstNode, Parse, SourceFile, SyntaxKind::*, SyntaxToken};
|
||||
|
||||
pub(super) static SOURCE_FILE: Lazy<Parse<SourceFile>> = Lazy::new(|| {
|
||||
SourceFile::parse(
|
||||
"const C: <()>::Item = ( true && true , true || true , 1 != 1, 2 == 2, 3 < 3, 4 <= 4, 5 > 5, 6 >= 6, !true, *p, &p , &mut p, { let a @ [] })\n;\n\nimpl A for B where: {}",
|
||||
"const C: <()>::Item = ( true && true , true || true , 1 != 1, 2 == 2, 3 < 3, 4 <= 4, 5 > 5, 6 >= 6, !true, *p, &p , &mut p, { let a @ [] })\n;\n\nimpl A for B where: {}", Edition::CURRENT,
|
||||
)
|
||||
});
|
||||
|
||||
|
@ -1186,13 +1187,13 @@ pub mod tokens {
|
|||
|
||||
pub fn whitespace(text: &str) -> SyntaxToken {
|
||||
assert!(text.trim().is_empty());
|
||||
let sf = SourceFile::parse(text).ok().unwrap();
|
||||
let sf = SourceFile::parse(text, Edition::CURRENT).ok().unwrap();
|
||||
sf.syntax().clone_for_update().first_child_or_token().unwrap().into_token().unwrap()
|
||||
}
|
||||
|
||||
pub fn doc_comment(text: &str) -> SyntaxToken {
|
||||
assert!(!text.trim().is_empty());
|
||||
let sf = SourceFile::parse(text).ok().unwrap();
|
||||
let sf = SourceFile::parse(text, Edition::CURRENT).ok().unwrap();
|
||||
sf.syntax().first_child_or_token().unwrap().into_token().unwrap()
|
||||
}
|
||||
|
||||
|
@ -1240,7 +1241,7 @@ pub mod tokens {
|
|||
|
||||
impl WsBuilder {
|
||||
pub fn new(text: &str) -> WsBuilder {
|
||||
WsBuilder(SourceFile::parse(text).ok().unwrap())
|
||||
WsBuilder(SourceFile::parse(text, Edition::CURRENT).ok().unwrap())
|
||||
}
|
||||
pub fn ws(&self) -> SyntaxToken {
|
||||
self.0.syntax().first_child_or_token().unwrap().into_token().unwrap()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue