mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
create leaf directly without calling the parser
This commit is contained in:
parent
4356240fa4
commit
c300135322
1 changed files with 2 additions and 23 deletions
|
@ -104,29 +104,8 @@ impl File {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let reparser: fn(&mut Parser) = if node.kind().is_trivia() {
|
let green = GreenNode::new_leaf(node.kind(), &text);
|
||||||
// since trivia is omitted by parser when it doesn't have a parent, \
|
let new_errors = vec![];
|
||||||
// we need to create one for it
|
|
||||||
|p| {
|
|
||||||
p.start().complete(p, ROOT);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
|p| {
|
|
||||||
p.bump();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let (green, new_errors) =
|
|
||||||
parser_impl::parse_with::<yellow::GreenBuilder>(
|
|
||||||
&text, &tokens, reparser,
|
|
||||||
);
|
|
||||||
|
|
||||||
let green = if node.kind().is_trivia() {
|
|
||||||
green.children().first().cloned().unwrap()
|
|
||||||
} else {
|
|
||||||
green
|
|
||||||
};
|
|
||||||
|
|
||||||
Some((node, green, new_errors))
|
Some((node, green, new_errors))
|
||||||
},
|
},
|
||||||
_ => None,
|
_ => None,
|
||||||
|
|
Loading…
Reference in a new issue