mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
feat: support inlay hint for more expr with label
This commit is contained in:
parent
9fcaab3704
commit
722020e63f
1 changed files with 24 additions and 3 deletions
|
@ -7,7 +7,7 @@ use hir::{HirDisplay, Semantics};
|
||||||
use ide_db::{FileRange, RootDatabase};
|
use ide_db::{FileRange, RootDatabase};
|
||||||
use span::EditionedFileId;
|
use span::EditionedFileId;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, AstNode, HasName},
|
ast::{self, AstNode, HasLoopBody, HasName},
|
||||||
match_ast, SyntaxKind, SyntaxNode, T,
|
match_ast, SyntaxKind, SyntaxNode, T,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -57,9 +57,30 @@ pub(super) fn hints(
|
||||||
// the actual number of lines in this case should be the line count of the parent BlockExpr,
|
// the actual number of lines in this case should be the line count of the parent BlockExpr,
|
||||||
// which the `min_lines` config cares about
|
// which the `min_lines` config cares about
|
||||||
node = node.parent()?;
|
node = node.parent()?;
|
||||||
let block = label.syntax().parent().and_then(ast::BlockExpr::cast)?;
|
|
||||||
closing_token = block.stmt_list()?.r_curly_token()?;
|
let parent = label.syntax().parent()?;
|
||||||
|
let block;
|
||||||
|
match_ast! {
|
||||||
|
match parent {
|
||||||
|
ast::BlockExpr(block_expr) => {
|
||||||
|
block = block_expr.stmt_list()?;
|
||||||
|
},
|
||||||
|
ast::LoopExpr(loop_expr) => {
|
||||||
|
block = loop_expr.loop_body()?.stmt_list()?;
|
||||||
|
},
|
||||||
|
ast::WhileExpr(while_expr) => {
|
||||||
|
block = while_expr.loop_body()?.stmt_list()?;
|
||||||
|
},
|
||||||
|
ast::ForExpr(for_expr) => {
|
||||||
|
block = for_expr.loop_body()?.stmt_list()?;
|
||||||
|
},
|
||||||
|
_ => return None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closing_token = block.r_curly_token()?;
|
||||||
|
|
||||||
let lifetime = label.lifetime().map_or_else(String::new, |it| it.to_string());
|
let lifetime = label.lifetime().map_or_else(String::new, |it| it.to_string());
|
||||||
|
|
||||||
(lifetime, Some(label.syntax().text_range()))
|
(lifetime, Some(label.syntax().text_range()))
|
||||||
} else if let Some(block) = ast::BlockExpr::cast(node.clone()) {
|
} else if let Some(block) = ast::BlockExpr::cast(node.clone()) {
|
||||||
closing_token = block.stmt_list()?.r_curly_token()?;
|
closing_token = block.stmt_list()?.r_curly_token()?;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue