Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support inlay hint for more expr with label #17784

Merged
merged 3 commits into from
Aug 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions crates/ide/src/inlay_hints/closing_brace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use hir::{HirDisplay, Semantics};
use ide_db::{FileRange, RootDatabase};
use span::EditionedFileId;
use syntax::{
ast::{self, AstNode, HasName},
ast::{self, AstNode, HasLoopBody, HasName},
match_ast, SyntaxKind, SyntaxNode, T,
};

Expand Down Expand Up @@ -57,9 +57,24 @@ pub(super) fn hints(
// the actual number of lines in this case should be the line count of the parent BlockExpr,
// which the `min_lines` config cares about
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::AnyHasLoopBody(loop_expr) => {
block = loop_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());

(lifetime, Some(label.syntax().text_range()))
} else if let Some(block) = ast::BlockExpr::cast(node.clone()) {
closing_token = block.stmt_list()?.r_curly_token()?;
Expand Down Expand Up @@ -219,6 +234,19 @@ fn test() {
//^ 'do_a
}
//^ 'end

'a: loop {
'b: for i in 0..5 {
'c: while true {


}
//^ 'c
}
//^ 'b
}
//^ 'a

}
//^ fn test
"#,
Expand Down