mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
fix indent caclulation
This commit is contained in:
parent
c46e0300e6
commit
884ce4a420
3 changed files with 51 additions and 11 deletions
|
@ -2,15 +2,23 @@ use ra_syntax::{
|
|||
AstNode,
|
||||
SyntaxNode, SyntaxKind::*,
|
||||
ast::{self, AstToken},
|
||||
algo::generate,
|
||||
};
|
||||
|
||||
/// If the node is on the begining of the line, calculate indent.
|
||||
pub(crate) fn leading_indent(node: &SyntaxNode) -> Option<&str> {
|
||||
let prev = node.prev_sibling()?;
|
||||
let prev = prev_leaf(node)?;
|
||||
let ws_text = ast::Whitespace::cast(prev)?.text();
|
||||
ws_text.rfind('\n').map(|pos| &ws_text[pos + 1..])
|
||||
}
|
||||
|
||||
fn prev_leaf(node: &SyntaxNode) -> Option<&SyntaxNode> {
|
||||
generate(node.ancestors().find_map(SyntaxNode::prev_sibling), |it| {
|
||||
it.last_child()
|
||||
})
|
||||
.last()
|
||||
}
|
||||
|
||||
pub(crate) fn extract_trivial_expression(block: &ast::Block) -> Option<&ast::Expr> {
|
||||
let expr = block.expr()?;
|
||||
if expr.syntax().text().contains('\n') {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue